Skip to content

Commit

Permalink
Upgrade local::lib. Do not use local::lib's --self-contained which is…
Browse files Browse the repository at this point in the history
… now deprecated. Fixes gh-33
  • Loading branch information
miyagawa committed Apr 10, 2010
1 parent 7d96bb7 commit e7877f9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 72 deletions.
84 changes: 22 additions & 62 deletions fatlib/local/lib.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ use File::Path ();
use Carp ();
use Config;

our $VERSION = '1.004009'; # 1.4.9
my @KNOWN_FLAGS = (qw/--self-contained/);
our $VERSION = '1.006000'; # 1.6.0

our @KNOWN_FLAGS = qw(--self-contained);

sub import {
my ($class, @args) = @_;
@args <= 1 + @KNOWN_FLAGS or die <<'DEATH';
Please see `perldoc local::lib` for directions on using this module.
DEATH

# Remember what PERL5LIB was when we started
my $perl5lib = $ENV{PERL5LIB} || '';
Expand Down Expand Up @@ -50,21 +48,7 @@ DEATH
}

if($arg_store{'self-contained'}) {
# 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

@INC = _uniq(
$class->install_base_arch_path($arg_store{path}),
$class->install_base_perl_path($arg_store{path}),
split( $Config{path_sep}, $perl5lib ),
$Config::Config{archlibexp},
$Config::Config{privlibexp},
);

# We explicitly set PERL5LIB here to the above de-duped list to prevent
# @INC from growing with each invocation
$ENV{PERL5LIB} = join( $Config{path_sep}, @INC );
die "FATAL: The local::lib --self-contained flag has never worked reliably and the original author, Mark Stosberg, was unable or unwilling to maintain it. As such, this flag has been removed from the local::lib codebase in order to prevent misunderstandings and potentially broken builds. The local::lib authors recommend that you look at the lib::core::only module shipped with this distribution in order to create a more robust environment that is equivalent to what --self-contained provided (although quite possibly not what you originally thought it provided due to the poor quality of the documentation, for which we apologise).\n";
}

