Move the #7390 test from warn/op to comp/redef.
[p5sagit/p5-mst-13.2.git] / lib / lib_pm.PL
CommitLineData
60ed1d8c 1use Config;
2use File::Basename qw(&basename &dirname);
3use File::Spec;
4use Cwd;
5
6my $origdir = cwd;
7chdir dirname($0);
8my $file = basename($0, '.PL');
4755096e 9$file =~ s!_(pm)$!.$1!i;
60ed1d8c 10
11my $Config_archname = defined($Config{'archname'}) ? $Config{'archname'} : '';
12my $Config_ver = defined($Config{'version'}) ? $Config{'version'} : '';
13my @Config_inc_version_list = defined($Config{'inc_version_list'}) ?
14 reverse split / /, $Config{'inc_version_list'} : ();
15
16open OUT,">$file" or die "Can't create $file: $!";
17
18print "Extracting $file (with variable substitutions)\n";
19
20# In this section, perl variables will be expanded during extraction.
21# You can use $Config{...} to use Configure variables.
22
23print OUT <<"!GROK!THIS!";
e50aee73 24package lib;
25
427f4adb 26# THIS FILE IS AUTOMATICALLY GENERATED FROM lib_pm.PL.
27# ANY CHANGES TO THIS FILE WILL BE OVERWRITTEN BY THE NEXT PERL BUILD.
4633a7c4 28
60ed1d8c 29my \$archname = "$Config_archname";
30my \$ver = "$Config_ver";
31my \@inc_version_list = qw(@Config_inc_version_list);
32
33!GROK!THIS!
34print OUT <<'!NO!SUBS!';
4633a7c4 35
17f410f9 36our @ORIG_INC = @INC; # take a handy copy of 'original' value
37our $VERSION = '0.5564';
e50aee73 38
39sub import {
40 shift;
aeb5d71d 41
42 my %names;
a5f75d66 43 foreach (reverse @_) {
016609bc 44 if ($_ eq '') {
af3dad46 45 require Carp;
774d564b 46 Carp::carp("Empty compile time value given to use lib");
af3dad46 47 }
20408e3c 48 if (-e && ! -d _) {
49 require Carp;
50 Carp::carp("Parameter to use lib must be directory, not file");
51 }
4633a7c4 52 unshift(@INC, $_);
29d82f8d 53 # Add any previous version directories we found at configure time
54 foreach my $incver (@inc_version_list)
55 {
56 unshift(@INC, "$_/$incver") if -d "$_/$incver";
57 }
4633a7c4 58 # Put a corresponding archlib directory infront of $_ if it
59 # looks like $_ has an archlib directory below it.
427f4adb 60 unshift(@INC, "$_/$archname") if -d "$_/$archname/auto";
29d82f8d 61 unshift(@INC, "$_/$ver") if -d "$_/$ver";
62 unshift(@INC, "$_/$ver/$archname") if -d "$_/$ver/$archname";
4633a7c4 63 }
abef537a 64
65 # remove trailing duplicates
66 @INC = grep { ++$names{$_} == 1 } @INC;
67 return;
e50aee73 68}
69
70
71sub unimport {
72 shift;
e50aee73 73
74 my %names;
aeb5d71d 75 foreach (@_) {
4633a7c4 76 ++$names{$_};
77 ++$names{"$_/$archname"} if -d "$_/$archname/auto";
427f4adb 78 ++$names{"$_/$ver"} if -d "$_/$ver";
79 ++$names{"$_/$ver/$archname"} if -d "$_/$ver/$archname";
4633a7c4 80 }
e50aee73 81
aeb5d71d 82 # Remove ALL instances of each named directory.
83 @INC = grep { !exists $names{$_} } @INC;
abef537a 84 return;
e50aee73 85}
86
4633a7c4 871;
e50aee73 88__END__
89
90=head1 NAME
91
92lib - manipulate @INC at compile time
93
94=head1 SYNOPSIS
95
96 use lib LIST;
97
98 no lib LIST;
99
100=head1 DESCRIPTION
101
102This is a small simple module which simplifies the manipulation of @INC
103at compile time.
104
105It is typically used to add extra directories to perl's search path so
106that later C<use> or C<require> statements will find modules which are
107not located on perl's default search path.
108
aeb5d71d 109=head2 Adding directories to @INC
e50aee73 110
111The parameters to C<use lib> are added to the start of the perl search
112path. Saying
113
114 use lib LIST;
115
4633a7c4 116is I<almost> the same as saying
e50aee73 117
118 BEGIN { unshift(@INC, LIST) }
119
4633a7c4 120For each directory in LIST (called $dir here) the lib module also
121checks to see if a directory called $dir/$archname/auto exists.
122If so the $dir/$archname directory is assumed to be a corresponding
123architecture specific directory and is added to @INC in front of $dir.
124
aeb5d71d 125To avoid memory leaks, all trailing duplicate entries in @INC are
126removed.
4633a7c4 127
aeb5d71d 128=head2 Deleting directories from @INC
e50aee73 129
130You should normally only add directories to @INC. If you need to
131delete directories from @INC take care to only delete those which you
132added yourself or which you are certain are not needed by other modules
133in your script. Other modules may have added directories which they
134need for correct operation.
135
aeb5d71d 136The C<no lib> statement deletes all instances of each named directory
137from @INC.
e50aee73 138
4633a7c4 139For each directory in LIST (called $dir here) the lib module also
140checks to see if a directory called $dir/$archname/auto exists.
141If so the $dir/$archname directory is assumed to be a corresponding
142architecture specific directory and is also deleted from @INC.
143
aeb5d71d 144=head2 Restoring original @INC
e50aee73 145
146When the lib module is first loaded it records the current value of @INC
147in an array C<@lib::ORIG_INC>. To restore @INC to that value you
4633a7c4 148can say
e50aee73 149
150 @INC = @lib::ORIG_INC;
151
e50aee73 152
153=head1 SEE ALSO
154
af3dad46 155FindBin - optional module which deals with paths relative to the source file.
e50aee73 156
157=head1 AUTHOR
158
159Tim Bunce, 2nd June 1995.
160
161=cut
60ed1d8c 162!NO!SUBS!
163
164close OUT or die "Can't close $file: $!";
165chdir $origdir;