Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created February 4, 2009 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanny/57986 to your computer and use it in GitHub Desktop.
Save kyanny/57986 to your computer and use it in GitHub Desktop.
#!/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