Skip Menu |

This queue is for tickets about the Template-Toolkit CPAN distribution.

Report information
The Basics
Id: 46269
Status: resolved
Worked: 10 min
Priority: 0/
Queue: Template-Toolkit

People
Owner: Nobody in particular
Requestors: norbi [...] nix.hu
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 2.20
  • 2.20_3
Fixed in: (no value)



Subject: #line directives in the compiled templates do not work
Perl demands that there must be no whitespace before the #line directives (otherwise they are not used to override Perl's idea about the current filename and line number) (see http://perldoc.perl.org/perlsyn.html#Plain-Old-Comments-(Not!) ). The attached patch fixes this (one regex change + test cases).
Subject: Template_linenumber_directive_fix.diff
Index: t/compile5.t =================================================================== --- t/compile5.t (revision 1217) +++ t/compile5.t (working copy) @@ -34,6 +34,9 @@ COMPILE_DIR => "$cdir/", # note trailing slash - should be handled OK COMPILE_EXT => '.ttc', ABSOLUTE => 1, + CONSTANTS => { + dir => $dir, + }, }; # check compiled template files exist @@ -108,3 +111,9 @@ [% INCLUDE "$root/src/blam" %] -- expect -- This is the wam-bam file +-- test -- +[%- # second pass, reads the compiled code from cache -%] +[% INCLUDE divisionbyzero -%] +-- expect -- +-- process -- +undef error - Illegal division by zero at [% constants.dir %]/src/divisionbyzero line 1, <DATA> chunk 1. Index: t/compile2.t =================================================================== --- t/compile2.t (revision 1217) +++ t/compile2.t (working copy) @@ -90,3 +90,8 @@ - 3 - 2 - 1 +-- test -- +[%- # second pass, reads the compiled code from cache -%] +[% INCLUDE divisionbyzero -%] +-- expect -- +undef error - Illegal division by zero at t/test/src/divisionbyzero line 1, <DATA> chunk 1. Index: t/compile4.t =================================================================== --- t/compile4.t (revision 1217) +++ t/compile4.t (working copy) @@ -38,6 +38,9 @@ COMPILE_DIR => $cdir, COMPILE_EXT => '.ttc', ABSOLUTE => 1, + CONSTANTS => { + dir => $dir, + }, }; # delete any existing cache files @@ -80,3 +83,9 @@ [% INCLUDE "$root/src/blam" %] -- expect -- This is the blam file +-- test -- +[%- # first pass, writes the compiled code to cache -%] +[% INCLUDE divisionbyzero -%] +-- expect -- +-- process -- +undef error - Illegal division by zero at [% constants.dir %]/src/divisionbyzero line 1. Index: t/compile1.t =================================================================== --- t/compile1.t (revision 1217) +++ t/compile1.t (working copy) @@ -35,7 +35,7 @@ }; # delete any existing files -foreach my $f ( "$dir/foo.ttc", "$dir/complex.ttc" ) { +foreach my $f ( "$dir/foo.ttc", "$dir/complex.ttc", "$dir/divisionbyzero.ttc" ) { ok( unlink($f) ) if -f $f; } @@ -76,4 +76,8 @@ This is the baz file, a: - +-- test -- +[%- # first pass, writes the compiled code to cache -%] +[% INCLUDE divisionbyzero -%] +-- expect -- +undef error - Illegal division by zero at t/test/src/divisionbyzero line 1. Index: lib/Template/Document.pm =================================================================== --- lib/Template/Document.pm (revision 1217) +++ lib/Template/Document.pm (working copy) @@ -231,7 +231,7 @@ my ($class, $content) = @_; my ($block, $defblocks, $metadata) = @$content{ qw( BLOCK DEFBLOCKS METADATA ) }; - $block =~ s/\n/\n /g; + $block =~ s/\n(?!#line)/\n /g; $block =~ s/\s+$//; $defblocks = join('', map {
Patch applied, thanks. The divisionbyzero template was missing from the patch, but I was able to guess what it did from the name and reconstitute it :-) Cheers A