xslate / p5-Text-Xslate

Scalable template engine for Perl5
https://metacpan.org/release/Text-Xslate
Other
121 stars 47 forks source link

Missing var problem with include binding & hash_with_default(Tie::Hash) #172

Closed pokutuna closed 7 years ago

pokutuna commented 7 years ago

I was stuck about this problem!

code:

use strict;
use warnings;

use Data::Section::Simple;
use Text::Xslate;
use Text::Xslate::Util;

my $vpath = Data::Section::Simple->new()->get_data_section();
my $vars = { foo => 'hoge', bar => 'fuga' };

my $xslate = Text::Xslate->new(path => [$vpath]);

# OK
warn $xslate->render('base.tx', $vars); #=> foo:hoge, bar:fuga

# NG: missing $foo
my $tied = Text::Xslate::Util::hash_with_default($vars, sub { "FILL @_" });
warn $xslate->render('base.tx', $tied); #=> foo:, bar:fuga

# OK with PP
require Text::Xslate::PP;
my $xslate_pp = Text::Xslate->new(path => [$vpath]);
warn $xslate_pp->render('base.tx', $tied); #=> foo:hoge, bar:fuga

__DATA__
@@ base.tx
:include _partial { foo => $foo }
@@ _partial.tx
foo:<: $foo :>, bar:<: $bar :>

I thing this is a bug because of the different behavior with PP.

syohex commented 7 years ago

I'm working at #173

syohex commented 7 years ago

@pokutuna Sorry belated reply. How about #173 ?

pokutuna commented 7 years ago

I don't have enough skills to maintain XS, but it looks good. The regression test is ok & #173 works correctly in my cases. Thanks for fixing this problem!

syohex commented 7 years ago

Thanks for checking code.

syohex commented 7 years ago

New version is released.