Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 12, 2014
1 parent eceba70 commit dee284f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

5.28 2014-08-12
5.28 2014-08-13
- Improved performance of nested helpers and helpers in templates
significantly.
- Improved Mojo::JSON to generate smaller JSON by not escaping the "/"
Expand Down
16 changes: 8 additions & 8 deletions lib/Mojolicious/Plugin/EPRenderer.pm
Expand Up @@ -11,8 +11,8 @@ sub register {

# Auto escape by default to prevent XSS attacks
my $template = {auto_escape => 1, %{$conf->{template} || {}}};
$self->{namespace} = $template->{namespace}
//= 'Mojo::Template::Sandbox::' . md5_sum("$self");
my $ns = $self->{namespace} = $template->{namespace}
//= 'Mojo::Template::Sandbox::' . md5_sum "$self";
# Add "ep" handler and make it the default
$app->renderer->default_handler('ep')->add_handler(
Expand All @@ -38,15 +38,15 @@ sub register {

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

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

# Make current controller available
no strict 'refs';
no warnings 'redefine';
local *{"@{[$mt->namespace]}::_C"} = sub {$c};
local *{"${ns}::_C"} = sub {$c};

# Render with "epl" handler
return $renderer->handlers->{epl}->($renderer, $c, $output, $options);
Expand All @@ -55,10 +55,10 @@ sub register {
}

sub _helpers {
my ($ns, $helpers) = @_;
for my $name (grep {/^\w+$/} keys %$helpers) {
my $sub = $helpers->{$name};
monkey_patch $ns, $name, sub { $ns->_C->$sub(@_) };
my ($class, $helpers) = @_;
for my $method (grep {/^\w+$/} keys %$helpers) {
my $sub = $helpers->{$method};
monkey_patch $class, $method, sub { $class->_C->$sub(@_) };
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Renderer.pm
Expand Up @@ -75,7 +75,7 @@ sub get_helper {
if (my $h = $self->helpers->{$name} || $self->{proxy}{$name}) { return $h }

my $found;
my $class = 'Mojolicious::Renderer::Helpers::' . md5_sum("$name:$self");
my $class = 'Mojolicious::Renderer::Helpers::' . md5_sum "$name:$self";
for my $key (keys %{$self->helpers}) {
$key =~ /^(\Q$name\E\.([^.]+))/ ? ($found, my $method) = (1, $2) : next;
my $sub = $self->get_helper($1);
Expand Down

0 comments on commit dee284f

Please sign in to comment.