in reply to Re: Re: Speed, and my sanity.
in thread Speed, and my sanity.
Turning a template into Perl code means turning a
template inside out: typical templating systems use
a mixture of HTML and Perl (or Perl and "something
else", which isn't necessarily HTML), where the Perl
is "inside" the HTML. Like this, sort of:
The HTML is the outer layer, and the Perl is contained within special sections marked off by some delimiters. In this case, <% and %>.<b>Name: </b><% $name %><br>
Most templating systems will turn something like the above into this:
Imagine $_out is a subroutine reference that is basically just$_out->("<b>Name: </b>"); $_out->( $name ); $_out->("<br>");
So essentially, "turning a template into Perl code" has created a piece of Perl code with a bunch of print statements, which is what you might have written if you hadn't used templates at all. This is what I mean by turning the template inside out: you have taken a template that was HTML with embedded Perl, and have turned it into a Perl script with embedded HTML.my $_out = sub { print @_ }
The advantage to Perl code is that Perl code is fast. :) Ie. if you have a block of Perl code, you can execute it directly; you don't have to parse it as a template. So you can store it in this intermediate Perl script form, and then just run it again without reparsing the original template.
This is a relatively standard way of caching templates for many Perl templating engines. And obviously, this is just a small example, but it shows the basics of how it works.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Re: Speed, and my sanity.
by Dylan (Monk) on Aug 26, 2001 at 21:42 UTC | |
by btrott (Parson) on Aug 26, 2001 at 22:19 UTC |
In Section
Seekers of Perl Wisdom