2 use File::Basename qw(&basename &dirname);
8 my $file = basename($0, '.PL');
9 $file =~ s!_(pm)$!.$1!i;
11 my $Config_archname = defined($Config{'archname'}) ? $Config{'archname'} : '';
12 my $Config_ver = defined($Config{'version'}) ? $Config{'version'} : '';
13 my @Config_inc_version_list = defined($Config{'inc_version_list'}) ?
14 reverse split / /, $Config{'inc_version_list'} : ();
16 open OUT,">$file" or die "Can't create $file: $!";
18 print "Extracting $file (with variable substitutions)\n";
20 # In this section, perl variables will be expanded during extraction.
21 # You can use $Config{...} to use Configure variables.
23 print OUT <<"!GROK!THIS!";
28 my \$archname = "$Config_archname";
29 my \$ver = "$Config_ver";
30 my \@inc_version_list = qw(@Config_inc_version_list);
33 print OUT <<'!NO!SUBS!';
35 our @ORIG_INC = @INC; # take a handy copy of 'original' value
36 our $VERSION = '0.5564';
42 foreach (reverse @_) {
45 Carp::carp("Empty compile time value given to use lib");
49 Carp::carp("Parameter to use lib must be directory, not file");
52 # Add any previous version directories we found at configure time
53 foreach my $incver (@inc_version_list)
55 unshift(@INC, "$_/$incver") if -d "$_/$incver";
57 # Put a corresponding archlib directory infront of $_ if it
58 # looks like $_ has an archlib directory below it.
59 unshift(@INC, "$_/$ver") if -d "$_/$ver";
60 unshift(@INC, "$_/$ver/$archname") if -d "$_/$ver/$archname";
63 # remove trailing duplicates
64 @INC = grep { ++$names{$_} == 1 } @INC;
75 ++$names{"$_/$archname"} if -d "$_/$archname/auto";
78 # Remove ALL instances of each named directory.
79 @INC = grep { !exists $names{$_} } @INC;
88 lib - manipulate @INC at compile time
98 This is a small simple module which simplifies the manipulation of @INC
101 It is typically used to add extra directories to perl's search path so
102 that later C<use> or C<require> statements will find modules which are
103 not located on perl's default search path.
105 =head2 Adding directories to @INC
107 The parameters to C<use lib> are added to the start of the perl search
112 is I<almost> the same as saying
114 BEGIN { unshift(@INC, LIST) }
116 For each directory in LIST (called $dir here) the lib module also
117 checks to see if a directory called $dir/$archname/auto exists.
118 If so the $dir/$archname directory is assumed to be a corresponding
119 architecture specific directory and is added to @INC in front of $dir.
121 To avoid memory leaks, all trailing duplicate entries in @INC are
124 =head2 Deleting directories from @INC
126 You should normally only add directories to @INC. If you need to
127 delete directories from @INC take care to only delete those which you
128 added yourself or which you are certain are not needed by other modules
129 in your script. Other modules may have added directories which they
130 need for correct operation.
132 The C<no lib> statement deletes all instances of each named directory
135 For each directory in LIST (called $dir here) the lib module also
136 checks to see if a directory called $dir/$archname/auto exists.
137 If so the $dir/$archname directory is assumed to be a corresponding
138 architecture specific directory and is also deleted from @INC.
140 =head2 Restoring original @INC
142 When the lib module is first loaded it records the current value of @INC
143 in an array C<@lib::ORIG_INC>. To restore @INC to that value you
146 @INC = @lib::ORIG_INC;
151 FindBin - optional module which deals with paths relative to the source file.
155 Tim Bunce, 2nd June 1995.
160 close OUT or die "Can't close $file: $!";