This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [ID 20020422.003] Suggestion in Perl 5.6.1 installation on AIX
[perl5.git] / lib / blib.pm
CommitLineData
49624702
CS
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
a635c943 41use vars qw($VERSION $Verbose);
88d01e8d 42$VERSION = '1.01';
a635c943 43$Verbose = 0;
49624702
CS
44
45sub import
46{
47 my $package = shift;
48 my $dir = getcwd;
fe6f1558 49 if ($^O eq 'VMS') { ($dir = VMS::Filespec::unixify($dir)) =~ s-/\z--; }
49624702
CS
50 if (@_)
51 {
49624702 52 $dir = shift;
fe6f1558
GS
53 $dir =~ s/blib\z//;
54 $dir =~ s,/+\z,,;
49624702
CS
55 $dir = '.' unless ($dir);
56 die "$dir is not a directory\n" unless (-d $dir);
57 }
58 my $i = 5;
59 while ($i--)
60 {
61 my $blib = "${dir}/blib";
62 if (-d $blib && -d "$blib/arch" && -d "$blib/lib")
63 {
64 unshift(@INC,"$blib/arch","$blib/lib");
a635c943 65 warn "Using $blib\n" if $Verbose;
49624702
CS
66 return;
67 }
68 $dir .= "/..";
69 }
70 die "Cannot find blib even in $dir\n";
71}
72
731;