Subject: | PATCH: add "--self-contained" option for generating self-contained dependency chains |
Matt,
Thanks for 'local::lib'. I've found it rather useful.
I wanted to use it to generate a self-contained folder of a module with
all of it's dependencies.
'local::lib' is great for helping with this, but because it keeps the
global "INC" paths, it wasn't quit working for me-- dependencies already
installed locally weren't added to my local directory.
To solve this I created the attached patch to add a "--self-contained"
option. When this flag is used, only the path to core modules and the
'local' directories are preserved.
It worked well for me in testing.
Mark
Subject: | self_contained_local_lib.patch |
--- /usr/local/share/perl/5.8.8/local/lib.pm 2008-08-06 06:52:36.000000000 -0400
+++ local/lib.pm 2008-09-27 16:38:58.000000000 -0400
@@ -14,9 +14,24 @@
our $VERSION = '1.002000'; # 1.2.0
sub import {
- my ($class, $path) = @_;
+ my ($class, @args) = @_;
+
+ # The path is required, but last in the list, so we pop, not shift here.
+ my $path = pop @args;
$path = $class->resolve_path($path);
$class->setup_local_lib_for($path);
+
+ # Handle the '--self-contained' option
+ my $flag = shift @args;
+ no warnings 'uninitialized'; # the flag is optional
+ if ($flag eq '--self-contained') {
+ # The only directories that remain are those that we just defined and those where core modules are stored.
+ @INC = ($Config::Config{privlibexp}, $Config::Config{archlibexp}, split ':', $ENV{PERL5LIB});
+ }
+ elsif (defined $flag) {
+ die "unrecognized import argument: $flag";
+ }
+
}
sub pipeline;
@@ -306,6 +321,13 @@
From the shell -
+ # Install LWP and it's missing dependencies to the 'my_lwp' directory
+ perl -MCPAN -Mlocal::lib=my_lwp -e 'install LWP'
+
+ # Install LWP and *all non-core* dependencies to the 'my_lwp' directory
+ perl -MCPAN -Mlocal::lib=--self-contained,my_lwp -e 'install LWP'
+
+ # Just print out useful shell commands
$ perl -Mlocal::lib
export MODULEBUILDRC=/home/username/perl/.modulebuildrc
export PERL_MM_OPT='INSTALL_BASE=/home/username/perl'
@@ -403,6 +425,8 @@
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>.
+
=head1 LICENSE
This library is free software under the same license as perl itself