Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Speed, and my sanity.

by chromatic (Archbishop)
on Aug 26, 2001 at 10:09 UTC ( [id://107896]=note: print w/replies, xml ) Need Help??


in reply to Speed, and my sanity.

Template Toolkit and Everything, the latter powering the site, actually turn a template into real Perl code. Once you have that, you can stow it somewhere safe. That's a big win, because you can skip the parsing step every time.

It's an even bigger win if you have components that rarely change. If you only have to compile a component once, it'll run at full Perl speed each time through.

If you have a working parser right now, it's not too difficult to generate Perl code. You'll certainly learn a lot. Feel free to download either package and dig through to see how it works.

Replies are listed 'Best First'.
Re: Re: Speed, and my sanity.
by Dylan (Monk) on Aug 26, 2001 at 10:32 UTC
    Wow, a reply in a very short ammount of time.. :)

    Well. I don't quite understand
    what do you mean "turn a template into real Perl code"? I already have perl code. maybe I was unclear (I am sometimes..)

    Well, sort of everything changes...

    it parsers generates HTML, not Perl code. and by 'compile' I ment it puts the same head and foot file on every page.

    I use the <@TAGS@> for all the colors.. When called like: manifold.cgi?mode=b it has basic, black and white and blue colors. and so on. So, my site is thus skinned. Perhaps I should post the code..

      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:
      <b>Name: </b><% $name %><br>
      The HTML is the outer layer, and the Perl is contained within special sections marked off by some delimiters. In this case, <% and %>.

      Most templating systems will turn something like the above into this:

      $_out->("<b>Name: </b>"); $_out->( $name ); $_out->("<br>");
      Imagine $_out is a subroutine reference that is basically just
      my $_out = sub { print @_ }
      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.

      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.

        Hmm.

        One would think that:

        <body bgcolor="<@BGCOLOR@>">, which with my engine has this done to it:

        s/<\@(\w+)\@>/$params{parse}->{$1}/ge; done to it, would be slower than:

        <body bgcolor="<% $params{parse}-{BGCOLOR} %>">,

        Embeding Perl in html, I guess, would be a good idea..
        But would I need a major rewrite? I have been working on Manifold for about 2.5 months.. :(

      Oh dear. In my question, I said a crazy perl and I ment to say a crazy person..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://107896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found