On Mon, 11 Feb 2002, Simon Wilcox wrote:

> sub new {
>     my $class   = shift;
>     my $context = shift;
>     return bless {}, $class;
> }

If you're not going to use the context later then you don't need to save
it.  And if you're not going to do anything other than

sub new {
    my $class = shift;
    bless {}, $class;
}

In your constructor then you might as well inherit the one from
Template::Plugin that does just do that (well, in recent versions of TT
that is).

Plugins are easy and quick to write, and are more reusable than passing
in subroutines.  If (you like me) end up reusing templates more than once
in more than one project, having the subroutine as a plugin that you can
carry with you from project to project (loaded in by the template
snippet) rather than having to re-frob the parameters for each project in
question is great.

I really like the idea that Plugins allow me to encapsulate design level
functionality (i.e. the middle bit of a three tier architecture) to
manipulate the data to do things like get the size of the images.  They
allow me to decouple the data manipulation logic both from the template
(which is good) but equally importantly from the original data source.
Just because my template for a particular output format requires image
sizes to be included I see no reason why I should concern myself about
this during the first stage...this is template dependent and I shouldn't
be worrying about this kind of thing when I'm doing my application logic.

Finally, the last reason I like Plugins.  I can really easily write tests
for plugins (as they're fully decoupled.)  This is a lot harder with
subroutines passed into the templates.

Of course, this IMHO and TMTOWTDI.

Later.

Mark.

-- 
  Mark Fowler
  Technology Developer
  http://www.indicosoftware.com/




Reply via email to