X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Flib_pm.PL;h=2c12be4dc7fb33304d2b3ff6678ec6f4809e40d6;hb=b9ad30b40cf004f5ea6fd7a945a950cf873aed7b;hp=66b4944de507fd087701057ddd9140bf32692836;hpb=0e06870bf080a38cda51c06c6612359afc2334e1;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/lib_pm.PL b/lib/lib_pm.PL index 66b4944..2c12be4 100644 --- a/lib/lib_pm.PL +++ b/lib/lib_pm.PL @@ -30,7 +30,7 @@ if ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS}) { $Config_archname = q($Config{archname}); $Config_version = q($Config{version}); $Config_inc_version_list = - q(reverse split / /, qw($Config{inc_version_list})); + q(reverse split / /, $Config{inc_version_list}); } open OUT,">$file" or die "Can't create $file: $!"; @@ -48,6 +48,8 @@ package lib; $useConfig +use strict; + my \$archname = $Config_archname; my \$version = $Config_version; my \@inc_version_list = $Config_inc_version_list; @@ -56,32 +58,47 @@ my \@inc_version_list = $Config_inc_version_list; 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, "$_/$archname") if -d "$_/$archname/auto"; - unshift(@INC, "$_/$version") if -d "$_/$version"; - unshift(@INC, "$_/$version/$archname") if -d "$_/$version/$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 @@ -95,10 +112,14 @@ sub unimport { my %names; foreach (@_) { - ++$names{$_}; - ++$names{"$_/$archname"} if -d "$_/$archname/auto"; - ++$names{"$_/$version"} if -d "$_/$version"; - ++$names{"$_/$version/$archname"} if -d "$_/$version/$archname"; + 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. @@ -106,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__ @@ -144,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. @@ -171,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