Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Keep It Simple, Stupid
 
PerlMonks  

Template::Toolkit and Contextual::Return

by jatill (Beadle)
on Sep 22, 2006 at 11:41 UTC ( [id://574395]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

jatill has asked for the wisdom of the Perl Monks concerning the following question:

I have a method that uses Contextual::Return to return either a hash or an object depending on how the method is called.

Ex:

sub my_method{ return LIST { $self->get_hash() } HASHREF { $self->get_hash() } OBJREF { $self->get_object()} } ; }
$self->my_method->get_age('phil') works, and so does $self->my_method->{age}{phil}.

However, when I try to use this method from Template::Toolkit, I only get a value back for $self->my_method->{age}{phil}. I am guess this is because somewhere behind the scenes, Template::Toolkit is asking for all data as a hashref, so that's what my_method will always return.

Is my guess correct? Is there a way to make Template::Toolkit behave 'intelligently', like the perl code works?

Thanks. ~jeff

Replies are listed 'Best First'.
Re: Template::Toolkit and Contextual::Return
by perrin (Chancellor) on Sep 22, 2006 at 14:55 UTC
    The TT stash code tries to examine what it's being used on to see if it should be called as a method or as a hash. It works iteratively, so it will call $self->my_method, and then call ->get_age on that. I don't use Contextual::Return so I don't know what it's looking for, but it sounds like actual method chaining may be needed in order to make it work, and TT will not do that when evaluating dot notation.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://574395]
Approved by Corion
Front-paged by grep
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.