Commit | Line | Data |
49624702 |
1 | package blib; |
2 | |
3 | =head1 NAME |
4 | |
5 | blib - 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 | |
15 | Looks for MakeMaker-like I<'blib'> directory structure starting in |
16 | I<dir> (or current directory) and working back up to five levels of '..'. |
17 | |
18 | Intended for use on command line with B<-M> option as a way of testing |
19 | arbitary scripts against an uninstalled version of a package. |
20 | |
21 | However it is possible to : |
22 | |
23 | use blib; |
24 | or |
25 | use blib '..'; |
26 | |
27 | etc. if you really must. |
28 | |
29 | =head1 BUGS |
30 | |
31 | Pollutes global name space for development only task. |
32 | |
33 | =head1 AUTHOR |
34 | |
35 | Nick Ing-Simmons nik@tiuk.ti.com |
36 | |
e69a2255 |
37 | =cut |
49624702 |
38 | |
39 | use Cwd; |
e69a2255 |
40 | use File::Spec; |
49624702 |
41 | |
a635c943 |
42 | use vars qw($VERSION $Verbose); |
e69a2255 |
43 | $VERSION = '1.02'; |
a635c943 |
44 | $Verbose = 0; |
49624702 |
45 | |
46 | sub import |
47 | { |
48 | my $package = shift; |
49 | my $dir = getcwd; |
fe6f1558 |
50 | if ($^O eq 'VMS') { ($dir = VMS::Filespec::unixify($dir)) =~ s-/\z--; } |
49624702 |
51 | if (@_) |
52 | { |
49624702 |
53 | $dir = shift; |
fe6f1558 |
54 | $dir =~ s/blib\z//; |
55 | $dir =~ s,/+\z,,; |
e69a2255 |
56 | $dir = File::Spec->curdir unless ($dir); |
49624702 |
57 | die "$dir is not a directory\n" unless (-d $dir); |
58 | } |
e69a2255 |
59 | my $i = 5; |
60 | my($blib, $blib_lib, $blib_arch); |
49624702 |
61 | while ($i--) |
62 | { |
e69a2255 |
63 | $blib = File::Spec->catdir($dir, "blib"); |
64 | $blib_lib = File::Spec->catdir($blib, "lib"); |
65 | |
66 | if ($^O eq 'MacOS') |
67 | { |
68 | $blib_arch = File::Spec->catdir($blib_lib, $MacPerl::Architecture); |
69 | } |
70 | else |
71 | { |
72 | $blib_arch = File::Spec->catdir($blib, "arch"); |
73 | } |
74 | |
75 | if (-d $blib && -d $blib_arch && -d $blib_lib) |
49624702 |
76 | { |
e69a2255 |
77 | unshift(@INC,$blib_arch,$blib_lib); |
a635c943 |
78 | warn "Using $blib\n" if $Verbose; |
49624702 |
79 | return; |
80 | } |
e69a2255 |
81 | $dir = File::Spec->catdir($dir, File::Spec->updir); |
49624702 |
82 | } |
83 | die "Cannot find blib even in $dir\n"; |
84 | } |
85 | |
86 | 1; |