2 use File::Basename qw(&basename &dirname);
8 my $file = basename($0, '.PL');
10 my $Config_archname = defined($Config{'archname'}) ? $Config{'archname'} : '';
11 my $Config_ver = defined($Config{'version'}) ? $Config{'version'} : '';
12 my @Config_inc_version_list = defined($Config{'inc_version_list'}) ?
13 reverse split / /, $Config{'inc_version_list'} : ();
15 open OUT,">$file" or die "Can't create $file: $!";
17 print "Extracting $file (with variable substitutions)\n";
19 # In this section, perl variables will be expanded during extraction.
20 # You can use $Config{...} to use Configure variables.
22 print OUT <<"!GROK!THIS!";
27 my \$archname = "$Config_archname";
28 my \$ver = "$Config_ver";
29 my \@inc_version_list = qw(@Config_inc_version_list);
32 print OUT <<'!NO!SUBS!';
34 our @ORIG_INC = @INC; # take a handy copy of 'original' value
35 our $VERSION = '0.5564';
41 foreach (reverse @_) {
44 Carp::carp("Empty compile time value given to use lib");
48 Carp::carp("Parameter to use lib must be directory, not file");
51 # Add any previous version directories we found at configure time
52 foreach my $incver (@inc_version_list)
54 unshift(@INC, "$_/$incver") if -d "$_/$incver";
56 # Put a corresponding archlib directory infront of $_ if it
57 # looks like $_ has an archlib directory below it.
58 unshift(@INC, "$_/$ver") if -d "$_/$ver";
59 unshift(@INC, "$_/$ver/$archname") if -d "$_/$ver/$archname";
62 # remove trailing duplicates
63 @INC = grep { ++$names{$_} == 1 } @INC;
74 ++$names{"$_/$archname"} if -d "$_/$archname/auto";
77 # Remove ALL instances of each named directory.
78 @INC = grep { !exists $names{$_} } @INC;
87 lib - manipulate @INC at compile time
97 This is a small simple module which simplifies the manipulation of @INC
100 It is typically used to add extra directories to perl's search path so
101 that later C<use> or C<require> statements will find modules which are
102 not located on perl's default search path.
104 =head2 Adding directories to @INC
106 The parameters to C<use lib> are added to the start of the perl search
111 is I<almost> the same as saying
113 BEGIN { unshift(@INC, LIST) }
115 For each directory in LIST (called $dir here) the lib module also
116 checks to see if a directory called $dir/$archname/auto exists.
117 If so the $dir/$archname directory is assumed to be a corresponding
118 architecture specific directory and is added to @INC in front of $dir.
120 To avoid memory leaks, all trailing duplicate entries in @INC are
123 =head2 Deleting directories from @INC
125 You should normally only add directories to @INC. If you need to
126 delete directories from @INC take care to only delete those which you
127 added yourself or which you are certain are not needed by other modules
128 in your script. Other modules may have added directories which they
129 need for correct operation.
131 The C<no lib> statement deletes all instances of each named directory
134 For each directory in LIST (called $dir here) the lib module also
135 checks to see if a directory called $dir/$archname/auto exists.
136 If so the $dir/$archname directory is assumed to be a corresponding
137 architecture specific directory and is also deleted from @INC.
139 =head2 Restoring original @INC
141 When the lib module is first loaded it records the current value of @INC
142 in an array C<@lib::ORIG_INC>. To restore @INC to that value you
145 @INC = @lib::ORIG_INC;
150 FindBin - optional module which deals with paths relative to the source file.
154 Tim Bunce, 2nd June 1995.
159 close OUT or die "Can't close $file: $!";