-
-
Save anonymous/955c9f9d73765e23c0d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojolicious/Controller.pm b/lib/Mojolicious/Controller.pm | |
index 198e99d..30430b2 100644 | |
--- a/lib/Mojolicious/Controller.pm | |
+++ b/lib/Mojolicious/Controller.pm | |
@@ -93,6 +93,10 @@ sub flash { | |
return $self; | |
} | |
+sub helpers { | |
+ ($_[0]->{helpers} ||= $_[0]->app->renderer->get_helper(''))->($_[0]); | |
+} | |
+ | |
sub on { | |
my ($self, $name, $cb) = @_; | |
my $tx = $self->tx; | |
diff --git a/lib/Mojolicious/Renderer.pm b/lib/Mojolicious/Renderer.pm | |
index 6014a68..45b34da 100644 | |
--- a/lib/Mojolicious/Renderer.pm | |
+++ b/lib/Mojolicious/Renderer.pm | |
@@ -76,8 +76,9 @@ sub get_helper { | |
my $found; | |
my $class = 'Mojolicious::Renderer::Helpers::' . md5_sum "$name:$self"; | |
+ my $re = $name eq '' ? qr/^(([^.]+))/ : qr/^(\Q$name\E\.([^.]+))/; | |
for my $key (keys %{$self->helpers}) { | |
- $key =~ /^(\Q$name\E\.([^.]+))/ ? ($found, my $method) = (1, $2) : next; | |
+ $key =~ $re ? ($found, my $method) = (1, $2) : next; | |
my $sub = $self->get_helper($1); | |
monkey_patch $class, $method => sub { ${shift()}->$sub(@_) }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment