Re: [MacPerl-Porters] [PROPOSED PATCHES] lib.pm/lib.t
[email protected] (Thomas Wegner) Fri, 31 May 2002 13:47:19 +0200
| Newsgroups | perl.macperl.porters |
|---|---|
| Message-ID | <p04320402b91d0feb4453@[149.225.17.179]> |
Good morning,
here are (proposed) patches for lib.t and lib_pm.PL. To apply or not
to apply, that's the question here :-).
Do VMS et al. allow native paths in @INC? I don't know, but I hope so.
diff -ru lib.t.orig lib.t
--- lib.t.orig Wed Apr 24 08:34:04 2002
+++ lib.t Fri May 31 13:22:57 2002
@@ -18,10 +18,9 @@
my $Auto_Dir;
my $Module;
BEGIN {
- # lib.pm is documented to only work with Unix filepaths.
@lib_dir = qw(stuff moo);
- $Lib_Dir = join "/", @lib_dir;
- $Arch_Dir = join "/", @lib_dir, $Config{archname};
+ $Lib_Dir = File::Spec->catdir( @lib_dir );
+ $Arch_Dir = File::Spec->catdir( @lib_dir, $Config{archname} );
# create the auto/ directory and a module
$Auto_Dir = File::Spec->catdir(@lib_dir, $Config{archname},'auto');
@@ -56,8 +55,7 @@
is( $INC[0], $Arch_Dir, ' auto/ dir in front of that' );
is( grep(/^\Q$Lib_Dir\E$/, @INC), 1, ' no duplicates' );
- # Yes, %INC uses Unixy filepaths.
- is( $INC{'Yup.pm'}, join("/",$Lib_Dir, 'Yup.pm'), '%INC set
properly' );
+ is( $INC{'Yup.pm'}, File::Spec->catfile( $Lib_Dir, 'Yup.pm'),
'%INC set properly' );
is( eval { do 'Yup.pm' }, 42, 'do() works' );
ok( eval { require Yup; }, ' require()' );
diff -ru lib_pm.PL.orig lib_pm.PL
--- lib_pm.PL.orig Wed Apr 24 08:34:04 2002
+++ lib_pm.PL Fri May 31 13:25:33 2002
@@ -54,6 +54,7 @@
!GROK!THIS!
print OUT <<'!NO!SUBS!';
+use File::Spec;
our @ORIG_INC = @INC; # take a handy copy of 'original' value
our $VERSION = '0.5564';
@@ -75,13 +76,18 @@
# Add any previous version directories we found at configure time
foreach my $incver (@inc_version_list)
{
- unshift(@INC, "$_/$incver") if -d "$_/$incver";
+ my $dir = File::Spec->catdir( $_, $incver );
+ unshift(@INC, $dir) if -d $dir;
}
# 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";
+ my $arch_auto_dir = File::Spec->catdir( $_, $archname, 'auto' );
+ my $arch_dir = File::Spec->catdir( $_, $archname );
+ my $version_dir = File::Spec->catdir( $_, $version );
+ my $version_arch_dir = File::Spec->catdir( $_, $version, $archname );
+ 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 +101,14 @@
my %names;
foreach (@_) {
+ my $arch_auto_dir = File::Spec->catdir( $_, $archname, 'auto' );
+ my $arch_dir = File::Spec->catdir( $_, $archname );
+ my $version_dir = File::Spec->catdir( $_, $version );
+ my $version_arch_dir = File::Spec->catdir( $_, $version, $archname );
++$names{$_};
- ++$names{"$_/$archname"} if -d "$_/$archname/auto";
- ++$names{"$_/$version"} if -d "$_/$version";
- ++$names{"$_/$version/$archname"} if -d "$_/$version/$archname";
+ ++$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.
@@ -140,9 +150,18 @@
BEGIN { unshift(@INC, LIST) }
For each directory in LIST (called $dir here) the lib module also
-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.
+checks to see if a directory $arch_auto_dir, where
+
+ $arch_auto_dir = File::Spec->catdir( $dir, $archname, 'auto' );
+
+exists.
+
+If so, a directory $arch_dir, where
+
+ $arch_dir = File::Spec->catdir( $dir, $archname );
+
+is assumed to be a corresponding architecture specific directory and
+is added to @INC in front of $dir.
To avoid memory leaks, all trailing duplicate entries in @INC are
removed.
@@ -171,14 +190,16 @@
@INC = @lib::ORIG_INC;
-=head1 CAVEATS
+=head1 NOTE
-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.
+Prior to Perl version 5.8.0, the lib module only worked with Unix
+filepaths. This restriction has been removed. We now use File::Spec
+internally to create platform specific paths. Thus, there's no need
+to translate file paths to Unix conventions. However, if you want to,
+this still works, e.g.:
# VMS users wanting to put [.stuff.moo] into
- # their @INC would write
+ # their @INC could write
use lib 'stuff/moo';
=head1 SEE ALSO
__END__ of 2 patches
Best regards,
--Thomas