From: "Eric Wilhelm" <[EMAIL PROTECTED]>
# from Jim Schneider
# on Sunday 12 March 2006 03:44 pm:
3) Well, I'm currently calling it TemplateLoader, but that's too
horrible for words. Your provide some particulars on the module
"use" line, and it creates a method in the calling class that loads
the template. Any suggestions for this one would definitely be
appreciated.
What kind of templates does it load? What sort of API does it provide?
I'm using it to load HTML::Template-type files. It's used like this:
use TemplateLoader (
template => 'main_template',
filename => 'main.tmpl',
defaults => { key1 => 'val1', },
) ;
# Somewhat later on in your code....
my $tmpl = $self->main_template(key2 => $val2);
After the above snippet, $tmpl is an HTML::Template object (or similar -
details shortly), and it's had its param() method called twice - once with
either key1 => 'val1', or key1 => $self->val1 (if the method exists), and
once with key2 => $val2.
Since I am using this with CGI::Application, I'm using the "load_tmpl"
method to load the template, but you can specify something else to load the
template. The only restriction on the template object itself is that it has
a "param" method, and even that can be changed. The module itself doesn't
require any others to function.
-<snip>-
But it isn't a base class although it injects methods into your
namespace? If so, it sounds a bit like a Trait, though
Trait::TemplateLoader isn't quite right.
It's not really a base class - you don't inherit from it, you import from it
(similar to the "constant" pragma).
The fact that template has meaning in the context of methods (e.g. the
C++ meaning and the more general prototype meaning) isn't going to
help. Template::LoaderMethod?
Like I said, the name I have is too horrible for words.