5 my $archname = $Config{'archname'};
7 @ORIG_INC = (); # (avoid typo warning)
8 @ORIG_INC = @INC; # take a handy copy of 'original' value
15 # Put a corresponding archlib directory infront of $_ if it
16 # looks like $_ has an archlib directory below it.
17 unshift(@INC, "$_/$archname") if -d "$_/$archname/auto";
24 my $mode = shift if $_[0] =~ m/^:[A-Z]+/;
29 ++$names{"$_/$archname"} if -d "$_/$archname/auto";
32 if ($mode and $mode eq ':ALL') {
33 # Remove ALL instances of each named directory.
34 @INC = grep { !exists $names{$_} } @INC;
36 # Remove INITIAL instance(s) of each named directory.
37 @INC = grep { --$names{$_} < 0 } @INC;
46 lib - manipulate @INC at compile time
56 This is a small simple module which simplifies the manipulation of @INC
59 It is typically used to add extra directories to perl's search path so
60 that later C<use> or C<require> statements will find modules which are
61 not located on perl's default search path.
64 =head2 ADDING DIRECTORIES TO @INC
66 The parameters to C<use lib> are added to the start of the perl search
71 is I<almost> the same as saying
73 BEGIN { unshift(@INC, LIST) }
75 For each directory in LIST (called $dir here) the lib module also
76 checks to see if a directory called $dir/$archname/auto exists.
77 If so the $dir/$archname directory is assumed to be a corresponding
78 architecture specific directory and is added to @INC in front of $dir.
80 If LIST includes both $dir and $dir/$archname then $dir/$archname will
81 be added to @INC twice (if $dir/$archname/auto exists).
84 =head2 DELETING DIRECTORIES FROM @INC
86 You should normally only add directories to @INC. If you need to
87 delete directories from @INC take care to only delete those which you
88 added yourself or which you are certain are not needed by other modules
89 in your script. Other modules may have added directories which they
90 need for correct operation.
92 By default the C<no lib> statement deletes the I<first> instance of
93 each named directory from @INC. To delete multiple instances of the
94 same name from @INC you can specify the name multiple times.
96 To delete I<all> instances of I<all> the specified names from @INC you can
97 specify ':ALL' as the first parameter of C<no lib>. For example:
101 For each directory in LIST (called $dir here) the lib module also
102 checks to see if a directory called $dir/$archname/auto exists.
103 If so the $dir/$archname directory is assumed to be a corresponding
104 architecture specific directory and is also deleted from @INC.
106 If LIST includes both $dir and $dir/$archname then $dir/$archname will
107 be deleted from @INC twice (if $dir/$archname/auto exists).
110 =head2 RESTORING ORIGINAL @INC
112 When the lib module is first loaded it records the current value of @INC
113 in an array C<@lib::ORIG_INC>. To restore @INC to that value you
116 @INC = @lib::ORIG_INC;
121 AddINC - optional module which deals with paths relative to the source file.
125 Tim Bunce, 2nd June 1995.