X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Flib_pm.PL;h=2c12be4dc7fb33304d2b3ff6678ec6f4809e40d6;hb=b9ad30b40cf004f5ea6fd7a945a950cf873aed7b;hp=0d2a73b842f1f20138ec649810c3f5b1f0a31245;hpb=4755096ec61711c5104ba0b6b9314f32ca0351fe;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/lib_pm.PL b/lib/lib_pm.PL index 0d2a73b..2c12be4 100644 --- a/lib/lib_pm.PL +++ b/lib/lib_pm.PL @@ -8,10 +8,30 @@ chdir dirname($0); my $file = basename($0, '.PL'); $file =~ s!_(pm)$!.$1!i; -my $Config_archname = defined($Config{'archname'}) ? $Config{'archname'} : ''; -my $Config_ver = defined($Config{'version'}) ? $Config{'version'} : ''; -my @Config_inc_version_list = defined($Config{'inc_version_list'}) ? - reverse split / /, $Config{'inc_version_list'} : (); +my $useConfig; +my $Config_archname; +my $Config_version; +my $Config_inc_version_list; + +# Expand the variables only if explicitly requested because +# otherwise relocating Perl becomes much harder. + +if ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS}) { + $useConfig = ''; + $Config_archname = qq('$Config{archname}'); + $Config_version = qq('$Config{version}'); + my @Config_inc_version_list = + reverse split / /, $Config{inc_version_list}; + $Config_inc_version_list = + @Config_inc_version_list ? + qq(@Config_inc_version_list) : q(()); +} else { + $useConfig = 'use Config;'; + $Config_archname = q($Config{archname}); + $Config_version = q($Config{version}); + $Config_inc_version_list = + q(reverse split / /, $Config{inc_version_list}); +} open OUT,">$file" or die "Can't create $file: $!"; @@ -23,41 +43,62 @@ print "Extracting $file (with variable substitutions)\n"; print OUT <<"!GROK!THIS!"; package lib; -use 5.005_64; +# THIS FILE IS AUTOMATICALLY GENERATED FROM lib_pm.PL. +# ANY CHANGES TO THIS FILE WILL BE OVERWRITTEN BY THE NEXT PERL BUILD. + +$useConfig + +use strict; -my \$archname = "$Config_archname"; -my \$ver = "$Config_ver"; -my \@inc_version_list = qw(@Config_inc_version_list); +my \$archname = $Config_archname; +my \$version = $Config_version; +my \@inc_version_list = $Config_inc_version_list; !GROK!THIS! print OUT <<'!NO!SUBS!'; our @ORIG_INC = @INC; # take a handy copy of 'original' value -our $VERSION = '0.5564'; +our $VERSION = '0.5565'; +my $Is_MacOS = $^O eq 'MacOS'; +my $Mac_FS; +if ($Is_MacOS) { + require File::Spec; + $Mac_FS = eval { require Mac::FileSpec::Unixish }; +} sub import { shift; my %names; foreach (reverse @_) { - if ($_ eq '') { + my $path = $_; # we'll be modifying it, so break the alias + if ($path eq '') { require Carp; Carp::carp("Empty compile time value given to use lib"); } - if (-e && ! -d _) { + + $path = _nativize($path); + + if (-e $path && ! -d _) { require Carp; Carp::carp("Parameter to use lib must be directory, not file"); } - unshift(@INC, $_); - # Add any previous version directories we found at configure time - foreach my $incver (@inc_version_list) - { - unshift(@INC, "$_/$incver") if -d "$_/$incver"; - } - # Put a corresponding archlib directory infront of $_ if it - # looks like $_ has an archlib directory below it. - unshift(@INC, "$_/$ver") if -d "$_/$ver"; - unshift(@INC, "$_/$ver/$archname") if -d "$_/$ver/$archname"; + unshift(@INC, $path); + # Add any previous version directories we found at configure time + foreach my $incver (@inc_version_list) + { + my $dir = $Is_MacOS + ? File::Spec->catdir( $path, $incver ) + : "$path/$incver"; + unshift(@INC, $dir) if -d $dir; + } + # Put a corresponding archlib directory in front of $path if it + # looks like $path has an archlib directory below it. + my($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir) + = _get_dirs($path); + unshift(@INC, $arch_dir) if -d $arch_auto_dir; + unshift(@INC, $version_dir) if -d $version_dir; + unshift(@INC, $version_arch_dir) if -d $version_arch_dir; } # remove trailing duplicates @@ -71,8 +112,14 @@ sub unimport { my %names; foreach (@_) { - ++$names{$_}; - ++$names{"$_/$archname"} if -d "$_/$archname/auto"; + my $path = _nativize($_); + + my($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir) + = _get_dirs($path); + ++$names{$path}; + ++$names{$arch_dir} if -d $arch_auto_dir; + ++$names{$version_dir} if -d $version_dir; + ++$names{$version_arch_dir} if -d $version_arch_dir; } # Remove ALL instances of each named directory. @@ -80,6 +127,37 @@ sub unimport { return; } +sub _get_dirs { + my($dir) = @_; + my($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir); + + # we could use this for all platforms in the future, but leave it + # Mac-only for now, until there is more time for testing it. + if ($Is_MacOS) { + $arch_auto_dir = File::Spec->catdir( $dir, $archname, 'auto' ); + $arch_dir = File::Spec->catdir( $dir, $archname, ); + $version_dir = File::Spec->catdir( $dir, $version ); + $version_arch_dir = File::Spec->catdir( $dir, $version, $archname ); + } else { + $arch_auto_dir = "$dir/$archname/auto"; + $arch_dir = "$dir/$archname"; + $version_dir = "$dir/$version"; + $version_arch_dir = "$dir/$version/$archname"; + } + return($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir); +} + +sub _nativize { + my($dir) = @_; + + if ($Is_MacOS && $Mac_FS && ! -d $dir) { + $dir = Mac::FileSpec::Unixish::nativize($dir); + $dir .= ":" unless $dir =~ /:$/; + } + + return $dir; +} + 1; __END__ @@ -118,6 +196,10 @@ checks to see if a directory called $dir/$archname/auto exists. If so the $dir/$archname directory is assumed to be a corresponding architecture specific directory and is added to @INC in front of $dir. +The current value of C<$archname> can be found with this command: + + perl -V:archname + To avoid memory leaks, all trailing duplicate entries in @INC are removed. @@ -145,6 +227,22 @@ can say @INC = @lib::ORIG_INC; +=head1 CAVEATS + +In order to keep lib.pm small and simple, it only works with Unix +filepaths. This doesn't mean it only works on Unix, but non-Unix +users must first translate their file paths to Unix conventions. + + # VMS users wanting to put [.stuff.moo] into + # their @INC would write + use lib 'stuff/moo'; + +=head1 NOTES + +In the future, this module will likely use File::Spec for determining +paths, as it does now for Mac OS (where Unix-style or Mac-style paths +work, and Unix-style paths are converted properly to Mac-style paths +before being added to @INC). =head1 SEE ALSO