lazy saunter

(personal learnings in computation)

Sunday, May 16, 2010

template toolkit for perl websites

while most future development at work will be done in java, i inherited a second web project which will still use perl. my experience with the last was not so good, not so organized, so this time i unilaterally decided to build the site with a templating system. a year and a half back i played with mason but apparently it did not catch on with me (i believe b/c of the perceived needs to change the apache configuration and to create more component files than i thought should have been necessary. i should probably look back through my notes on the matter...).

since then i have installed and configured bugzilla to run on our work server. being written using the perl template toolkit module (TT), it has been very easy to alter the web pages without breaking the underlying code. for this latest project i sought to do the same and everything is going well so far.

a cgi script (.pl file) sets the values of variables and then calls a template file (.tpl is the extension i give these). the template file has access to all the variables passed to it in the cgi script. the variables can be scalars, lists (arrays), or hashes. within the template file, hashes can be looped through with the FOREACH directive. the variables to be printed or evaluated would take forms like "person.id" or "person.height" in the case of hash values. this is much cleaner and easier to read than stuffing an entire sql statement and execution there in the same bit of code that displays the values.

another benefit is easier delegation of duties. i am able to ask another person to work on making the design look nice while i concurrently work on the piece of code that contains the logic. third, already alluded to perhaps, is that TT is very easy for someone unfamiliar with it to understand how it works and jump right in. i did a short 45 minute presentation to our team of programmers and i think i convinced all of them that this way is superior to the current, all-in-one-pot way.

none of this concept is new, however, this is only the second project that i'll put into production that uses a templating system (the first used smarty for php) and i feel even more confident this time around. as long as the move to java web apps lingers, i plan to develop with TT and don't plan to use anything more complex since the next bump up would be significant like a move to an MVC pattern or a database abstraction model, both of which i think have much steeper learning curves.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home