tinita has asked for the wisdom of the Perl Monks concerning the following question:

hello monks,

I'm writing a template system. before everybody says, omg, not another one, please let me explain a bit =)

I personally like HTML::Template because of its restrictions, because it is small and easy to use. what I don't like is that it is not too fast. it's fast enough for many applications, but sometimes you want it faster =)
I also don't like that you either just have access to the current level of parameters, or to every level. another thing is the syntax TMPL_*. (ok, I know i can use filters...).
also you always have to feed it a hash, it can't work with object-methods.

if I'm wrong with some of these assumptions above or below, I'm glad if you correct me.

I've also looked at Template-Toolkit, but I'm not too happy with its syntax either. what I don't know is how fast it is and how much memory it uses compared to other systems. I haven't found a comparison in the web yet.

Well, and last but not least, I wanted to see if I can program it myself =)

one question I have is about the module name - the Template-namespace is practically "owned" by TT. As my module started from HTML::Template I called it HTML::Template::Compiled (HTC). I like the name; is it too long though?

the manpage of the current version is located at HTC.html, you can download it at HTML-Template-Compiled-0.28.tar.gz (or for the latest version my download section)

I'd be glad about any comments.
The first goal of the module is that it works with most HTML::Template files (doesn't implement all features of it, though), and that it is faster than that. it compiles the template to perl code (like TT can do).

update: I'm also interested in what features HTML::Template users would like to see implemented.

update2: I added case_insensitive var names (optional) in version HTML-Template-Compiled-0.30.tar.gz and the benchmark script is now in examples/bench.pl

update3: i'm now thinking about 'Text::CTemplate' which hides the origin but is a better namespaces IMHO.

update 27.08.2005: on CPAN now: HTML::Template::Compiled

Replies are listed 'Best First'.
Re: developing a template system
by chromatic (Archbishop) on Aug 12, 2005 at 22:09 UTC

    If it's incompatible with HTML::Template, you probably oughtn't confuse people by using a similar name.

    CGI::Application work has lead to a lot of new features and plugins for HTML::Template lately, so I recommend instead you talk to the developers there about incorporating your compilation system; that could make H::T faster for everyone and prevent even more template system proliferation.

      thanks, I didn't know that.
      maybe CGI::Application could use Any::Template someday, this seems like a good idea to me, to have a generalized API to all template systems.
      I'll get in contact with the developers.
Re: developing a template system
by perrin (Chancellor) on Aug 12, 2005 at 23:49 UTC
    Take a look at HTML::Template::JIT. It compiles HTML::Template templates into C programs. It should be much faster than the one you just wrote and supports most of the HTML::Template options.
      yes, I've had a look on it already, but thanks.
      it also doesn't support all HTML::Template options, and it's about 4-8 times faster, while HTC was about 5 times faster in my tests. not too much faster in comparison.
      and it has the limitations of HTML::Template I mentioned before and in my manpage.
        I'd like to see your tests. It's hard to see how your perl one could be faster, unless it is leaving out significant pieces of functionality.
Re: developing a template system
by westernflame (Sexton) on Aug 13, 2005 at 23:57 UTC
    Maybe the best approach would be to make templating systems less restrictive. whether using a single perl script, splitting script and perl (HTML::Template) or embedding perl (HTML::Mason) there are clear disadvantages. An alternative is to join all three methods together. Have a file that is a perl script but contains the ability to include templating and embedding. For example:
    #!/usr/bin/perl use strict; my $script; my $template_variable = "templating"; while(<DATA>){ my $line = $_; $line=~s/\n//g; if ($line=~m/^(\s*)%(.*)/ig){ $script = $script."$2\n"; }else{ $script = $script."print \"$line\n\";\n"; } } #print $script; eval $script; __DATA__ <html> normal HTML %print "embedding perl \n"; $template_variable

    As little or as much templating or embedding could be done depending on the requirements of the project, without changing framework and using perl as much as possible.
Re: developing a template system
by astroboy (Chaplain) on Aug 14, 2005 at 09:03 UTC