fix fatpacking for 5.6
[p5sagit/App-FatPacker.git] / lib / App / FatPacker.pm
index 1aaba1c..8c77d20 100644 (file)
@@ -14,7 +14,7 @@ use File::Copy qw(copy);
 use File::Path qw(mkpath rmtree);
 use B qw(perlstring);
 
-our $VERSION = '0.010000'; # 0.10.0
+our $VERSION = '0.010004'; # 0.10.4
 
 $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}||[]};
 
@@ -142,8 +143,11 @@ sub script_command_packlists_for {
 sub packlists_containing {
   my ($self, $targets) = @_;
   my @targets = @$targets;
-  foreach my $t (@targets) {
-    require $t;
+  {
+    local @INC = ('lib', @INC);
+    foreach my $t (@targets) {
+      require $t;
+    }
   }
   my @search = grep -d $_, map catdir($_, 'auto'), @INC;
   my %pack_rev;
@@ -274,15 +278,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;
+          });
+        }
       };
     }