> Anyway, I've noticed that Template::Stash incorrectly 'die's upon _any_
> use of an undefined variable when in DEBUG mode, including in the
> following example (from the docs):
>
> [% user = get_user(uid) IF uid.defined %]
>
> I realize that this is consistent with the documentation, but it seems
> rather unintuitive to raise a fatal exception when one is already being
> cautious.
I agree. But there are two separate questions here: (1) does uid
exist, and (2) does it have a value other than "undef"? Maybe there
should be a couple of settings for DEBUG, one that traps variables
that don't exist, and a second that traps variable values of "undef"?
It sounds like we need an new (special) operator called "exist", which
could be implemented along the lines this proposed patch to Stash that
adds special operators "ref" and "scalar":
http://www.template-toolkit.org/pipermail/templates/2001-May/001012.html
This method could also be used to make "defined" not raise an exception
when DEBUG is set.
BTW, there is another bug with undef values. stash->get converts undef
to an empty string, so an undef value in the stash doesn't survive any
expression, argument passing or assignment. For example, this program
sets y to '' (rather than undef), and prints "y is defined".
use Template;
$tt = Template->new();
$tt->process(\*DATA, { x => undef }) || die $tt->error();
__DATA__
[%
y = x;
"x is defined\n" IF ( x.defined );
"y is defined\n" IF ( y.defined );
%]
Craig