This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
blib
[perl5.git] / blib.pm
CommitLineData
be9cdb87
NIS
1package blib;
2
3=head1 NAME
4
5blib - Use MakeMaker's uninstalled version of a package
6
7=head1 SYNOPSIS
8
9 perl -Mblib script [args...]
10
11 perl -Mblib=dir script [args...]
12
13=head1 DESCRIPTION
14
15Looks for MakeMaker-like I<'blib'> directory structure starting in
16I<dir> (or current directory) and working back up to five levels of '..'.
17
18Intended for use on command line with B<-M> option as a way of testing
19arbitary scripts against an uninstalled version of a package.
20
21However it is possible to :
22
23 use blib;
24 or
25 use blib '..';
26
27etc. if you really must.
28
29=head1 BUGS
30
31Pollutes global name space for development only task.
32
33=head1 AUTHOR
34
35Nick Ing-Simmons nik@tiuk.ti.com
36
37=cut
38
39use Cwd;
40
41warn __FILE__;
42
43sub import
44{
45 my $package = shift;
46 my $dir = getcwd;
47 if (@_)
48 {
49 print join(',',@_),"\n";
50 $dir = shift;
51 $dir =~ s/blib$//;
52 $dir =~ s,/+$,,;
53 $dir = '.' unless ($dir);
54 die "$dir is not a directory\n" unless (-d $dir);
55 }
56 my $i = 5;
57 while ($i--)
58 {
59 my $blib = "${dir}/blib";
60 if (-d $blib && -d "$blib/arch" && -d "$blib/lib")
61 {
62 unshift(@INC,"$blib/arch","$blib/lib");
63 warn "Using $blib";
64 return;
65 }
66 $dir .= "/..";
67 }
68 die "Cannot find blib even in $dir\n";
69}
70
711;