Skip to content

Commit

Permalink
fixed small line directive bug in Mojo::Template
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 13, 2013
1 parent 92d1cf7 commit 9c53f86
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -53,6 +53,7 @@
- Fixed layout bugs in Mojolicious::Renderer.
- Fixed support for HEAD request method in Mojo::Server::CGI and
Mojo::Server::PSGI.
- Fixed small line directive bug in Mojo::Template.
- Fixed small limit bug in Mojo::Message.

3.97 2013-04-25
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojo/Template.pm
Expand Up @@ -99,7 +99,9 @@ sub compile {

# Compile with line directive
return undef unless my $code = $self->code;
my $compiled = eval qq{#line 1 "@{[$self->name]}"\n$code};
my $name = $self->name;
$name =~ s/"//g;
my $compiled = eval qq{#line 1 "$name"\n$code};
$self->compiled($compiled) and return undef unless $@;

# Use local stacktrace for compile exceptions
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojolicious/Plugin/EPLRenderer.pm
Expand Up @@ -43,13 +43,14 @@ sub _epl {
# Try template
if (-r $path) {
$log->debug(qq{Rendering template "$t".});
$$output = $mt->name("template $t")->render_file($path, $c);
$$output = $mt->name(qq{template "$t"})->render_file($path, $c);
}

# Try DATA section
elsif (my $d = $renderer->get_data_template($options)) {
$log->debug(qq{Rendering template "$t" from DATA section.});
$$output = $mt->name("template $t from DATA section")->render($d, $c);
$$output
= $mt->name(qq{template "$t" from DATA section})->render($d, $c);
}

# No template
Expand Down
7 changes: 4 additions & 3 deletions t/mojo/template.t
Expand Up @@ -1052,16 +1052,17 @@ like "$output", qr/exception\.mt line 2/, 'right result';

# Exception in file (different name)
$mt = Mojo::Template->new;
$output = $mt->name('foo.mt')->render_file($file);
$output = $mt->name('"foo.mt" from DATA section')->render_file($file);
isa_ok $output, 'Mojo::Exception', 'right exception';
like $output->message, qr/foo\.mt line 2/, 'message contains filename';
like $output->message, qr/foo\.mt from DATA section line 2/,
'message contains filename';
is $output->lines_before->[0][0], 1, 'right number';
is $output->lines_before->[0][1], 'test', 'right line';
is $output->line->[0], 2, 'right number';
is $output->line->[1], '% die;', 'right line';
is $output->lines_after->[0][0], 3, 'right number';
is $output->lines_after->[0][1], '123', 'right line';
like "$output", qr/foo\.mt line 2/, 'right result';
like "$output", qr/foo\.mt from DATA section line 2/, 'right result';

# Exception with UTF-8 context
$mt = Mojo::Template->new;
Expand Down

0 comments on commit 9c53f86

Please sign in to comment.