2 use File::Basename qw(&basename &dirname);
8 my $file = basename($0, '.PL');
9 $file =~ s!_(pm)$!.$1!i;
14 my $Config_inc_version_list;
16 # Expand the variables only if explicitly requested because
17 # otherwise relocating Perl becomes much harder.
19 if ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS}) {
21 $Config_archname = qq('$Config{archname}');
22 $Config_version = qq('$Config{version}');
23 my @Config_inc_version_list =
24 reverse split / /, $Config{inc_version_list};
25 $Config_inc_version_list =
26 @Config_inc_version_list ?
27 qq(@Config_inc_version_list) : q(());
29 $useConfig = 'use Config;';
30 $Config_archname = q($Config{archname});
31 $Config_version = q($Config{version});
32 $Config_inc_version_list =
33 q(reverse split / /, $Config{inc_version_list});
36 open OUT,">$file" or die "Can't create $file: $!";
38 print "Extracting $file (with variable substitutions)\n";
40 # In this section, perl variables will be expanded during extraction.
41 # You can use $Config{...} to use Configure variables.
43 print OUT <<"!GROK!THIS!";
46 # THIS FILE IS AUTOMATICALLY GENERATED FROM lib_pm.PL.
47 # ANY CHANGES TO THIS FILE WILL BE OVERWRITTEN BY THE NEXT PERL BUILD.
51 my \$archname = $Config_archname;
52 my \$version = $Config_version;
53 my \@inc_version_list = $Config_inc_version_list;
56 print OUT <<'!NO!SUBS!';
58 our @ORIG_INC = @INC; # take a handy copy of 'original' value
59 our $VERSION = '0.5564';
60 my $Is_MacOS = $^O eq 'MacOS';
64 $Mac_FS = eval { require Mac::FileSpec::Unixish };
71 foreach (reverse @_) {
74 Carp::carp("Empty compile time value given to use lib");
77 local $_ = _nativize($_);
81 Carp::carp("Parameter to use lib must be directory, not file");
84 # Add any previous version directories we found at configure time
85 foreach my $invcer (@inc_version_list)
88 ? File::Spec->catdir( $_, $incver )
90 unshift(@INC, $dir) if -d $dir;
92 # Put a corresponding archlib directory infront of $_ if it
93 # looks like $_ has an archlib directory below it.
94 my($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir)
96 unshift(@INC, $arch_dir) if -d $arch_auto_dir;
97 unshift(@INC, $version_dir) if -d $version_dir;
98 unshift(@INC, $version_arch_dir) if -d $version_arch_dir;
101 # remove trailing duplicates
102 @INC = grep { ++$names{$_} == 1 } @INC;
112 local $_ = _nativize($_);
114 my($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir)
117 ++$names{$arch_dir} if -d $arch_auto_dir;
118 ++$names{$version_dir} if -d $version_dir;
119 ++$names{$version_arch_dir} if -d $version_arch_dir;
122 # Remove ALL instances of each named directory.
123 @INC = grep { !exists $names{$_} } @INC;
129 my($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir);
131 # we could use this for all platforms in the future, but leave it
132 # Mac-only for now, until there is more time for testing it.
134 $arch_auto_dir = File::Spec->catdir( $_, $archname, 'auto' );
135 $arch_dir = File::Spec->catdir( $_, $archname, );
136 $version_dir = File::Spec->catdir( $_, $version );
137 $version_arch_dir = File::Spec->catdir( $_, $version, $archname );
139 $arch_auto_dir = "$_/$archname/auto";
140 $arch_dir = "$_/$archname";
141 $version_dir = "$_/$version";
142 $version_arch_dir = "$_/$version/$archname";
144 return($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir);
150 if ($Is_MacOS && $Mac_FS) {
151 $dir = Mac::FileSpec::Unixish::nativize($dir);
152 $dir .= ":" unless $dir =~ /:$/;
163 lib - manipulate @INC at compile time
173 This is a small simple module which simplifies the manipulation of @INC
176 It is typically used to add extra directories to perl's search path so
177 that later C<use> or C<require> statements will find modules which are
178 not located on perl's default search path.
180 =head2 Adding directories to @INC
182 The parameters to C<use lib> are added to the start of the perl search
187 is I<almost> the same as saying
189 BEGIN { unshift(@INC, LIST) }
191 For each directory in LIST (called $dir here) the lib module also
192 checks to see if a directory called $dir/$archname/auto exists.
193 If so the $dir/$archname directory is assumed to be a corresponding
194 architecture specific directory and is added to @INC in front of $dir.
196 To avoid memory leaks, all trailing duplicate entries in @INC are
199 =head2 Deleting directories from @INC
201 You should normally only add directories to @INC. If you need to
202 delete directories from @INC take care to only delete those which you
203 added yourself or which you are certain are not needed by other modules
204 in your script. Other modules may have added directories which they
205 need for correct operation.
207 The C<no lib> statement deletes all instances of each named directory
210 For each directory in LIST (called $dir here) the lib module also
211 checks to see if a directory called $dir/$archname/auto exists.
212 If so the $dir/$archname directory is assumed to be a corresponding
213 architecture specific directory and is also deleted from @INC.
215 =head2 Restoring original @INC
217 When the lib module is first loaded it records the current value of @INC
218 in an array C<@lib::ORIG_INC>. To restore @INC to that value you
221 @INC = @lib::ORIG_INC;
225 In order to keep lib.pm small and simple, it only works with Unix
226 filepaths. This doesn't mean it only works on Unix, but non-Unix
227 users must first translate their file paths to Unix conventions.
229 # VMS users wanting to put [.stuff.moo] into
230 # their @INC would write
235 In the future, this module will likely use File::Spec for determining
236 paths, as it does now for Mac OS (where Unix-style or Mac-style paths
237 work, and Unix-style paths are converted properly to Mac-style paths
238 before being added to @INC).
242 FindBin - optional module which deals with paths relative to the source file.
246 Tim Bunce, 2nd June 1995.
251 close OUT or die "Can't close $file: $!";