diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-10-03 15:05:25 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-10-03 15:08:29 -0500 |
commit | b6b1bd1936ea207c74ecf0993bd3b7c55c71ec57 (patch) | |
tree | 6c67d41ca8ceedb1daeecce1fec877a46108e7e1 /lib/Text/Handlebars.pm | |
parent | bbec479a424eda0bc48250c118aaad85ddb6ee00 (diff) | |
download | text-handlebars-b6b1bd1936ea207c74ecf0993bd3b7c55c71ec57.tar.gz text-handlebars-b6b1bd1936ea207c74ecf0993bd3b7c55c71ec57.zip |
make basic lambdas work (not block lambdas yet)
Diffstat (limited to 'lib/Text/Handlebars.pm')
-rw-r--r-- | lib/Text/Handlebars.pm | 15 |
1 files changed, 15 insertions, 0 deletions
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; |