Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed .ep template bug where the stash value "c" could no longer be u…
…sed (closes #671)
  • Loading branch information
kraih committed Sep 3, 2014
1 parent 4ca8e4a commit e9e2052
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@

5.37 2014-09-03
- Improved Mojo::Template performance slightly.
- Fixed .ep template bug where the stash value "c" could no longer be used.

5.36 2014-09-02
- Improved Mojo::Template performance.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Template.pm
Expand Up @@ -274,7 +274,7 @@ sub _wrap {
my $num = () = $code =~ /\n/g;
my $head = $self->_line(1);
$head .= "\npackage @{[$self->namespace]}; use Mojo::Base -strict;";
$code = "$head sub { my \$_M = ''; @{[$self->prepend]}; do { $code\n";
$code = "$head sub { my \$_M = ''; @{[$self->prepend]}; { $code\n";
$code .= $self->_line($num + 1) . "\n@{[$self->append]}; \$_M } };";

warn "-- Code for @{[$self->name]}\n@{[encode 'UTF-8', $code]}\n\n" if DEBUG;
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojolicious/Plugin/EPRenderer.pm
Expand Up @@ -34,10 +34,11 @@ sub register {
unless $self->{helpers};

# Stash values (every time)
my $prepend = 'my $self = my $c = shift; my $_S = $c->stash;';
my $prepend = 'my $self = my $c = shift; my $_S = $c->stash; {';
$prepend .= join '', map {" my \$$_ = \$_S->{'$_'};"} @keys;
$mt->prepend($prepend . $mt->prepend)->append('}' . $mt->append);

$cache->set($key => $mt->prepend($prepend . $mt->prepend));
$cache->set($key => $mt);
}

# Make current controller available
Expand Down
2 changes: 2 additions & 0 deletions t/mojolicious/app.t
Expand Up @@ -65,6 +65,8 @@ is $t->app->renderer->template_handler(
is $t->app->build_controller->req->url, '', 'no URL';
is $t->app->build_controller->render_to_string('does_not_exist'), undef,
'no result';
is $t->app->build_controller->render_to_string(inline => '%= $c', c => 'foo'),
"foo\n", 'right result';

# Missing methods and functions (AUTOLOAD)
eval { $t->app->missing };
Expand Down

0 comments on commit e9e2052

Please sign in to comment.