[Templates] Subclassing Template::Stash::XS
Paul Seamons
mail@seamons.com
Wed, 21 Jun 2006 10:36:58 -0600
> Is there a way to have the perl undef value returned for undefined
> variables when using Template::Stash::XS?
This doesn't answer the particular question, but it may add more fodder to the
fire.
CGI::Ex::Template has two methods that can be overridden - undefined_get and
undefined_any. undefined_get is called if a variable or expression is
undefined during a GET directive. undefined_any is called anytime a variable
is requested and operates more closely to what Template::Stash::undefined
does.
The benefit of having these two methods is that you can do:
sub undefined_any { undef }
sub undefined_get { '' }
And then it is easy to see if anything was actually undefined when variables
are passed to other functions - but still get an empty string when swapped
into a template.
You could also do:
sub undefined_get {
my $self = shift;
my $id = shift;
return 'Id: '.Data::Dumper::Dumper($id).' was not defined';
}
And things like:
[% foo || bar %]
Would correctly work, but calling
[% foo %]
Would swap in a big message if foo wasn't defined.
Again - this isn't an answer, just more ideas for how to extend Stash.
Paul