On Wed, 5 Jun 2002, Andy Wardley wrote:

> In TT, you would usually pre-declare a particular format in a config
> file, pre-processed templates, or some other "global" style document.
> e.g.
>
>   [% USE money = format('%.02f') %]
>
> In your main page templates you would do something like this:
>
>   [% money(order.total) %]
>
> Then you can change the money format in one place and your designers
> don't have to worry about sprintf formats.

In HTML::Template::Expr:

  sub money { sprintf "%.02f", $_[0] }
  HTML::Template::Expr->register_function(money => \&money);

Then in the template:

  <tmpl_var expr="money(order_total)">

Now, I don't use HTML::Template::Expr.  I think it's generally not such a
good idea.  But it's there if you want it...

> See, the problem is that MVC is just one particular decomposition.  It's
> generally a good one because application, data and presentation are typically
> the three biggest aspects that you want to separate.  However, it doesn't
> take into account any of the other dozen or so aspects that you might want
> to model in your system.  Nowhere in MVC or any other Design Pattern does
> it tell you to define all your URLs in one place in case you ever need to
> change them en masse.  You have to think of that all by yourself.  MVC is
> no substitute for thinking

Oh, absolutely.  MVC is just a framework, and it only addresses a subset
of the problems in any large system.  I think that's actually a strength.
I would be deeply suspicious of any paradigm that claimed to solve ALL my
problems.  I prefer small, simple (tools|paradigms) that do one thing and
do it well.

> I've seen far too many example of people who didn't pass objects into their
> templates, didn't embed Perl code, or didn't do this or that because they
> thought that it might violate the MVC principal.

Here!

> The end result was that they jumped through hoops and made the system
> more complex than it needed to be for the sake of "purity".

It was?  I don't think this is the only result.  It might be that these
people you've observed were just the hoop-jumping, complexifying types.
I've built quite a number of large systems without embedded Perl and object
variables without excessive hoop-jumping.

Here's my theory: the best usage of most templating systems are virtually
indistinguishable and all result in reasonably maintainable systems.
However, the bad usage of some templating systems is much worse than
others.  Also, the general usage of a templating system, even by otherwise
bright people, tends more towards the bad than the good.

Thus my solution: a templating system that simply will not allow you to
put anything significantly complicated in the template.  You can't.  If
you want complexity you'll just have to put it in the code, where it
belongs.  That's HTML::Template in a nutshell.

>   [% silver.bullet %] isn't the answer by itself...

Here here.  Neither is <tmpl_var silver_bullet> but I'd rather get shot
with mine than yours!

-sam


Reply via email to