use Template; { package MyStash; use base qw(Template::Stash); sub undefined { my $self = shift; my @ident = shift; print "(".join("|",@ident).")\n"; if (@ident > 1) { return ''; } elsif ($ident[0] eq 'adjective') { return 'red'; } elsif ($ident[0] eq 'noun') { return 'fox'; } elsif ($ident[0] eq 'verb') { return 'jumped'; } else { return ''; } } } my $stash = MyStash->new; my $string = "The [% adjective %] [% noun %] [% verb %] over the river +.\n"; Template->new(STASH => $stash)->process(\$string);
In reply to Re: Parse template into data structure
by Rhandom
in thread Parse template into data structure
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |