in reply to RFC: Templating without a System
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RFC: Templating without a System
by shmem (Chancellor) on Jun 20, 2006 at 23:34 UTC | |
DOM parsing is costly, I have considered that approach, but I would do it only in the design phase of the application and deployment, or after changes made to some template, its to say I wouldn't use it as the page generating core. I ran benchmark on a 5649 Byte html file with HTML::Seamstress and Servlet.
The only changes were uncomment use warnings because it clutters up the test with warnings about unitialized variables, and changed the warn "PROCESS_TREE: ", $tree->as_HTML; to a print statement. bench.pl: gave the following results: I would replace_content with variable stubs and turn the resulting file inside out, as with my code.
greetings,
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] [d/l] [select] |
by metaperl (Curate) on Jun 23, 2006 at 13:46 UTC | |
I looked around on CPAN for a singleton caching solution, but nothing really fit, so what I did was call Webpage::PackageName->new() and store the results in a cache key ahead of time. The module for caching is Class::Cache. Like I said, I didn't want to write it but it was necessary. | [reply] [d/l] |
by shmem (Chancellor) on Jun 23, 2006 at 15:13 UTC | |
You're in a fix here. Parsing HTML to a DOM tree gives you the freedom to manipulate every branch and twig and content as you like, but at the cost of speed. If you cache the modified tree or parts of it, you give away that freedom, as if you hadn't had it in the first place. If if you have fixed places where elements are altered - as with your example pages produced from spkg.pl, there is no difference to static pages with inline perl as with Mason or with my approach. In the sub process of spkg.pl-generated pages the names are even static:
To have freedom of which node has to be altered with which value, the key/value pairs should be taken from $stash. But then, again, caching is ineffective. That's why I think HTML::Seamstress is ok for template generation but not actually for serving pages. regards, _($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] [d/l] [select] |