develooper Front page | perl.perl5.porters | Postings from February 2003

Re: [patch] small lib.pm bufgixes

Thread Previous | Thread Next
From:
Alex Vandiver
Date:
February 27, 2003 04:13
Subject:
Re: [patch] small lib.pm bufgixes
Message ID:
1046348018.32257.35.camel@supox
On Thu, 2003-02-27 at 01:18, Benjamin Goldberg wrote:
> Alex Vandiver wrote:
> [snip]
> >   Finally, I added a catch so that CODE blocks which are inserted into
> > @INC don't get treated as strings.
> 
> Coderefs are not the only refs allowed in @INC -- you can put in an
> arrayref or a blessed refs, too. [snip useful information]
Interesting.  People's lack of knowledge is probably partially caused by
the fact that quite a few cool modules used the functionality soon after
5.6.1 came out, when it wasn't documented.  I know I only remembered it
because I'd seen/heard of tools which used it, but had never seen the
spec.
  In any case, I've updated the patch below -- and fixed a dumb mistake
in the original patch (I should never assume I'm smarter than diff..) 
I've also tested it with Ingy's only.pm, with no ill effects.
 - Alex

diff -ruN perl-current/lib/lib_pm.PL perl-patched/lib/lib_pm.PL
--- perl-current/lib/lib_pm.PL	Sun Aug 25 11:14:25 2002
+++ perl-patched/lib/lib_pm.PL	Thu Feb 27 06:43:06 2003
@@ -71,17 +71,20 @@
 
     my %names;
     foreach (reverse @_) {
-	my $path = $_;		# we'll be modifying it, so break the alias
-	if ($path eq '') {
+        if (!defined $_ or $_ eq '') {
 	    require Carp;
 	    Carp::carp("Empty compile time value given to use lib");
+	    next;
 	}
 
+	my $path = $_;		# we'll be modifying it, so break the alias
+	unshift(@INC, $path) && next if ref $path; # Skip refs
 	$path = _nativize($path);
 
 	if (-e $path && ! -d _) {
 	    require Carp;
 	    Carp::carp("Parameter to use lib must be directory, not file");
+	    next;
 	}
 	unshift(@INC, $path);
 	# Add any previous version directories we found at configure time
@@ -112,11 +115,17 @@
 
     my %names;
     foreach (@_) {
-	local $_ = _nativize($_);
+        if (!defined $_ or $_ eq '') {
+	    require Carp;
+	    Carp::carp("Empty compile time value given to no lib");
+	    next;
+	}
+	my $path = $_;          # we'll be modifying it, so break the alias
+	$path = _nativize($path);
 
 	my($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir)
-	    = _get_dirs($_);
-	++$names{$_};
+	    = _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;
@@ -134,15 +143,15 @@
     # 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( $_, $archname, 'auto' );
-	$arch_dir         = File::Spec->catdir( $_, $archname, );
-	$version_dir      = File::Spec->catdir( $_, $version );
-	$version_arch_dir = File::Spec->catdir( $_, $version, $archname );
+	$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    = "$_/$archname/auto";
-	$arch_dir         = "$_/$archname";
-	$version_dir      = "$_/$version";
-	$version_arch_dir = "$_/$version/$archname";
+	$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);
 }



-- 
Networking -- only one letter away from not working.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About