Subject: | Packing modules that attempt conditial loading |
Date: | Sun, 22 Aug 2010 22:51:35 +0100 |
To: | bugs-App-FatPacker [...] rt.cpan.org |
From: | David Leadbeater <dgl [...] dgl.cx> |
Hi,
I found an issue when trying to fatpack trace an app that uses Encode. It tries
to pack Encode::ConfigLocal which Encode tries to load within an eval block
(although anything that tries that sort of thing could fail).
Here's an attempt to fix it. Note using CHECK blocks means the test can't even
C<require App::FatPacker::Trace> anymore.
David
--- a/lib/App/FatPacker/Trace.pm
+++ b/lib/App/FatPacker/Trace.pm
@@ -4,14 +4,36 @@ use strict;
use warnings FATAL => 'all';
use B ();
+my %seen;
+my $trace_file = "fatpacker.trace";
+
sub import {
- my $open = $_[1] || '>>fatpacker.trace';
- open my $trace, $open
- or die "Couldn't open ${open} to trace to: $!";
+ $trace_file = $_[1] if defined $_[1];
+
unshift @INC, sub {
- print $trace "$_[1]\n";
+ $seen{$_[1]}++;
+ return; # false in case someone messed with %INC
+ };
+
+ my $remover;
+ push @INC, $remover = sub {
+ # Ensure this stays at the end
+ if($INC[-1] ne $remover) {
+ @INC = ((grep { !ref || $_ != $remover } @INC), $remover);
+ return;
+ }
+
+ delete $seen{$_[1]};
+ return;
};
+
B::minus_c;
}
+CHECK {
+ open my $trace, ">", $trace_file
+ or die "Couldn't open ${trace_file} to trace to: $!";
+ print $trace "$_\n" for keys %seen;
+}
+
1;
diff --git a/t/basic.t b/t/basic.t
index 6e97616..9da7609 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -3,6 +3,5 @@ use warnings FATAL => 'all';
use Test::More qw(no_plan);
require App::FatPacker;
-require App::FatPacker::Trace;
pass "Didn't blow up";