summaryrefslogtreecommitdiffstats
path: root/lib/Text/Handlebars.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-05 18:30:32 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-05 18:30:32 -0500
commit6ff12b877afbda62ad2cb6d748487e7674e5c396 (patch)
tree74fa460cfbb35ff23603a8ee4e3a84c7d2dda52b /lib/Text/Handlebars.pm
parentf805baad91b66f47885160afaed141a4e4c5fa67 (diff)
downloadtext-handlebars-6ff12b877afbda62ad2cb6d748487e7674e5c396.tar.gz
text-handlebars-6ff12b877afbda62ad2cb6d748487e7674e5c396.zip
change back to defining helpers and functions separately
helpers are different from functions because they implicitly receive the current context as the first argument, so they need to be declared differently. they work identically to functions in all other respects.
Diffstat (limited to 'lib/Text/Handlebars.pm')
-rw-r--r--lib/Text/Handlebars.pm18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/Text/Handlebars.pm b/lib/Text/Handlebars.pm
index 25075b1..a040504 100644
--- a/lib/Text/Handlebars.pm
+++ b/lib/Text/Handlebars.pm
@@ -90,6 +90,7 @@ sub options {
my $options = $class->SUPER::options(@_);
$options->{compiler} = 'Text::Handlebars::Compiler';
+ $options->{helpers} = {};
return $options;
}
@@ -128,6 +129,23 @@ sub _register_builtin_methods {
return $code->($vars, @args, $options);
};
+
+ for my $helper (keys %{ $self->{helpers} }) {
+ $funcs->{$helper} = $self->{helpers}{$helper};
+ }
+}
+
+sub _compiler {
+ my $self = shift;
+
+ if (!ref($self->{compiler})) {
+ my $compiler = $self->SUPER::_compiler(@_);
+ $compiler->define_helper(keys %{ $self->{helpers} });
+ return $compiler;
+ }
+ else {
+ return $self->SUPER::_compiler(@_);
+ }
}
sub render_string {