From b6b1bd1936ea207c74ecf0993bd3b7c55c71ec57 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 3 Oct 2012 15:05:25 -0500 Subject: make basic lambdas work (not block lambdas yet) --- lib/Text/Handlebars.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/Text/Handlebars.pm') diff --git a/lib/Text/Handlebars.pm b/lib/Text/Handlebars.pm index 30a769c..fa9e32c 100644 --- a/lib/Text/Handlebars.pm +++ b/lib/Text/Handlebars.pm @@ -22,6 +22,10 @@ sub default_functions { my ($length) = @_; return [(undef) x $length]; }, + '(is_code)' => sub { + my ($val) = @_; + return ref($val) && ref($val) eq 'CODE'; + }, '(new_vars_for)' => sub { my ($vars, $value, $i) = @_; $i = 0 unless defined $i; # XXX @@ -62,4 +66,15 @@ sub options { return $options; } +sub _register_builtin_methods { + my $self = shift; + my ($funcs) = @_; + + weaken(my $weakself = $self); + $funcs->{'(run_code)'} = sub { + my ($code, $vars) = @_; + return $self->render_string($code->(), $vars); + }; +} + 1; -- cgit v1.2.3-54-g00ecf