From: David Leadbeater Date: Tue, 18 Jan 2011 20:45:24 +0000 (+0000) Subject: Add --use option to use extra modules when tracing X-Git-Tag: v0.9.7~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3fdf85cab9fd27ad5e7d5141e197b9832d6b9394;p=p5sagit%2FApp-FatPacker.git Add --use option to use extra modules when tracing --- diff --git a/bin/fatpack b/bin/fatpack index 536073c..e56350d 100755 --- a/bin/fatpack +++ b/bin/fatpack @@ -10,7 +10,8 @@ fatpack - Command line frontend for App::FatPacker =head2 trace - $ fatpack trace [--to=trace-file|--to-stderr] myscript.pl + $ fatpack trace [--to=trace-file|--to-stderr] [--use=MODULE] + myscript.pl Compiles myscript.pl (as in "perl -c") and writes out a trace file containing every module require()d during the compilation. @@ -22,6 +23,9 @@ If you pass --to-stderr fatpack writes the trace to STDERR instead. You cannot pass both --to and --to-stderr. +If the --use option specifies a module (or modules, if used multiple +times) those modules will be additionally included in the trace output. + =head2 packlists-for $ fatpack packlists-for Module1 Module2 Module3 diff --git a/lib/App/FatPacker.pm b/lib/App/FatPacker.pm index 453f3bc..62a1612 100644 --- a/lib/App/FatPacker.pm +++ b/lib/App/FatPacker.pm @@ -65,23 +65,27 @@ sub script_command_trace { $args = call_parser $args => [ 'to=s' => \my $file, 'to-stderr' => \my $to_stderr, + 'use=s' => \my @additional_use ]; die "Can't use to and to-stderr on same call" if $file && $to_stderr; - (my $use_file = $file) ||= 'fatpacker.trace'; - if (!$to_stderr and -e $use_file) { - unlink $use_file or die "Couldn't remove old trace file: $!"; + $file ||= 'fatpacker.trace'; + if (!$to_stderr and -e $file) { + unlink $file or die "Couldn't remove old trace file: $!"; } my $arg = do { - if ($file) { - "=>>${file}" - } elsif ($to_stderr) { + if ($to_stderr) { "=>&STDERR" - } else { - "" + } elsif ($file) { + "=>>${file}" } }; + + if(@additional_use) { + $arg .= "," . join ",", @additional_use; + } + { local $ENV{PERL5OPT} = '-MApp::FatPacker::Trace'.$arg; system $^X, @$args; @@ -203,7 +207,7 @@ App::FatPacker - pack your dependencies onto your script file See the documentation for the L script itself for more information. -The programmatic API for this code is not yet fully decided, hence the 0.9.1 +The programmatic API for this code is not yet fully decided, hence the 0.9 release version. Expect that to be cleaned up for 1.0. =head1 SUPPORT diff --git a/lib/App/FatPacker/Trace.pm b/lib/App/FatPacker/Trace.pm index 1da5943..28cde3a 100644 --- a/lib/App/FatPacker/Trace.pm +++ b/lib/App/FatPacker/Trace.pm @@ -8,11 +8,17 @@ my $trace_file; my %initial_inc; sub import { - $trace_file = $_[1] || '>>fatpacker.trace'; + my(undef, $file, @extras) = @_; + + $trace_file = $file || '>>fatpacker.trace'; # For filtering out our own deps later. # (Not strictly required as these are core only and won't have packlists, but # looks neater.) %initial_inc = %INC; + + # Use any extra modules specified + eval "use $_" for @extras; + B::minus_c; }