merlyn has asked for the wisdom of the Perl Monks concerning the following question:
So, I've got a hunk of TT code in my CGI::Prototype application that I want to move to a separate file, and reuse. Fine, TT has INCLUDE and WRAPPER and all that cool stuff.
Except, the code calls "self.THIS" and "self.THAT" to do the heavy lifting, calling back to the "self" passed in to the template, corresponding to the same named ".pm" file next to the ".tt" file.
If I put that code into a separate template, the "heavy lifting" code will have to be moved all the way back up to the top of my application, if I'm planning on using this TT chunk in more than one page.
So, my idea is to "call" a subtemplate in a special way that creates a lightweight class (this is Class::Prototyped, so I can do that trivially) that creates a temporary new "self" that inherits from both the calling page (the original self) and the mix-in code (in a new same-named .pm file) to do the heavy lifting for the subpage. I figure the search order will be mix-in, then original, so that I don't have to worry that some other part of my app has a conflicting name.
But then, oops, how do I create defaults in my mixin code that can be overridden by the caller? It's not like a traditional inheritance, where I can override, because the mix-in code will go to its own default before it checks the rest of the tree?
Am I bonkers? How are mixins with defaults and overrides normally handled?
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mixins (problem in CGI::Prototype and Class::Protototyped with subtemplates)
by cbrandtbuffalo (Deacon) on Mar 16, 2005 at 16:55 UTC | |
by merlyn (Sage) on Mar 16, 2005 at 17:04 UTC | |
|
Re: Mixins (problem in CGI::Prototype and Class::Protototyped with subtemplates)
by metaperl (Curate) on Mar 16, 2005 at 19:19 UTC |