Created
February 4, 2009 06:27
-
-
Save kyanny/57986 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
use strict; | |
use Template; | |
use Data::Dumper; | |
sub myfilter { | |
my ($context, $key) = @_; | |
return sub { | |
my $text = shift; | |
warn ref $context; | |
warn ref $context->stash; | |
warn Dumper $context->stash; | |
warn ref $context->stash->get('component'); | |
my $content = $context->stash->get($text); | |
return $content; | |
}; | |
} | |
my $tt = Template->new( | |
FILTERS => { | |
myfilter => [\&myfilter, 1], | |
}, | |
); | |
$tt->process('hoge.tt', {}, \my $output); | |
$tt = Template->new( | |
FILTERS => { | |
myfilter => [\&myfilter, 1], | |
}, | |
); | |
my $tmpl = <<TMPL; | |
[% MACRO foo BLOCK %] | |
blah blah blah | |
[% END %] | |
[%- 'foo' | myfilter('key') %] | |
TMPL | |
$tt->process(\$tmpl, {}, \my $output); | |
__END__ | |
[kyanny@kyanny-laptop2 ~/daily/2009-02-04] | |
$ ./tt-stash-component.pl | |
Template::Context at ./tt-stash-component.pl line 12. | |
Template::Stash::XS at ./tt-stash-component.pl line 13. | |
$VAR1 = bless( { | |
'template' => bless( { | |
'_DEFBLOCKS' => {}, | |
'_BLOCK' => sub { "DUMMY" }, | |
'modtime' => 1233727427, | |
'name' => 'hoge.tt', | |
'_HOT' => 1 | |
}, 'Template::Document' ), | |
'global' => {}, | |
'inc' => sub { "DUMMY" }, | |
'dec' => sub { "DUMMY" }, | |
'component' => $VAR1->{'template'}, | |
'_DEBUG' => 0, | |
'foo' => sub { "DUMMY" }, | |
'_PARENT' => bless( { | |
'global' => $VAR1->{'global'}, | |
'inc' => $VAR1->{'inc'}, | |
'_DEBUG' => 0, | |
'dec' => $VAR1->{'dec'}, | |
'_PARENT' => undef | |
}, 'Template::Stash::XS' ) | |
}, 'Template::Stash::XS' ); | |
Template::Document at ./tt-stash-component.pl line 15. | |
Template::Context at ./tt-stash-component.pl line 12. | |
Template::Stash::XS at ./tt-stash-component.pl line 13. | |
$VAR1 = bless( { | |
'template' => bless( { | |
'_DEFBLOCKS' => {}, | |
'_BLOCK' => sub { "DUMMY" }, | |
'modtime' => 1233728058, | |
'name' => 'input text', | |
'_HOT' => 1 | |
}, 'Template::Document' ), | |
'global' => {}, | |
'inc' => sub { "DUMMY" }, | |
'dec' => sub { "DUMMY" }, | |
'component' => $VAR1->{'template'}, | |
'_DEBUG' => 0, | |
'foo' => sub { "DUMMY" }, | |
'_PARENT' => bless( { | |
'global' => $VAR1->{'global'}, | |
'inc' => $VAR1->{'inc'}, | |
'_DEBUG' => 0, | |
'dec' => $VAR1->{'dec'}, | |
'_PARENT' => undef | |
}, 'Template::Stash::XS' ) | |
}, 'Template::Stash::XS' ); | |
Template::Document at ./tt-stash-component.pl line 15. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment