[jifty-devel] RFC: New Template::Declare Mixin Interface

David E. Wheeler david at kineticode.com
Tue Oct 6 17:17:58 EDT 2009


I'm now pretty clear on how importing templates works in  
Template::Declare. And I think I've got a handle on aliasing, too,  
though there may well be some subtleties I've missed. But part of the  
reason why it was tough for me to figure out (aside from the lack of  
documentation) was the fact that these two methods do very similar  
things (interface-wise), though their implementations are very  
different. The fact that they both fall under the header "Mixin" only  
increased the confusion for me.

Before I document these methods, I'd like to propose a new interface  
that incorporates the features of both importing and aliasing, but  
gives template authors and users a log more control over composition.  
It's simpler, too. I propose a new method: mix. To get the current  
behavior of import_templates, you'd use:

   mix MyApp::SomeRole under '/somerole';

To get the alias behavior, you'd use:

   mix MyApp::Stuff under '/stuff' with { name => 'Larry' };

Furthermore, I'd add another keyword, into, which would allow not just  
template authors, but template users to mix stuff around. For example:

   mix MyApp::Stuff into MyApp::Main under '/stuff';

This would mix MyApp::Stuff into MyApp::Main -- I do not have to be  
the author of MyApp::Main (or re-open the package) to do it. If no  
`under` argument is passed, it would default to `caller(0)`, just as  
it does now.

At first, I'd probably just have the code dispatch to `alias` and  
`import_templates`, even as I'd like to deprecate those methods. But  
long-term, it might make sense to make aliases and imported templates  
use the same implementation.

I think that this is a cleaner interface, simpler to understand as  
mixing, and less prone to confusing users.




More information about the jifty-devel mailing list