=head1 COMMANDS
+=head2 pack
+
+ $ fatpack pack myscript.pl > myscript.packed.pl
+
+A shortcut to do all the work of tracing, collecting packlists,
+extracting modules in fatlib, then concatenating into a packed script
+- in one shot. If you need more detailed controls for additional
+modules, use the following commands separately (see L</RECIPES>).
+
=head2 trace
$ fatpack trace [--to=trace-file|--to-stderr] [--use=MODULE]
map +(chomp,$_)[1], do { local @ARGV = ($_[0]); <> };
}
+sub maybe_shebang {
+ my ($file) = @_;
+ open my $in, "<", $file or die "$file: $!";
+ my $head = <$in>;
+ if ($head =~ m/^#\!/) {
+ ($head, do { local $/; <$in> });
+ } else {
+ ('', do { local $/; $head . <$in> });
+ }
+}
+
sub stripspace {
my ($text) = @_;
$text =~ /^(\s+)/ && $text =~ s/^$1//mg;
print "Try `perldoc fatpack` for how to use me\n";
}
+sub script_command_pack {
+ my ($self, $args) = @_;
+
+ my @modules = split /\r?\n/, $self->trace(args => $args);
+ my @packlists = $self->packlists_containing(\@modules);
+
+ my $base = catdir(cwd, 'fatlib');
+ $self->packlists_to_tree($base, \@packlists);
+
+ my $file = shift @$args;
+ my($head, $body) = maybe_shebang($file);
+ print $head, $self->fatpack_file($file), $body;
+}
+
sub script_command_trace {
my ($self, $args) = @_;
sub trace {
my ($self, %opts) = @_;
- my $capture;
-
- my $output = $opts{output} || do {
- $capture++; '>&STDOUT'
- };
-
+ my $output = $opts{output};
my $trace_opts = join ',', $output||'>&STDOUT', @{$opts{use}||[]};
local $ENV{PERL5OPT} = '-MApp::FatPacker::Trace='.$trace_opts;
sub script_command_file {
my ($self, $args) = @_;
my $file = shift @$args;
+ print $self->fatpack_file($file);
+}
+
+sub fatpack_file {
+ my ($self, $file) = @_;
my $cwd = cwd;
my @dirs = grep -d, map rel2abs($_, $cwd), ('lib','fatlib');
my %files;
'$fatpacked{'.perlstring($_).qq!} = <<'${name}';\n!
.qq!${data}${name}\n!;
} sort keys %files;
- print join "\n", $start, @segments, $end;
+ return join "\n", $start, @segments, $end;
}
=encoding UTF-8
=head1 SYNOPSIS
+ $ fatpack pack myscript.pl >myscript.packed.pl
+
+Or, with more step-by-step control:
+
$ fatpack trace myscript.pl
$ fatpack packlists-for `cat fatpacker.trace` >packlists
$ fatpack tree `cat packlists`