From 813512b43e411bb8657ecc3f9715943afff07b37 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 4 Oct 2012 17:39:32 -0500 Subject: refactor this so that helpers are just normal functions --- lib/Text/Handlebars.pm | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'lib/Text/Handlebars.pm') diff --git a/lib/Text/Handlebars.pm b/lib/Text/Handlebars.pm index 471d2f0..11de467 100644 --- a/lib/Text/Handlebars.pm +++ b/lib/Text/Handlebars.pm @@ -64,7 +64,6 @@ sub options { my $options = $class->SUPER::options(@_); $options->{compiler} = 'Text::Handlebars::Compiler'; - $options->{helpers} = {}; return $options; } @@ -88,19 +87,16 @@ sub _register_builtin_methods { return 1 if try { $weakself->find_file($filename); 1 }; return 0; }; + $funcs->{'(run_block_helper)'} = sub { + my ($code, $raw_text, $vars, @args) = @_; - for my $helper (keys %{ $self->{helpers} }) { - my $code = $self->{helpers}{$helper}; - $funcs->{$helper} = sub { - my ($raw_text, $vars, @args) = @_; - my $recurse = sub { - my ($new_vars) = @_; - return $weakself->render_string($raw_text, $new_vars); - }; - - return $code->($vars, @args, { fn => $recurse }); - } - } + my $recurse = sub { + my ($new_vars) = @_; + return $weakself->render_string($raw_text, $new_vars); + }; + + return $code->($vars, @args, { fn => $recurse }); + }; } 1; -- cgit v1.2.3-54-g00ecf