From: Tatsuhiko Miyagawa Date: Wed, 3 Apr 2013 22:21:01 +0000 (-0700) Subject: Added fatpack pack file, which does the equivalent of RECIPE in the doc in one shot X-Git-Tag: v0.009015~2^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cb3e6884a7ccb6f2ec6bed447cc669a4d54a941d;p=p5sagit%2FApp-FatPacker.git Added fatpack pack file, which does the equivalent of RECIPE in the doc in one shot --- diff --git a/lib/App/FatPacker.pm b/lib/App/FatPacker.pm index a7871c8..71fd66d 100644 --- a/lib/App/FatPacker.pm +++ b/lib/App/FatPacker.pm @@ -32,6 +32,17 @@ sub lines_of { 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; @@ -67,6 +78,20 @@ sub script_command_help { 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) = @_;