This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Locale::Codes 2.02.
[perl5.git] / lib / lib_pm.PL
CommitLineData
60ed1d8c
GS
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
e9c6cca7
GS
11my $useConfig;
12my $Config_archname;
13my $Config_version;
14my $Config_inc_version_list;
15
16# Expand the variables only if explicitly requested because
17# otherwise relocating Perl becomes much harder.
18
19if ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS}) {
20 $useConfig = '';
21 $Config_archname = qq('$Config{archname}');
22 $Config_version = qq('$Config{version}');
23 my @Config_inc_version_list =
24 reverse split / /, $Config{inc_version_list};
25 $Config_inc_version_list =
26 @Config_inc_version_list ?
27 qq(@Config_inc_version_list) : q(());
28} else {
29 $useConfig = 'use Config;';
30 $Config_archname = q($Config{archname});
31 $Config_version = q($Config{version});
32 $Config_inc_version_list =
91a12f7d 33 q(reverse split / /, $Config{inc_version_list});
e9c6cca7 34}
60ed1d8c
GS
35
36open OUT,">$file" or die "Can't create $file: $!";
37
38print "Extracting $file (with variable substitutions)\n";
39
40# In this section, perl variables will be expanded during extraction.
41# You can use $Config{...} to use Configure variables.
42
43print OUT <<"!GROK!THIS!";
e50aee73
AD
44package lib;
45
427f4adb
TC
46# THIS FILE IS AUTOMATICALLY GENERATED FROM lib_pm.PL.
47# ANY CHANGES TO THIS FILE WILL BE OVERWRITTEN BY THE NEXT PERL BUILD.
4633a7c4 48
e9c6cca7
GS
49$useConfig
50
51my \$archname = $Config_archname;
52my \$version = $Config_version;
53my \@inc_version_list = $Config_inc_version_list;
60ed1d8c
GS
54
55!GROK!THIS!
56print OUT <<'!NO!SUBS!';
4633a7c4 57
17f410f9
GS
58our @ORIG_INC = @INC; # take a handy copy of 'original' value
59our $VERSION = '0.5564';
e50aee73
AD
60
61sub import {
62 shift;
aeb5d71d
GS
63
64 my %names;
a5f75d66 65 foreach (reverse @_) {
016609bc 66 if ($_ eq '') {
af3dad46 67 require Carp;
774d564b 68 Carp::carp("Empty compile time value given to use lib");
af3dad46 69 }
20408e3c
GS
70 if (-e && ! -d _) {
71 require Carp;
72 Carp::carp("Parameter to use lib must be directory, not file");
73 }
4633a7c4 74 unshift(@INC, $_);
29d82f8d
GS
75 # Add any previous version directories we found at configure time
76 foreach my $incver (@inc_version_list)
77 {
78 unshift(@INC, "$_/$incver") if -d "$_/$incver";
79 }
4633a7c4
LW
80 # Put a corresponding archlib directory infront of $_ if it
81 # looks like $_ has an archlib directory below it.
e9c6cca7
GS
82 unshift(@INC, "$_/$archname") if -d "$_/$archname/auto";
83 unshift(@INC, "$_/$version") if -d "$_/$version";
84 unshift(@INC, "$_/$version/$archname") if -d "$_/$version/$archname";
4633a7c4 85 }
abef537a
GS
86
87 # remove trailing duplicates
88 @INC = grep { ++$names{$_} == 1 } @INC;
89 return;
e50aee73
AD
90}
91
92
93sub unimport {
94 shift;
e50aee73
AD
95
96 my %names;
aeb5d71d 97 foreach (@_) {
4633a7c4 98 ++$names{$_};
e9c6cca7
GS
99 ++$names{"$_/$archname"} if -d "$_/$archname/auto";
100 ++$names{"$_/$version"} if -d "$_/$version";
101 ++$names{"$_/$version/$archname"} if -d "$_/$version/$archname";
4633a7c4 102 }
e50aee73 103
aeb5d71d
GS
104 # Remove ALL instances of each named directory.
105 @INC = grep { !exists $names{$_} } @INC;
abef537a 106 return;
e50aee73
AD
107}
108
4633a7c4 1091;
e50aee73
AD
110__END__
111
112=head1 NAME
113
114lib - manipulate @INC at compile time
115
116=head1 SYNOPSIS
117
118 use lib LIST;
119
120 no lib LIST;
121
122=head1 DESCRIPTION
123
124This is a small simple module which simplifies the manipulation of @INC
125at compile time.
126
127It is typically used to add extra directories to perl's search path so
128that later C<use> or C<require> statements will find modules which are
129not located on perl's default search path.
130
aeb5d71d 131=head2 Adding directories to @INC
e50aee73
AD
132
133The parameters to C<use lib> are added to the start of the perl search
134path. Saying
135
136 use lib LIST;
137
4633a7c4 138is I<almost> the same as saying
e50aee73
AD
139
140 BEGIN { unshift(@INC, LIST) }
141
4633a7c4
LW
142For each directory in LIST (called $dir here) the lib module also
143checks to see if a directory called $dir/$archname/auto exists.
144If so the $dir/$archname directory is assumed to be a corresponding
145architecture specific directory and is added to @INC in front of $dir.
146
aeb5d71d
GS
147To avoid memory leaks, all trailing duplicate entries in @INC are
148removed.
4633a7c4 149
aeb5d71d 150=head2 Deleting directories from @INC
e50aee73
AD
151
152You should normally only add directories to @INC. If you need to
153delete directories from @INC take care to only delete those which you
154added yourself or which you are certain are not needed by other modules
155in your script. Other modules may have added directories which they
156need for correct operation.
157
aeb5d71d
GS
158The C<no lib> statement deletes all instances of each named directory
159from @INC.
e50aee73 160
4633a7c4
LW
161For each directory in LIST (called $dir here) the lib module also
162checks to see if a directory called $dir/$archname/auto exists.
163If so the $dir/$archname directory is assumed to be a corresponding
164architecture specific directory and is also deleted from @INC.
165
aeb5d71d 166=head2 Restoring original @INC
e50aee73
AD
167
168When the lib module is first loaded it records the current value of @INC
169in an array C<@lib::ORIG_INC>. To restore @INC to that value you
4633a7c4 170can say
e50aee73
AD
171
172 @INC = @lib::ORIG_INC;
173
e7bf5e49
MS
174=head1 CAVEATS
175
176In order to keep lib.pm small and simple, it only works with Unix
177filepaths. This doesn't mean it only works on Unix, but non-Unix
178users must first translate their file paths to Unix conventions.
179
180 # VMS users wanting to put [.stuff.moo] into
181 # their @INC would write
182 use lib 'stuff/moo';
e50aee73
AD
183
184=head1 SEE ALSO
185
af3dad46 186FindBin - optional module which deals with paths relative to the source file.
e50aee73
AD
187
188=head1 AUTHOR
189
190Tim Bunce, 2nd June 1995.
191
192=cut
60ed1d8c
GS
193!NO!SUBS!
194
195close OUT or die "Can't close $file: $!";
196chdir $origdir;