[Bast-commits] r7495 - in local-lib/1.000/trunk: . lib/local t

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Wed Sep 2 22:35:38 GMT 2009


Author: t0m
Date: 2009-09-02 22:35:37 +0000 (Wed, 02 Sep 2009)
New Revision: 7495

Added:
   local-lib/1.000/trunk/t/de-dup.t
Modified:
   local-lib/1.000/trunk/Changes
   local-lib/1.000/trunk/lib/local/lib.pm
Log:
De-dup @INC and $ENV{PERL5LIB} entries

Modified: local-lib/1.000/trunk/Changes
===================================================================
--- local-lib/1.000/trunk/Changes	2009-09-02 22:33:42 UTC (rev 7494)
+++ local-lib/1.000/trunk/Changes	2009-09-02 22:35:37 UTC (rev 7495)
@@ -1,5 +1,8 @@
 Revision history for local::lib
 
+        - Ensure that $ENV{PERL5LIB} and @INC are always de-duped, stopping them
+          from growing if local::lib is invoked multiple times for the same path.
+
 1.004006 2009-08-25
         - Fix parsing of --self-contained and local lib directory. It's now
           possible to specify flags and the directory in any order. Also made

Modified: local-lib/1.000/trunk/lib/local/lib.pm
===================================================================
--- local-lib/1.000/trunk/lib/local/lib.pm	2009-09-02 22:33:42 UTC (rev 7494)
+++ local-lib/1.000/trunk/lib/local/lib.pm	2009-09-02 22:35:37 UTC (rev 7495)
@@ -53,17 +53,17 @@
     # The only directories that remain are those that we just defined and those
     # where core modules are stored.  We put PERL5LIB first, so it'll be favored
     # over privlibexp and archlibexp
-    my %seen;
-    @INC = grep { ! $seen{$_}++ } (
+
+    @INC = _uniq(
       $class->install_base_perl_path($arg_store{path}),
       $class->install_base_arch_path($arg_store{path}),
       split( $Config{path_sep}, $perl5lib ),
       $Config::Config{privlibexp},
       $Config::Config{archlibexp}
-  );
-    
+    );
+
     # We explicitly set PERL5LIB here to the above de-duped list to prevent
-    # @INC from growing with each invocation 
+    # @INC from growing with each invocation
     $ENV{PERL5LIB} = join( $Config{path_sep}, @INC );
   }
 
@@ -109,6 +109,11 @@
 
 =cut
 
+sub _uniq {
+    my %seen;
+    grep { ! $seen{$_}++ } @_;
+}
+
 sub resolve_path {
   my ($class, $path) = @_;
   $class->${pipeline qw(
@@ -206,7 +211,7 @@
     exit 0;
   } else {
     $class->setup_env_hash_for($path);
-    unshift(@INC, split($Config{path_sep}, $ENV{PERL5LIB}));
+    @INC = _uniq(split($Config{path_sep}, $ENV{PERL5LIB}), @INC);
   }
 }
 

Added: local-lib/1.000/trunk/t/de-dup.t
===================================================================
--- local-lib/1.000/trunk/t/de-dup.t	                        (rev 0)
+++ local-lib/1.000/trunk/t/de-dup.t	2009-09-02 22:35:37 UTC (rev 7495)
@@ -0,0 +1,34 @@
+use strict;
+use warnings;
+use Test::More;
+use File::Temp qw(tempdir);
+use Cwd;
+
+plan tests => 4;
+
+my $dir = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1);
+
+use local::lib ();
+local::lib->import($dir);
+local::lib->import($dir);
+
+{
+    my (%inc, %perl5lib);
+    map { $inc{$_}++ } @INC;
+    map { $perl5lib{$_} } split /:/, $ENV{PERL5LIB};
+    ok ! grep({ $inc{$_} > 1 } keys %inc), '@INC entries not duplicated';
+use Data::Dumper;
+warn Dumper(\@INC);
+    ok ! grep({ $perl5lib{$_} > 1 } keys %perl5lib), 'ENV{PERL5LIB} entries not duplicated';
+}
+
+local::lib->import('--self-contained', $dir);
+
+{
+    my (%inc, %perl5lib);
+    map { $inc{$_}++ } @INC;
+    map { $perl5lib{$_} } split /:/, $ENV{PERL5LIB};
+    ok ! grep({ $inc{$_} > 1 } keys %inc), '@INC entries not duplicated (--self-contained)';
+    ok ! grep({ $perl5lib{$_} > 1 } keys %perl5lib), 'ENV{PERL5LIB} entries not duplicated (--self-contained)';
+}
+




More information about the Bast-commits mailing list