Skip to content

Instantly share code, notes, and snippets.

Created August 14, 2014 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/955c9f9d73765e23c0d4 to your computer and use it in GitHub Desktop.
Save anonymous/955c9f9d73765e23c0d4 to your computer and use it in GitHub Desktop.
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