Skip to content

Commit

Permalink
fix empty template handling in Mojo::Template
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 9, 2015
1 parent ff5cba2 commit 0538c9b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@

6.02 2015-03-09
- Improved portability of Morbo.
- Fixed empty template handling in Mojo::Template.

6.01 2015-03-03
- Added content_with helper to Mojolicious::Plugin::DefaultHelpers.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Template.pm
Expand Up @@ -87,7 +87,7 @@ sub compile {
my $self = shift;

# Compile with line directive
return undef unless my $code = $self->code;
return undef unless defined(my $code = $self->code);
my $compiled = eval $self->_wrap($code);
$self->compiled($compiled) and return undef unless $@;

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/EPRenderer.pm
Expand Up @@ -36,7 +36,7 @@ sub register {
# Stash values (every time)
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);
$mt->prepend($prepend . $mt->prepend)->append(';}' . $mt->append);

$cache->set($key => $mt);
}
Expand Down
8 changes: 6 additions & 2 deletions t/mojo/template.t
Expand Up @@ -24,10 +24,14 @@ use Mojo::Template;
# Capture helper
my $capture = 'no warnings "redefine"; sub capture { shift->(@_) }';

# Empty template
my $mt = Mojo::Template->new;
my $output = $mt->render('');
is $output, '', 'empty string';

# Consistent scalar context
my $mt = Mojo::Template->new;
$mt->prepend('my @foo = (3, 4);')->parse('<%= @foo %>:<%== @foo %>');
my $output = $mt->build->compile || $mt->interpret;
$output = $mt->build->compile || $mt->interpret;
is $output, "2:2\n", 'same context';

# Parentheses
Expand Down

1 comment on commit 0538c9b

@kberov
Copy link
Contributor

@kberov kberov commented on 0538c9b Mar 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks

Please sign in to comment.