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
# 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 );
}
=cut
+sub _uniq {
+ my %seen;
+ grep { ! $seen{$_}++ } @_;
+}
+
sub resolve_path {
my ($class, $path) = @_;
$class->${pipeline qw(
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);
}
}
--- /dev/null
+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)';
+}
+