summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-14 14:46:44 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-15 02:09:08 -0500
commit3925504e1390c02950110e92a8581e9670aac054 (patch)
tree2976814b43c82facd7b9891f0e87d088eee8c913
parent4e3bf34027567183336f95153ae94019c468c701 (diff)
downloadtext-handlebars-3925504e1390c02950110e92a8581e9670aac054.tar.gz
text-handlebars-3925504e1390c02950110e92a8581e9670aac054.zip
is_code_ref can now be an opcode too
-rw-r--r--lib/Text/Handlebars.pm4
-rw-r--r--lib/Text/Handlebars/Compiler.pm17
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) = @_;