Gossamer Forum
Home : General : Perl Programming :

Template Parser

Quote Reply
Template Parser
I'm coming to the end of writing my template parser inspired by GT's and was just excited at how nicely it turned out so thought I'd make a post in honour of that fact :)

I still have a few things to add like calculations and loops but you can see the syntax it supports (well some of it) in the attached file.

I'm thinking of submitting it to cpan as it is one of the best modules I've written but I've not decided yet.

Last edited by:

Paul: Jun 6, 2002, 7:14 AM
Quote Reply
Re: [Paul] Template Parser In reply to
Very nice. I've been working on one myself. I've only been able to impliment if statements, variables, includes and hopefully elses sometime. Pretty cool that yours supports elsif and unless.

As far as loops, what do you think the performance hit will be ie do you think loops would be better off let to actual perl code instead of a parser, I've interested in this point as I've never done any tests on this portion.
http://www.fullmoonshining.com for Pearl Jam Fans
Quote Reply
Re: [haplo] Template Parser In reply to
>>Pretty cool that yours supports elsif and unless. <<

The trick is to let perl do the work. The parser builds the output as perl code and evals it so it's not as tricky as it first seems (took me ages to figure it out though...I totally overlooked the description at the top of GT::Template...hehe)

As for loops, I couldn't say for sure...maybe a staff member could, but loops will probably be slightly slower than building the output in the perl script but unless you have lots of loops I don't think it would hurt that much.
Quote Reply
Re: [Paul] Template Parser In reply to
In Reply To:
>>Pretty cool that yours supports elsif and unless. <<

The trick is to let perl do the work. The parser builds the output as perl code and evals it so it's not as tricky as it first seems (took me ages to figure it out though...I totally overlooked the description at the top of GT::Template...hehe)


GT::Template version 2.000 saw the introduction of parsing templates into Perl, as a speedup. We were expecting that the first parse would be slower, since we have to parse _and_ run the code, but much to our surprise, parsing and then running the code was actually faster than the parsing in version 1.

In Reply To:


As for loops, I couldn't say for sure...maybe a staff member could, but loops will probably be slightly slower than building the output in the perl script but unless you have lots of loops I don't think it would hurt that much.
Building up variables in Perl code is slightly faster than compared to GT::Template's loops, however if you are parsing a template multiple times in the code to build up the value of that loop, GT::Template loops wins hands down.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com