Skip to content

Commit

Permalink
match keys only once
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 12, 2014
1 parent ea20e1d commit c1eeadc
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -71,15 +71,16 @@ sub get_helper {
my ($self, $name) = @_;

if (my $h = $self->helpers->{$name} || $self->{proxy}{$name}) { return $h }
return undef unless grep {/^\Q$name\E\./} my @keys = keys %{$self->helpers};

my $class = 'Mojolicious::Renderer::Helpers::' . md5_sum("$name:$self");
for my $key (@keys) {
next unless $key =~ /^(\Q$name\E\.([^.]+))/;
my $export = $2;
my $sub = $self->get_helper($1);
monkey_patch $class, $export => sub { ${shift()}->$sub(@_) };

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

return undef unless $found;
return $self->{proxy}{$name} = sub { bless \shift, $class };
}

Expand Down

0 comments on commit c1eeadc

Please sign in to comment.