Lately, I've added an AUTOLOAD function to a class from which many other 
classes descend; the goal 
of that was to provide factory methods that would figure out the requested 
class name automatically, 
and that worked well enough for that purpose.

But when I try to use these objects in a template, it results in unwanted calls 
to my AUTOLOAD 
function - when I just want to access a property of the object, not a function.

As an example, assuming an object called "user", I would expect this:

[% user.email %]

to give me whatever's in

$user->{email}

instead, it tries to call a function email(), before looking for a hash member 
by that name.
As there is no email() function, AUTOLOAD is invoked - and my AUTOLOAD gives a 
fatal error because 
it can't find any email function anywhere in the inheritance chain or in the 
functions it knows how 
to create automatically.

As a temporary kluge, I have AUTOLOAD intepret the function name as a hash key 
name and return that, 
if it exists... but I'm not comfortable munging together function and hash key 
namespaces like this, 
and it isn't going to work when the hash key might legitimately be undefined.

Is there any way to prevent TT from calling functions that don't exist and 
falling into AUTOLOAD? 
Or requiring parentheses on method calls so that functions and variables are 
truly distinct?

Or, is there some magic value I could return from AUTOLOAD that TT would 
interpret as meaning "I 
really don't want to have a function call for this symbol, go look for it as a 
hash key and pretend 
there never was an AUTOLOAD"?

thanks, matt.




_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to