> > but I do see several problems with this approach:
> > - It's not a template.
> 
> In what sense? The example was pretty contrived but how I
> actually use it is to pass in a bunch of vars to substitute
> into the XML. Seems like a template to me.

You could argue that any program that produces output is a template of
sorts, but when people use things like TT they are normally talking
about something that starts out looking close to a finished document and
just modifies some small parts.

> What about something like:
> 
>  [% xw = XML.Writer %]
>  <html>
>    <head>
>      <title>[% doc.title | html %]</title>
>      [% FOREACH name IN doc.meta.keys ;
>           xw.emptyTag('meta', name=>name, content=>doc.meta.$name);
>         END; %]
>    </head>
>    <body>

That looks more like a template, since at least some of the boiler-plate
is actually there.

> > - It doesn't get the syntax checking that perl code normally would.
> 
> Of course, it gets the syntax checking that templates normally do.

That really can't compete with strict and warnings, not to mention
perltidy and Perl::Critic and syntax-coloring in your editor.  TT is
intentionally loose about data types and defined-ness.

> > - It can't be debugged or profiled in the normal ways.
> 
> In the normal ways you do with templates.
> Whats stopping you profilling TT code?
> (I'm pobably luck in never really having performace problems
> with templates.)

I've run TT code through the profiler and debugger.  You get tons of
calls to TT internals.  It's very hard to debug a template that way.

> > - It's a lot slower than it needs to be.
> 
> Depends how fast it needs to be. Hard to say without
> some profilling.

Let me rephrase that: it's much slower than the equivalent perl script
would be.

> Templates complile down to a perl script
> so it's not much different, apart from some extra calls
> due to the plugin wrapping.

There is a lot of overhead in reading the stash and making those calls,
compared to reading normal perl variables and making the method calls
directly.

> You snipped the bit about non-perl coders. Do you not think
> XML::Writer could be useful functionality to expose to
> Template coders?

I think most would prefer a more traditional templating approach.  As
you said, it can be hard to match up your tags that way, but it can also
be easier to see what the intended result is.

Having said that, go ahead and put it up.  There's nothing wrong with
your module and there may be other people who find it useful.  I
personally prefer to write all significant chunks of code in perl rather
than TT.

- Perrin


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to