Skip Menu |

This queue is for tickets about the Template-Toolkit CPAN distribution.

Report information
The Basics
Id: 91592
Status: resolved
Priority: 0/
Queue: Template-Toolkit

People
Owner: Nobody in particular
Requestors: jraspass [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Can't check defined values while under STRICT
I'm running under STRICT, I'm passing Moose objects into my template, I want to make decisions based on whether an attribute is defined. I can't/shouldn't assume the object is a hash and that the keys match the method names, so obj.defined('method') is out, I tried obj.method.defined but this throws. Below is example code demonstrating the issue: package Foo; sub new { bless [] } sub bar { warn "->bar called\n"; return; } package main; use Template; my $tt = Template->new( STRICT => 1 ); $tt->process( \'[% "It works" IF foo.bar.defined %]', { foo => Foo->new }, ) or die $tt->error; I'm not sure if this is a bug or wishlist, but I can't for the life of me see a way to use STRICT without this fixed/added.
From: ozcoder [...] gmail.com
Hi, On Mon Dec 23 06:51:44 2013, RAZ wrote: Show quoted text
> I'm running under STRICT, I'm passing Moose objects into my template, > I want to make decisions based on whether an attribute is defined. > > I can't/shouldn't assume the object is a hash and that the keys match > the method names, so obj.defined('method') is out, I tried > obj.method.defined but this throws. > > Below is example code demonstrating the issue: > > package Foo; > > sub new { bless [] } > > sub bar { > warn "->bar called\n"; > return; > } > > package main; > > use Template; > > my $tt = Template->new( STRICT => 1 ); > > $tt->process( > \'[% "It works" IF foo.bar.defined %]', > { foo => Foo->new }, > ) or die $tt->error; > > I'm not sure if this is a bug or wishlist, but I can't for the life > of me see a way to use STRICT without this fixed/added.
That's the way it is meant to work in STRICT mode. You need to do TRY CATCH blocks. See http://tt2.org/docs/manual/Config.html#section_STRICT Gordon
Ticket migrated to github as https://github.com/abw/Template2/issues/164