3 use vars qw(@ORIG_INC);
6 my $archname = $Config{'archname'};
8 @ORIG_INC = @INC; # take a handy copy of 'original' value
15 foreach (reverse @_) {
18 Carp::carp("Empty compile time value given to use lib");
22 Carp::carp("Parameter to use lib must be directory, not file");
25 # Put a corresponding archlib directory infront of $_ if it
26 # looks like $_ has an archlib directory below it.
27 if (-d "$_/$archname") {
28 unshift(@INC, "$_/$archname") if -d "$_/$archname/auto";
29 unshift(@INC, "$_/$archname/$]") if -d "$_/$archname/$]/auto";
31 # remove trailing duplicates
32 @INC = grep { ++$names{$_} == 1 } @INC;
43 ++$names{"$_/$archname"} if -d "$_/$archname/auto";
46 # Remove ALL instances of each named directory.
47 @INC = grep { !exists $names{$_} } @INC;
55 lib - manipulate @INC at compile time
65 This is a small simple module which simplifies the manipulation of @INC
68 It is typically used to add extra directories to perl's search path so
69 that later C<use> or C<require> statements will find modules which are
70 not located on perl's default search path.
72 =head2 Adding directories to @INC
74 The parameters to C<use lib> are added to the start of the perl search
79 is I<almost> the same as saying
81 BEGIN { unshift(@INC, LIST) }
83 For each directory in LIST (called $dir here) the lib module also
84 checks to see if a directory called $dir/$archname/auto exists.
85 If so the $dir/$archname directory is assumed to be a corresponding
86 architecture specific directory and is added to @INC in front of $dir.
88 To avoid memory leaks, all trailing duplicate entries in @INC are
91 =head2 Deleting directories from @INC
93 You should normally only add directories to @INC. If you need to
94 delete directories from @INC take care to only delete those which you
95 added yourself or which you are certain are not needed by other modules
96 in your script. Other modules may have added directories which they
97 need for correct operation.
99 The C<no lib> statement deletes all instances of each named directory
102 For each directory in LIST (called $dir here) the lib module also
103 checks to see if a directory called $dir/$archname/auto exists.
104 If so the $dir/$archname directory is assumed to be a corresponding
105 architecture specific directory and is also deleted from @INC.
107 =head2 Restoring original @INC
109 When the lib module is first loaded it records the current value of @INC
110 in an array C<@lib::ORIG_INC>. To restore @INC to that value you
113 @INC = @lib::ORIG_INC;
118 FindBin - optional module which deals with paths relative to the source file.
122 Tim Bunce, 2nd June 1995.