diff --git a/lib/HTML/Mason/Lexer.pm b/lib/HTML/Mason/Lexer.pm index 0d88b711..1e3ea14d 100644 --- a/lib/HTML/Mason/Lexer.pm +++ b/lib/HTML/Mason/Lexer.pm @@ -306,7 +306,9 @@ sub key_val_block ); } - $self->{current}{lines}++; + $self->{current}{lines}++ if $self->{current}{comp_source} =~ /\n\G/; + # OR + # $self->{current}{lines}++ if $& =~ /\n\Z/; } $p->{allow_text} = 0; diff --git a/t/bug-source_line_num.t b/t/bug-source_line_num.t new file mode 100644 index 00000000..9b667b08 --- /dev/null +++ b/t/bug-source_line_num.t @@ -0,0 +1,55 @@ +use strict; +use Test::More; +use HTML::Mason; + +my $die_at_line4 = <<''; +<%attr> + key1 => "val1" + +% die; + +my $die_at_line2 = <<''; +<%attr> key1 => "val1" +% die; + +{ + my $interp = HTML::Mason::Interp->new; + + my $comp = $interp->make_component( comp_source => $die_at_line4 ); + eval { $interp->exec($comp) }; + like $@, qr/Died at line 4\./; + + my $source = HTML::Mason::ComponentSource->new( + friendly_name => '', + comp_path => '', + source_callback => sub { $die_at_line4 }, + ); + + my $object_code = $source->object_code( + compiler => $interp->compiler, + ); + + like $$object_code, qr/^#line 4 ""/m; +} + +{ + my $interp = HTML::Mason::Interp->new; + + my $comp = $interp->make_component( comp_source => $die_at_line2 ); + eval { $interp->exec($comp) }; + like $@, qr/Died at line 2\./; + + my $source = HTML::Mason::ComponentSource->new( + friendly_name => '', + comp_path => '', + source_callback => sub { $die_at_line2 }, + ); + + my $object_code = $source->object_code( + compiler => $interp->compiler, + ); + + like $$object_code, qr/^#line 2 ""/m; +} + +done_testing;