3 use vars qw(@ORIG_INC);
6 my $archname = $Config{'archname'};
8 @ORIG_INC = @INC; # take a handy copy of 'original' value
13 foreach (reverse @_) {
14 ## Ignore this if not defined.
15 next unless defined($_);
18 Carp::carp("Empty compile time value given to use lib");
23 Carp::carp("Parameter to use lib must be directory, not file");
26 # Put a corresponding archlib directory infront of $_ if it
27 # looks like $_ has an archlib directory below it.
28 if (-d "$_/$archname") {
29 unshift(@INC, "$_/$archname") if -d "$_/$archname/auto";
30 unshift(@INC, "$_/$archname/$]") if -d "$_/$archname/$]/auto";
38 my $mode = shift if $_[0] =~ m/^:[A-Z]+/;
43 ++$names{"$_/$archname"} if -d "$_/$archname/auto";
46 if ($mode and $mode eq ':ALL') {
47 # Remove ALL instances of each named directory.
48 @INC = grep { !exists $names{$_} } @INC;
50 # Remove INITIAL instance(s) of each named directory.
51 @INC = grep { --$names{$_} < 0 } @INC;
60 lib - manipulate @INC at compile time
70 This is a small simple module which simplifies the manipulation of @INC
73 It is typically used to add extra directories to perl's search path so
74 that later C<use> or C<require> statements will find modules which are
75 not located on perl's default search path.
77 =head2 ADDING DIRECTORIES TO @INC
79 The parameters to C<use lib> are added to the start of the perl search
84 is I<almost> the same as saying
86 BEGIN { unshift(@INC, LIST) }
88 For each directory in LIST (called $dir here) the lib module also
89 checks to see if a directory called $dir/$archname/auto exists.
90 If so the $dir/$archname directory is assumed to be a corresponding
91 architecture specific directory and is added to @INC in front of $dir.
93 If LIST includes both $dir and $dir/$archname then $dir/$archname will
94 be added to @INC twice (if $dir/$archname/auto exists).
96 =head2 DELETING DIRECTORIES FROM @INC
98 You should normally only add directories to @INC. If you need to
99 delete directories from @INC take care to only delete those which you
100 added yourself or which you are certain are not needed by other modules
101 in your script. Other modules may have added directories which they
102 need for correct operation.
104 By default the C<no lib> statement deletes the I<first> instance of
105 each named directory from @INC. To delete multiple instances of the
106 same name from @INC you can specify the name multiple times.
108 To delete I<all> instances of I<all> the specified names from @INC you can
109 specify ':ALL' as the first parameter of C<no lib>. For example:
113 For each directory in LIST (called $dir here) the lib module also
114 checks to see if a directory called $dir/$archname/auto exists.
115 If so the $dir/$archname directory is assumed to be a corresponding
116 architecture specific directory and is also deleted from @INC.
118 If LIST includes both $dir and $dir/$archname then $dir/$archname will
119 be deleted from @INC twice (if $dir/$archname/auto exists).
121 =head2 RESTORING ORIGINAL @INC
123 When the lib module is first loaded it records the current value of @INC
124 in an array C<@lib::ORIG_INC>. To restore @INC to that value you
127 @INC = @lib::ORIG_INC;
132 FindBin - optional module which deals with paths relative to the source file.
136 Tim Bunce, 2nd June 1995.