>Yes. Writing a templating system in Perl is trivial. Writing a
>*useful* templating system in Perl is demonstratably hard.
I too have written a templating system.
About a year ago I wrote a simple module called dbq.pm. It performed
database queries. Basically, you could mock up a simple html page,
add some special dbq tags, and it would run queries against the
database. I wrote it to see if I could write a simple version of
ColdFusion.... It took 90 minutes to write on a saturday night.
On monday morning, I made the mistake of showing it to my boss. He
made it is personal quest to try to rewrite parts of our existing CGI
system using this 90 minute version of ColdFusion.
As his quest continued, he found that there were certain features
that were not present. It was quickly made a "company project," and
new features (such as the ability to interface with our existing
widget and api modules) were added.
Then we switched to using XHTML. Everything had to be compliant. We
started using Expat. DBQ (now XML::DBQ) started core dumping
mysteriously. We traced everything to a problems with the (then
unstable) Expat libraries. So we rewrote the XML parser using native
perl. Since we now had full control over the parser, we found we
could add new features (like if else constructs and defines).
Then we added the ability to execute internal perl functions (like
substr). Our quest was still not over, and we continued to add more
features.
And it is now that we realize that we have written a system that is 3
times slower than CGI, 8 times slower than mod_perl, 10 times more
difficult to read than perl, and is being used in about 45% of our
site.
The moral of this story is that using an existing templating system
will save you more hours of coding, learning, debugging, upgrading,
adding new features, and maintaining than you could possibly hope to
account for when writing a "Simple" templating system.
I hope this helps answer any questions about why you should not write
your own templating system.
Robert Landrum