This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove stale code from Thread.xs.
[perl5.git] / lib / lib.pm
CommitLineData
e50aee73
AD
1package lib;
2
774d564b 3use vars qw(@ORIG_INC);
4633a7c4
LW
4use Config;
5
6my $archname = $Config{'archname'};
7
e50aee73
AD
8@ORIG_INC = @INC; # take a handy copy of 'original' value
9
10
11sub import {
12 shift;
a5f75d66 13 foreach (reverse @_) {
016609bc
BP
14 ## Ignore this if not defined.
15 next unless defined($_);
16 if ($_ eq '') {
af3dad46 17 require Carp;
774d564b 18 Carp::carp("Empty compile time value given to use lib");
19 # at foo.pl line ...
af3dad46 20 }
4633a7c4
LW
21 unshift(@INC, $_);
22 # Put a corresponding archlib directory infront of $_ if it
23 # looks like $_ has an archlib directory below it.
774d564b 24 if (-d "$_/$archname") {
25 unshift(@INC, "$_/$archname") if -d "$_/$archname/auto";
26 unshift(@INC, "$_/$archname/$]") if -d "$_/$archname/$]/auto";
27 }
4633a7c4 28 }
e50aee73
AD
29}
30
31
32sub unimport {
33 shift;
34 my $mode = shift if $_[0] =~ m/^:[A-Z]+/;
35
36 my %names;
4633a7c4
LW
37 foreach(@_) {
38 ++$names{$_};
39 ++$names{"$_/$archname"} if -d "$_/$archname/auto";
40 }
e50aee73
AD
41
42 if ($mode and $mode eq ':ALL') {
43 # Remove ALL instances of each named directory.
44 @INC = grep { !exists $names{$_} } @INC;
45 } else {
46 # Remove INITIAL instance(s) of each named directory.
47 @INC = grep { --$names{$_} < 0 } @INC;
48 }
49}
50
4633a7c4 511;
e50aee73
AD
52__END__
53
54=head1 NAME
55
56lib - manipulate @INC at compile time
57
58=head1 SYNOPSIS
59
60 use lib LIST;
61
62 no lib LIST;
63
64=head1 DESCRIPTION
65
66This is a small simple module which simplifies the manipulation of @INC
67at compile time.
68
69It is typically used to add extra directories to perl's search path so
70that later C<use> or C<require> statements will find modules which are
71not located on perl's default search path.
72
e50aee73
AD
73=head2 ADDING DIRECTORIES TO @INC
74
75The parameters to C<use lib> are added to the start of the perl search
76path. Saying
77
78 use lib LIST;
79
4633a7c4 80is I<almost> the same as saying
e50aee73
AD
81
82 BEGIN { unshift(@INC, LIST) }
83
4633a7c4
LW
84For each directory in LIST (called $dir here) the lib module also
85checks to see if a directory called $dir/$archname/auto exists.
86If so the $dir/$archname directory is assumed to be a corresponding
87architecture specific directory and is added to @INC in front of $dir.
88
89If LIST includes both $dir and $dir/$archname then $dir/$archname will
90be added to @INC twice (if $dir/$archname/auto exists).
91
e50aee73
AD
92=head2 DELETING DIRECTORIES FROM @INC
93
94You should normally only add directories to @INC. If you need to
95delete directories from @INC take care to only delete those which you
96added yourself or which you are certain are not needed by other modules
97in your script. Other modules may have added directories which they
98need for correct operation.
99
100By default the C<no lib> statement deletes the I<first> instance of
101each named directory from @INC. To delete multiple instances of the
102same name from @INC you can specify the name multiple times.
103
104To delete I<all> instances of I<all> the specified names from @INC you can
105specify ':ALL' as the first parameter of C<no lib>. For example:
106
107 no lib qw(:ALL .);
108
4633a7c4
LW
109For each directory in LIST (called $dir here) the lib module also
110checks to see if a directory called $dir/$archname/auto exists.
111If so the $dir/$archname directory is assumed to be a corresponding
112architecture specific directory and is also deleted from @INC.
113
114If LIST includes both $dir and $dir/$archname then $dir/$archname will
115be deleted from @INC twice (if $dir/$archname/auto exists).
116
e50aee73
AD
117=head2 RESTORING ORIGINAL @INC
118
119When the lib module is first loaded it records the current value of @INC
120in an array C<@lib::ORIG_INC>. To restore @INC to that value you
4633a7c4 121can say
e50aee73
AD
122
123 @INC = @lib::ORIG_INC;
124
e50aee73
AD
125
126=head1 SEE ALSO
127
af3dad46 128FindBin - optional module which deals with paths relative to the source file.
e50aee73
AD
129
130=head1 AUTHOR
131
132Tim Bunce, 2nd June 1995.
133
134=cut
135