use warnings FATAL => 'all';
use B ();
+my $trace_file;
+my %initial_inc;
+
sub import {
- my $open = $_[1] || '>>fatpacker.trace';
- open my $trace, $open
- or die "Couldn't open ${open} to trace to: $!";
- unshift @INC, sub {
- print $trace "$_[1]\n";
- };
+ $trace_file = $_[1] || '>>fatpacker.trace';
+ # For filtering out our own deps later.
+ # (Not strictly required as these are core only and won't have packlists, but
+ # looks neater.)
+ %initial_inc = %INC;
B::minus_c;
}
+CHECK {
+ return unless $trace_file; # not imported
+
+ open my $trace, $trace_file
+ or die "Couldn't open $trace_file to trace to: $!";
+
+ for my $inc(keys %INC) {
+ next if exists $initial_inc{$inc};
+ print $trace "$inc\n";
+ }
+}
+
1;
--- /dev/null
+#!perl
+use Test::More;
+
+test_trace("t/mod/a.pm" => ("t/mod/b.pm", "t/mod/c.pm"));
+test_trace("t/mod/b.pm" => ("t/mod/c.pm"));
+test_trace("t/mod/c.pm" => ());
+
+# Attempts to conditionally load a module that isn't present
+test_trace("t/mod/cond.pm" => ());
+
+done_testing;
+
+sub test_trace {
+ my($file, @loaded) = @_;
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+ system($^X, "-Mblib", "-MApp::FatPacker::Trace", $file);
+
+ open my $trace, "<", "fatpacker.trace";
+ while(<$trace>) {
+ chomp;
+ my $load = $_;
+ @loaded = grep { $load ne $_ } @loaded;
+ }
+
+ ok !@loaded, "All expected modules loaded for $file";
+ unlink "fatpacker.trace";
+}
+