$arg_store{path} = $class->resolve_path($arg_store{path});
Expand Down Expand Up @@ -350,7 +334,7 @@ sub build_environment_vars_for {
PERL5LIB => join($Config{path_sep},
$class->install_base_perl_path($path),
$class->install_base_arch_path($path),
($ENV{PERL5LIB} ?
(($ENV{PERL5LIB}||()) ?
($interpolate == INTERPOLATE_ENV
? ($ENV{PERL5LIB})
: (($^O ne 'MSWin32') ? '$PERL5LIB' : '%PERL5LIB%' ))
Expand All @@ -359,7 +343,7 @@ sub build_environment_vars_for {
PATH => join($Config{path_sep},
$class->install_base_bin_path($path),
($interpolate == INTERPOLATE_ENV
? $ENV{PATH}
? ($ENV{PATH}||())
: (($^O ne 'MSWin32') ? '$PATH' : '%PATH%' ))
),
)
Expand Down Expand Up @@ -397,11 +381,8 @@ In code -
From the shell -
# Install LWP and it's missing dependencies to the 'my_lwp' directory
perl -MCPAN -Mlocal::lib=my_lwp -e 'CPAN::install(LWP)'
# Install LWP and *all non-core* dependencies to the 'my_lwp' directory
perl -MCPAN -Mlocal::lib=--self-contained,my_lwp -e 'CPAN::install(LWP)'
# Install LWP and its missing dependencies to the '~/perl5' directory
perl -MCPAN -Mlocal::lib -e 'CPAN::install(LWP)'
# Just print out useful shell commands
$ perl -Mlocal::lib
Expand Down Expand Up @@ -453,35 +434,17 @@ You can also pass --bootstrap=~/foo to get a different location -
echo 'eval $(perl -I$HOME/foo/lib/perl5 -Mlocal::lib=$HOME/foo)' >>~/.bashrc
After writing your shell configuration file, be sure to re-read it to get the
changed settings into your current shell's environment.
. ~/.bashrc
If you are using C shell, you can do this as follows:
/bin/csh
echo $SHELL
/bin/csh
perl -I$HOME/perl5/lib/perl5 -Mlocal::lib >> ~/.cshrc
source ~/.cshrc
You can also pass --bootstrap=~/foo to get a different location -
perl Makefile.PL --bootstrap=~/foo
make test && make install
echo 'eval $(perl -I$HOME/foo/lib/perl5 -Mlocal::lib=$HOME/foo)' >> ~/.bashrc
. ~/.bashrc
changed settings into your current shell's environment. Bourne shells use C<.
~/.bashrc> for this, whereas C shells use C<source ~/.cshrc>. Replace .bashrc or
.cshrc with the name of the file you wrote above with the echo command.
If you're on a slower machine, or are operating under draconian disk space
limitations, you can disable the automatic generation of manpages from POD when
installing modules by using the C<--no-manpages> argument when bootstrapping:
perl Makefile.PL --bootstrap --no-manpages
If you want to install multiple Perl module environments, say for application evelopment,
If you want to install multiple Perl module environments, say for application development,
install local::lib globally and then:
cd ~/mydir1
Expand Down Expand Up @@ -585,6 +548,12 @@ PATH is appended to, rather than clobbered.
These values are then available for reference by any code after import.
=head1 CREATING A SELF-CONTAINED SET OF MODULES
See L<lib::core::only|lib::core::only> for one way to do this - but note that
there are a number of caveats, and the best approach is always to perform a
build against a clean perl (i.e. site and vendor as close to empty as possible).
=head1 METHODS
=head2 ensure_directory_structure_for
Expand Down Expand Up @@ -785,18 +754,9 @@ auto_install fixes kindly sponsored by http://www.takkle.com/
=head1 CONTRIBUTORS
Chris Nehren <apeiron@cpan.org> now oversees maintenance of local::lib, in
addition to providing doc patches and bootstrap fixes to prevent users from
shooting themselves in the foot (it's more likely than you think).
Patches to correctly output commands for csh style shells, as well as some
documentation additions, contributed by Christopher Nehren <apeiron@cpan.org>.
'--self-contained' feature contributed by Mark Stosberg <mark@summersault.com>.
Ability to pass '--self-contained' without a directory inspired by frew on
irc.perl.org/#catalyst.
Doc patches for a custom local::lib directory contributed by Torsten Raudssus
<torsten@raudssus.de>.
Expand All @@ -811,11 +771,11 @@ section. Many thanks!
Patch to add Win32 support contributed by Curtis Jewell <csjewell@cpan.org>.
kgish/#perl-help@irc.perl.org suggested revamping the section on sourcing the
shell file to make it clearer to those quickly reading the POD.
Warnings for missing PATH/PERL5LIB (as when not running interactively) silenced
by a patch from Marco Emilio Poleggi.
t0m and chrisa on #local-lib@irc.perl.org pointed out a PERL5LIB ordering issue
with C<--self-contained>.
Mark Stosberg <mark@summersault.com> provided the code for the now deleted
'--self-contained' option.
=head1 COPYRIGHT
Expand Down
26 changes: 16 additions & 10 deletions lib/App/cpanminus/script.pm
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,20 @@ DIAG
sleep 2;
}

sub _core_only_inc {
my($self, $base) = @_;
require local::lib;
(
local::lib->install_base_perl_path($base),
local::lib->install_base_arch_path($base),
@Config{qw(privlibexp archlibexp)},
);
}

sub _dump_inc {
my $self = shift;
my($self, $inc) = @_;

my @inc = map { qq('$_') } (@INC, '.'); # . for inc/Module/Install.pm
my @inc = map { qq('$_') } (@$inc, '.'); # . for inc/Module/Install.pm

open my $out, ">$self->{base}/DumpedINC.pm" or die $!;
local $" = ",";
Expand All @@ -444,15 +454,11 @@ sub _try_local_lib {
local $0 = 'cpanm'; # so curl/wget | perl works
$base ||= "~/perl5";
if ($self->{self_contained}) {
my @inc = @INC;
local $ENV{PERL5LIB} = '';
$self->_import_local_lib('--self-contained', $base);
$self->_dump_inc;
$self->{search_inc} = [ @INC ];
@INC = @inc;
} else {
$self->_import_local_lib($base);
my @inc = $self->_core_only_inc($base);
$self->_dump_inc(\@inc);
$self->{search_inc} = [ @inc ];
}
$self->_import_local_lib($base);
}

push @{$self->{bootstrap_deps}},
Expand Down

0 comments on commit e7877f9

Please sign in to comment.