Skip to content

Commit

Permalink
changed prepend semantics a little and improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 12, 2012
1 parent 9caf5a8 commit 823efd7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/Mojo/Template.pm
Expand Up @@ -23,7 +23,6 @@ has tree => sub { [] };

# Helpers
my $HELPERS = <<'EOF';
use Mojo::Util;
no warnings 'redefine';
sub _escape {
return $_[0] if ref $_[0] eq 'Mojo::ByteStream';
Expand Down
7 changes: 4 additions & 3 deletions lib/Mojolicious/Plugin/EPRenderer.pm
Expand Up @@ -3,6 +3,7 @@ use Mojo::Base 'Mojolicious::Plugin';

use Mojo::Template;
use Mojo::Util qw(encode md5_sum);
use Scalar::Util ();

# "What do you want?
# I'm here to kick your ass!
Expand Down Expand Up @@ -30,8 +31,8 @@ sub register {
my $mt = Mojo::Template->new($template);

# Be a bit more relaxed for helpers
my $prepend = q[my $self = shift; use Scalar::Util 'weaken';]
. q[weaken $self; no strict 'refs'; no warnings 'redefine';];
my $prepend = q[my $self = shift; Scalar::Util::weaken $self;]
. q[no strict 'refs'; no warnings 'redefine';];

# Helpers
$prepend .= 'my $_H = $self->app->renderer->helpers;';
Expand All @@ -47,7 +48,7 @@ sub register {
for grep {/^\w+$/} keys %{$c->stash};

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

# Render with "epl" handler
Expand Down
6 changes: 3 additions & 3 deletions t/mojolicious/twinkle_lite_app.t
Expand Up @@ -26,7 +26,7 @@ my $twinkle = {
expression_mark => '*',
line_start => '.',
namespace => 'TwinkleSandBoxTest',
prepend => 'no warnings "redefine"; sub bar { "bar!" }',
prepend => 'my $prepended = $self->config("foo");',
tag_end => '**',
tag_start => '**',
trim_mark => '*'
Expand Down Expand Up @@ -72,7 +72,7 @@ my $t = Test::Mojo->new;

# GET /
$t->get_ok('/')->status_is(200)
->content_like(qr/testHello <sebastian>!bar! TwinkleSandBoxTest123/);
->content_like(qr/testHello <sebastian>!bar TwinkleSandBoxTest123/);

# GET /advanced
$t->get_ok('/advanced')->status_is(200)
Expand Down Expand Up @@ -103,7 +103,7 @@ __DATA__
@@ index.foo.twinkle
. layout 'twinkle';
Hello *** $name **!\
*** bar ** *** __PACKAGE__ **\
*** $prepended ** *** __PACKAGE__ **\
@@ layouts/twinkle.foo.ep
test<%= content %>123\
Expand Down

0 comments on commit 823efd7

Please sign in to comment.