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';
65 foreach (reverse @_) {
68 Carp::carp("Empty compile time value given to use lib");
72 Carp::carp("Parameter to use lib must be directory, not file");
75 # Add any previous version directories we found at configure time
76 foreach my $incver (@inc_version_list)
78 unshift(@INC, "$_/$incver") if -d "$_/$incver";
80 # Put a corresponding archlib directory infront of $_ if it
81 # looks like $_ has an archlib directory below it.
82 unshift(@INC, "$_/$archname") if -d "$_/$archname/auto";
83 unshift(@INC, "$_/$version") if -d "$_/$version";
84 unshift(@INC, "$_/$version/$archname") if -d "$_/$version/$archname";
87 # remove trailing duplicates
88 @INC = grep { ++$names{$_} == 1 } @INC;
99 ++$names{"$_/$archname"} if -d "$_/$archname/auto";
100 ++$names{"$_/$version"} if -d "$_/$version";
101 ++$names{"$_/$version/$archname"} if -d "$_/$version/$archname";
104 # Remove ALL instances of each named directory.
105 @INC = grep { !exists $names{$_} } @INC;
114 lib - manipulate @INC at compile time
124 This is a small simple module which simplifies the manipulation of @INC
127 It is typically used to add extra directories to perl's search path so
128 that later C<use> or C<require> statements will find modules which are
129 not located on perl's default search path.
131 =head2 Adding directories to @INC
133 The parameters to C<use lib> are added to the start of the perl search
138 is I<almost> the same as saying
140 BEGIN { unshift(@INC, LIST) }
142 For each directory in LIST (called $dir here) the lib module also
143 checks to see if a directory called $dir/$archname/auto exists.
144 If so the $dir/$archname directory is assumed to be a corresponding
145 architecture specific directory and is added to @INC in front of $dir.
147 To avoid memory leaks, all trailing duplicate entries in @INC are
150 =head2 Deleting directories from @INC
152 You should normally only add directories to @INC. If you need to
153 delete directories from @INC take care to only delete those which you
154 added yourself or which you are certain are not needed by other modules
155 in your script. Other modules may have added directories which they
156 need for correct operation.
158 The C<no lib> statement deletes all instances of each named directory
161 For each directory in LIST (called $dir here) the lib module also
162 checks to see if a directory called $dir/$archname/auto exists.
163 If so the $dir/$archname directory is assumed to be a corresponding
164 architecture specific directory and is also deleted from @INC.
166 =head2 Restoring original @INC
168 When the lib module is first loaded it records the current value of @INC
169 in an array C<@lib::ORIG_INC>. To restore @INC to that value you
172 @INC = @lib::ORIG_INC;
177 FindBin - optional module which deals with paths relative to the source file.
181 Tim Bunce, 2nd June 1995.
186 close OUT or die "Can't close $file: $!";