[Templates] How To Throw Exception on Missing Method
Matisse Enzer
menzer@apple.com
Thu, 26 Jul 2007 12:22:46 -0700
On Jul 25, 2007, at 8:36 PM, Bill Moseley wrote:
> On Wed, Jul 25, 2007 at 01:30:46PM -0700, Matisse Enzer wrote:
>> (re-posted because I stoopidly left out the Subject on the prior
>> posting. I apologize.)
>>
>> How do get Template Toolkit to throw an exception if it encounters a
>> call to a non-existent method?
>
> You want it globally, or just in some cases?
>
> DEBUG_UNDEF
>
> Otherwise, I'd test for values and use THROW if I didn't like what I
> got.
So I have tried the DEBUG_UNDEF approach, but, I now find that it
doesn't do what I want.
With DEBUG_UNDEF this template produces an error if someMethod()
exists but
returns and empty list:
[% FOREACH thing IN object.someMethod %]
[% thing %]
[% END %]
What I want is an error only if $object is undef, or if there is no
someMethod() defined, and I want this behavior globally.
What's the best practice for achieving this?
-M
------------------------------------
Matisse Enzer
menzer@apple.com