Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Very nice article, but I must say you overcomplicate things. I've developed similar template system, used by group of freelance programmers in last 5 years. For me it looks like you make few wrong design decisions and thus result in lot of additional work and problems.

Please don't take my comment as "I'm rock, you suck", I'm just wanna show design differences between our systems to prove this task can be solved much ease.

My system has same features as yours, except 'include template' feature and 'caching' feature (my parser is small and fast so I just don't need caching for now).

My template syntax was designed to work well in WYSIWYG-editors like Dreamweaver. For code which should be executed without outputing anything I've used <!--& ... --> constuct, so it looks like html-comments for such editors. For code which should insert something into html I've used three different construct: @~...~@, ^~...~^ and #~...~#, so web designer is able to see: here will be inserted some text.
Only difference between them is escaping: @~~@ add html-escaping, ^~~^ add uri-escaping and #~~# leave text as is for case I need to generate html tags from my code (bad idea usually - because make web designer work too hard - and used rarely).
That's all, only 4 special tags!

I've also used eperl idea "A template is just a program, but you quote the code, not the output.", but for solving ';' issue I've used do{}, as Jenda proposed in previous comment.

My module has many other features in addition to template processing (outputing die() message to browser, sending files to browser, sending redirects, reloading changed files from disk (for mod_perl environment), supporting correct line numbers for error messages).
And all these tasks solved in 150 lines of code (parser itself is 30 lines), less than 6KB.

Some other notes:

  • namespace issue I've solved by using no global variables (as mod_perl recommend), this way everything works fine in 'main::'
  • instead of using 'print' I've added text into some variable (accumulator), this solve STDOUT/OUT issue
  • no problem with non-scalar variables and references because I can use any my() scalars/arrays/hashes
  • to comment my perl code I use usual #-comments inside <--& ... --> block, no need for special tag because that perl block will not be included in generated html anyway
I'll not include here code examples, this comment already too long, but you can download my POWER::iCGI-2.73 module from my site and check it code.

In reply to Re: The history of a templating engine by powerman
in thread The history of a templating engine by jimt

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (8)
    As of 2018-06-17 22:49 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (107 votes). Check out past polls.