From: Olivier Mengué Date: Thu, 27 Jun 2013 20:10:14 +0000 (+0200) Subject: Generate absolute #line for the packed modules X-Git-Tag: v0.010000~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FApp-FatPacker.git;a=commitdiff_plain;h=56a51caacfbeef8aaa808be284f4bd0ef4095993 Generate absolute #line for the packed modules Generate a #line at the beginning of each packed module so we can easily track errors: the error file/line will now be reported absolute from the packed script. --- diff --git a/lib/App/FatPacker.pm b/lib/App/FatPacker.pm index ec006a4..16b8cdd 100644 --- a/lib/App/FatPacker.pm +++ b/lib/App/FatPacker.pm @@ -295,7 +295,7 @@ sub fatpack_code { (my $stub = $_) =~ s/\.pm$//; my $name = uc join '_', split '/', $stub; my $data = $files->{$_}; $data =~ s/^/ /mg; $data =~ s/(? Mithaldu - Christian Walde (cpan:MITHALDU) +dolmen - Olivier Mengué (cpan:DOLMEN) + Many more people are probably owed thanks for ideas. Yet another doc nit to fix. diff --git a/t/line.t b/t/line.t new file mode 100644 index 0000000..ac1f7b4 --- /dev/null +++ b/t/line.t @@ -0,0 +1,23 @@ +#!perl +use strict; +use warnings FATAL => 'all'; +use Test::More tests => 3; +use File::Temp qw/tempdir/; +use File::Spec; + +BEGIN { use_ok "App::FatPacker", "" } + +chdir 't/line'; + +my $fp = App::FatPacker->new; +my $temp_fh = File::Temp->new; +select $temp_fh; +$fp->script_command_file([ 'line-test.pl' ]); +select STDOUT; +close $temp_fh; + +# make sure we don't pick up things from our created dir +chdir File::Spec->tmpdir; + +# Packed, now try using it. This should run the tests inside t/line/a.pm +do $temp_fh; diff --git a/t/line/lib/line/a.pm b/t/line/lib/line/a.pm new file mode 100644 index 0000000..db45e6b --- /dev/null +++ b/t/line/lib/line/a.pm @@ -0,0 +1,9 @@ + +# This file will be included in the packed file generated by t/line.t + +# Check that the name is the one of the packed file +is __FILE__, $main_file, '__FILE__'; +# Check that the line is the one where the module code starts in the packed file +is __LINE__, 14, '__LINE__'; + +1; diff --git a/t/line/line-test.pl b/t/line/line-test.pl new file mode 100644 index 0000000..f1cc2da --- /dev/null +++ b/t/line/line-test.pl @@ -0,0 +1,14 @@ + +# To run this test manually: +# perl -I../../lib ../../bin/fatpack file line-test.pl | perl + +package OurTest; + +use Test::More; + +our $main_file = __FILE__; +note "File: $main_file"; + +# Run the tests in the packed file +do 'line/a.pm'; +