From fb6e289d7fe95bf9b7aec9acd9ccfe155274e0da Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 19 Oct 2012 11:26:40 -0500 Subject: find_file and suffix are now opcodes --- lib/Text/Handlebars.pm | 7 ------- lib/Text/Handlebars/Compiler.pm | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/Text/Handlebars.pm b/lib/Text/Handlebars.pm index 947a336..2bd0096 100644 --- a/lib/Text/Handlebars.pm +++ b/lib/Text/Handlebars.pm @@ -143,13 +143,6 @@ sub _register_builtin_methods { my ($funcs) = @_; weaken(my $weakself = $self); - $funcs->{'(suffix)'} = sub { - return $weakself->{suffix}; - }; - $funcs->{'(find_file)'} = sub { - my ($filename) = @_; - return try { $weakself->find_file($filename); 1 }; - }; $funcs->{'(make_block_helper)'} = sub { my ($code, $raw_text, $else_raw_text, $hash) = @_; diff --git a/lib/Text/Handlebars/Compiler.pm b/lib/Text/Handlebars/Compiler.pm index 356baeb..de7b0c4 100644 --- a/lib/Text/Handlebars/Compiler.pm +++ b/lib/Text/Handlebars/Compiler.pm @@ -83,7 +83,7 @@ sub _generate_partial { arity => 'binary', id => '~', first => $file->[0], - second => $self->call($node, '(suffix)'), + second => $node->clone(arity => 'suffix'), ); } @@ -102,11 +102,24 @@ sub _generate_partial { ); } +sub _generate_suffix { + my $self = shift; + my ($node) = @_; + + return ( + $self->opcode('suffix'), + ); +} + sub find_file { my $self = shift; my ($filename) = @_; - return $self->call($filename, '(find_file)', $filename); + return $filename->clone( + arity => 'unary', + id => 'find_file', + first => $filename, + ); } sub _generate_for { @@ -207,7 +220,7 @@ sub _generate_unary { ); # render_string can't be constant folded, because it depends on the # current vars - if ($Text::Xslate::Compiler::OPTIMIZE and $self->_code_is_literal(@code) && $node->id ne 'render_string') { + if ($Text::Xslate::Compiler::OPTIMIZE and $self->_code_is_literal(@code) && $node->id ne 'render_string' && $node->id ne 'find_file') { $self->_fold_constants(\@code); } return @code; @@ -223,7 +236,7 @@ sub is_unary { my %unary = ( map { $_ => 1 } qw(builtin_is_array_ref builtin_is_hash_ref is_code_ref - render_string) + find_file render_string) ); return $unary{$id}; -- cgit v1.2.3