Release commit for 0.010008
[p5sagit/App-FatPacker.git] / lib / App / FatPacker.pm
index 8b623ac..e376e6f 100644 (file)
@@ -14,7 +14,7 @@ use File::Copy qw(copy);
 use File::Path qw(mkpath rmtree);
 use B qw(perlstring);
 
-our $VERSION = '0.009018'; # 0.009.017
+our $VERSION = '0.010008'; # v0.10.8
 
 $VERSION = eval $VERSION;
 
@@ -117,7 +117,8 @@ sub trace {
   my $output = $opts{output};
   my $trace_opts = join ',', $output||'>&STDOUT', @{$opts{use}||[]};
 
-  local $ENV{PERL5OPT} = '-MApp::FatPacker::Trace='.$trace_opts;
+  local $ENV{PERL5OPT} = join ' ',
+    ($ENV{PERL5OPT}||()), '-MApp::FatPacker::Trace='.$trace_opts;
 
   my @args = @{$opts{args}||[]};
 
@@ -141,9 +142,17 @@ sub script_command_packlists_for {
 
 sub packlists_containing {
   my ($self, $targets) = @_;
-  my @targets = @$targets;
-  foreach my $t (@targets) {
-    require $t;
+  my @targets;
+  {
+    local @INC = ('lib', @INC);
+    foreach my $t (@$targets) {
+      unless (eval { require $t; 1}) {
+        warn "Failed to load ${t}: $@\n"
+            ."Make sure you're not missing a packlist as a result\n";
+        next;
+      }
+      push @targets, $t;
+    }
   }
   my @search = grep -d $_, map catdir($_, 'auto'), @INC;
   my %pack_rev;
@@ -174,8 +183,11 @@ sub packlists_to_tree {
     my $pack_base;
     PART: foreach my $p (0 .. $#dir_parts) {
       if ($dir_parts[$p] eq 'auto') {
-        # $p-2 since it's <wanted path>/$Config{archname}/auto
-        $pack_base = catpath $vol, catdir @dir_parts[0..$p-2];
+        # $p-2 normally since it's <wanted path>/$Config{archname}/auto but
+        # if the last bit is a number it's $Config{archname}/$version/auto
+        # so use $p-3 in that case
+        my $version_lib = 0+!!($dir_parts[$p-1] =~ /^[0-9.]+$/);
+        $pack_base = catpath $vol, catdir @dir_parts[0..$p-(2+$version_lib)];
         last PART;
       }
     }
@@ -274,15 +286,17 @@ sub fatpack_end {
 
     if ($] < 5.008) {
       *{"${class}::INC"} = sub {
-         if (my $fat = $_[0]{$_[1]}) {
-           return sub {
-             return 0 unless length $fat;
-             $fat =~ s/^([^\n]*\n?)//;
-             $_ = $1;
-             return 1;
-           };
-         }
-         return;
+        if (my $fat = $_[0]{$_[1]}) {
+          my $pos = 0;
+          my $last = length $fat;
+          return (sub {
+            return 0 if $pos == $last;
+            my $next = (1 + index $fat, "\n", $pos) || $last;
+            $_ .= substr $fat, $pos, $next - $pos;
+            $pos = $next;
+            return 1;
+          });
+        }
       };
     }
 
@@ -332,19 +346,38 @@ Or, with more step-by-step control:
   $ fatpack tree `cat packlists`
   $ fatpack file myscript.pl >myscript.packed.pl
 
-See the documentation for the L<fatpack> script itself for more information.
+Each command is designed to be simple and self-contained so that you can modify
+the input/output of each step as needed. See the documentation for the
+L<fatpack> script itself for more information.
 
-The programmatic API for this code is not yet fully decided, hence the 0.9
+The programmatic API for this code is not yet fully decided, hence the 0.x
 release version. Expect that to be cleaned up for 1.0.
 
+=head1 CAVEATS
+
+As dependency module code is copied into the resulting file as text, only
+pure-perl dependencies can be packed, not compiled XS code.
+
+The currently-installed dependencies to pack are found via F<.packlist> files,
+which are generally only included in non-core distributions that were installed
+by a CPAN installer. This is a feature; see L<fatpack/packlists-for> for
+details. (a notable exception to this is FreeBSD, which, since its packaging
+system is designed to work equivalently to a source install, does preserve
+the packlist files)
+
 =head1 SEE ALSO
 
 L<article for Perl Advent 2012|http://www.perladvent.org/2012/2012-12-14.html>
 
+L<pp> - PAR Packager, a much more complex architecture-dependent packer that
+can pack compiled code and even a Perl interpreter
+
 =head1 SUPPORT
 
-Your current best avenue is to come annoy annoy mst on #toolchain on
-irc.perl.org. There should be a non-IRC means of support by 1.0.
+Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=App-FatPacker>
+(or L<bug-App-FatPacker@rt.cpan.org|mailto:bug-App-FatPacker@rt.cpan.org>).
+
+You can normally also obtain assistance on irc, in #toolchain on irc.perl.org.
 
 =head1 AUTHOR
 
@@ -372,6 +405,10 @@ dolmen - Olivier MenguĂ© (cpan:DOLMEN) <dolmen@cpan.org>
 
 djerius - Diab Jerius (cpan:DJERIUS) <djerius@cpan.org>
 
+haarg - Graham Knop (cpan:HAARG) <haarg@haarg.org>
+
+grinnz - Dan Book (cpan:DBOOK) <dbook@cpan.org>
+
 Many more people are probably owed thanks for ideas. Yet
 another doc nit to fix.