From 8dde6c5072fd4c989e6cdec3b827050754647e7f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 14 Oct 2012 14:46:44 -0500 Subject: is_code_ref can now be an opcode too --- lib/Text/Handlebars.pm | 4 ---- lib/Text/Handlebars/Compiler.pm | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/Text/Handlebars.pm b/lib/Text/Handlebars.pm index 6fed7a7..fbc0976 100644 --- a/lib/Text/Handlebars.pm +++ b/lib/Text/Handlebars.pm @@ -124,10 +124,6 @@ sub default_functions { return { %{ $class->SUPER::default_functions(@_) }, %{ $class->default_helpers }, - '(is_code)' => sub { - my ($val) = @_; - return ref($val) && ref($val) eq 'CODE'; - }, '(new_vars_for)' => sub { my ($vars, $value, $i) = @_; diff --git a/lib/Text/Handlebars/Compiler.pm b/lib/Text/Handlebars/Compiler.pm index 0282fff..d2d6865 100644 --- a/lib/Text/Handlebars/Compiler.pm +++ b/lib/Text/Handlebars/Compiler.pm @@ -164,7 +164,7 @@ sub _generate_block { my $var = $name->clone(arity => 'variable'); return $self->compile_ast( $self->make_ternary( - $self->call($node, '(is_code)', $var->clone), + $self->is_code_ref($var->clone), $self->call( $node, '(run_code)', @@ -210,7 +210,7 @@ sub is_unary { my ($id) = @_; my %unary = ( - map { $_ => 1 } qw(builtin_is_array_ref) + map { $_ => 1 } qw(builtin_is_array_ref is_code_ref) ); return $unary{$id}; @@ -278,7 +278,7 @@ sub check_lambda { my ($var) = @_; return $self->make_ternary( - $self->call($var, '(is_code)', $var->clone), + $self->is_code_ref($var->clone), $self->call($var, '(run_code)', $var->clone, $self->vars), $var, ); @@ -295,6 +295,17 @@ sub is_array_ref { ); } +sub is_code_ref { + my $self = shift; + my ($var) = @_; + + return $self->parser->symbol('(is_code_ref)')->clone( + id => 'is_code_ref', + arity => 'unary', + first => $var, + ); +} + sub make_array { my $self = shift; my (@contents) = @_; -- cgit v1.2.3