Checking values for definedness under STRICT

Andy Lester <andy-U7RegYgSe6NWk0Htik3J/[email protected]> Thu, 22 Jan 2015 16:35:52 -0600
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <[email protected]>
--===============0902869987245852022==
Content-Type: multipart/alternative; boundary="Apple-Mail=_D6BF77EC-2BB7-4F49-BB13-3403C72C584D"


--Apple-Mail=_D6BF77EC-2BB7-4F49-BB13-3403C72C584D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii


Can we not check for definedness under STRICT in TT?

Here's my test program that blows up:

$ cat foo.pl
#!/usr/bin/perl

use strict;
use warnings;

use Template;

my $template =3D <<'END';
Hello, [% name.defined ? name : 'unknown person' %]
How are things in [% town.defined ? town : 'your town' %]?
END

my $tt =3D Template->new( { STRICT =3D> 1 } );

$tt->process( \$template, { name =3D> 'Dave', town =3D> undef } ) or die =
$tt->error, "\n";

$ perl foo.pl
var.undef error - undefined variable: town.defined

This seems wrong to me, and this post by RJBS =
(http://rjbs.manxome.org/rubric/entry/1995) seems to verify it.

Is there something we're missing?

Thanks,
xoa

--
Andy Lester =3D> www.petdance.com


--Apple-Mail=_D6BF77EC-2BB7-4F49-BB13-3403C72C584D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=us-ascii

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;"><div><br></div><div>Can we not check for definedness =
under STRICT in TT?</div><div><br></div><div>Here's my test program that =
blows up:</div><div><br></div><div><font face=3D"Courier New">$&nbsp;cat =
foo.pl<br>#!/usr/bin/perl<br><br>use strict;<br>use warnings;<br><br>use =
Template;<br><br>my $template =3D &lt;&lt;'END';<br>Hello, [% =
name.defined ? name : 'unknown person' %]<br>How are things in [% =
town.defined ? town : 'your town' %]?<br>END<br><br>my $tt =3D =
Template-&gt;new( { STRICT =3D&gt; 1 } );<br><br>$tt-&gt;process( =
\$template, { name =3D&gt; 'Dave', town =3D&gt; undef } ) or die =
$tt-&gt;error, "\n";<br><br></font></div><div><font face=3D"Courier =
New">$&nbsp;perl foo.pl<br>var.undef error - undefined variable: =
town.defined</font></div><div><br></div><div>This seems wrong to me, and =
this post by RJBS (<a =
href=3D"http://rjbs.manxome.org/rubric/entry/1995">http://rjbs.manxome.org=
/rubric/entry/1995</a>) seems to verify it.</div><div><br></div><div>Is =
there something we're =
missing?</div><div><br></div><div>Thanks,</div><div>xoa</div><br><div =
apple-content-edited=3D"true">
<div style=3D"color: rgb(0, 0, 0); letter-spacing: normal; orphans: =
auto; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: auto; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span =
class=3D"Apple-style-span" style=3D"border-collapse: separate; =
font-family: 'Courier New'; border-spacing: 0px;"><div style=3D"word-wrap:=
 break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;"><span class=3D"Apple-style-span" =
style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =
'Courier New'; font-style: normal; font-variant: normal; font-weight: =
normal; letter-spacing: normal; line-height: normal; orphans: 2; =
text-indent: 0px; text-transform: none; white-space: normal; widows: 2; =
word-spacing: 0px; border-spacing: 0px; =
-webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: =
0px;"><div style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; =
-webkit-line-break: after-white-space;">--<br>Andy Lester =3D&gt; <a =
href=3D"http://www.petdance.com">www.petdance.com</a></div></span></div></=
span></div>
</div>
<br></body></html>=

--Apple-Mail=_D6BF77EC-2BB7-4F49-BB13-3403C72C584D--


--===============0902869987245852022==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

--===============0902869987245852022==--