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