Start anew
[git/jnareb-git.git] / lib / perl5 / 5.6.1 / lib.pm
blob077dd633e7d6bd9af97dfd2382eac0f36c712ab6
1 package lib;
3 use 5.005_64;
4 use Config;
6 my $archname = defined($Config{'archname'}) ? $Config{'archname'} : '';
7 my $ver = defined($Config{'version'}) ? $Config{'version'} : '';
8 my @inc_version_list = defined($Config{'inc_version_list'}) ?
9 reverse split / /, $Config{'inc_version_list'} : ();
11 our @ORIG_INC = @INC; # take a handy copy of 'original' value
12 our $VERSION = '0.5564';
14 sub import {
15 shift;
17 my %names;
18 foreach (reverse @_) {
19 if ($_ eq '') {
20 require Carp;
21 Carp::carp("Empty compile time value given to use lib");
23 if (-e && ! -d _) {
24 require Carp;
25 Carp::carp("Parameter to use lib must be directory, not file");
27 unshift(@INC, $_);
28 # Add any previous version directories we found at configure time
29 foreach my $incver (@inc_version_list)
31 unshift(@INC, "$_/$incver") if -d "$_/$incver";
33 # Put a corresponding archlib directory infront of $_ if it
34 # looks like $_ has an archlib directory below it.
35 unshift(@INC, "$_/$archname") if -d "$_/$archname/auto";
36 unshift(@INC, "$_/$ver") if -d "$_/$ver";
37 unshift(@INC, "$_/$ver/$archname") if -d "$_/$ver/$archname";
40 # remove trailing duplicates
41 @INC = grep { ++$names{$_} == 1 } @INC;
42 return;
46 sub unimport {
47 shift;
49 my %names;
50 foreach (@_) {
51 ++$names{$_};
52 ++$names{"$_/$archname"} if -d "$_/$archname/auto";
53 ++$names{"$_/$ver"} if -d "$_/$ver";
54 ++$names{"$_/$ver/$archname"} if -d "$_/$ver/$archname";
57 # Remove ALL instances of each named directory.
58 @INC = grep { !exists $names{$_} } @INC;
59 return;
63 __END__
65 =head1 NAME
67 lib - manipulate @INC at compile time
69 =head1 SYNOPSIS
71 use lib LIST;
73 no lib LIST;
75 =head1 DESCRIPTION
77 This is a small simple module which simplifies the manipulation of @INC
78 at compile time.
80 It is typically used to add extra directories to perl's search path so
81 that later C<use> or C<require> statements will find modules which are
82 not located on perl's default search path.
84 =head2 Adding directories to @INC
86 The parameters to C<use lib> are added to the start of the perl search
87 path. Saying
89 use lib LIST;
91 is I<almost> the same as saying
93 BEGIN { unshift(@INC, LIST) }
95 For each directory in LIST (called $dir here) the lib module also
96 checks to see if a directory called $dir/$archname/auto exists.
97 If so the $dir/$archname directory is assumed to be a corresponding
98 architecture specific directory and is added to @INC in front of $dir.
100 To avoid memory leaks, all trailing duplicate entries in @INC are
101 removed.
103 =head2 Deleting directories from @INC
105 You should normally only add directories to @INC. If you need to
106 delete directories from @INC take care to only delete those which you
107 added yourself or which you are certain are not needed by other modules
108 in your script. Other modules may have added directories which they
109 need for correct operation.
111 The C<no lib> statement deletes all instances of each named directory
112 from @INC.
114 For each directory in LIST (called $dir here) the lib module also
115 checks to see if a directory called $dir/$archname/auto exists.
116 If so the $dir/$archname directory is assumed to be a corresponding
117 architecture specific directory and is also deleted from @INC.
119 =head2 Restoring original @INC
121 When the lib module is first loaded it records the current value of @INC
122 in an array C<@lib::ORIG_INC>. To restore @INC to that value you
123 can say
125 @INC = @lib::ORIG_INC;
128 =head1 SEE ALSO
130 FindBin - optional module which deals with paths relative to the source file.
132 =head1 AUTHOR
134 Tim Bunce, 2nd June 1995.
136 =cut