On 7/25/07, Matisse Enzer <[EMAIL PROTECTED]> wrote:
How do get Template Toolkit to throw an exception if it encounters a
call to a non-existent method?

In the following example  zoo   is an object, but there is no
get_animals()  method - so I want TT to throw an exception at that
point.

            [% FOREACH animal IN zoo.get_animals %]

Everyone's suggesting ways to work around your problem... but I think
this is a flaw in Template.  I thought it was the case that if foo is
an object, then foo.bar is the bar method, or if foo is a hash, and
foo.bar is the value corresponding to the key bar.  But apparently, if
foo is an object implemented as a hash that lacks a bar method,
Template is looking up the value corresponding to the key bar.  The
problem with that is you are giving users the chance to peek inside
objects waaaaay too easily.  Objects are supposed to be accessed using
their API.

Am I correct in assuming that in your example, zoo is an object whose
implementation is a hash?  What do you get if you do the same thing
for an object whose implementation is something other than a hash?

For backward compatibility sake, I don't think we can change this
behavior.  But what if an option could be added that would make the
Template engine treat objects more strictly?  Seems analagous to the
'use strict' pragma in Perl to me.

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

Reply via email to