[Templates] Recursion in macros?
lmb
lars@marowsky-bree.de
Fri, 17 Jan 2003 15:08:09 +0100
On 2003-01-17T08:01:11,
darren chamberlain <dlc@users.sourceforge.net> said:
> > now my MetaCache module is working quite nicely - links change the URL
> > automatically whereever I move the page, language icons can be set,
> > the title of the page is consistent across the entire site,
> > "referenced by" lists show up automatically when I add a link
> > anywhere, I can query a list of pages which have a particular
> > attribute set etc.
> Nice. Sounds interesting; what are the chances that you'll make this
> stuff publicly available?
Quite good, actually. Right now it is tied to using a GDBM_File in the
backend and keeping some caches in Perl structs around though. This is fine
for me because I don't need concurrent access and wanted a low-overhead
solution - for really dynamic sites I'd expect that a DBI backend should be
used instead.
One ugliness I still have is the search() function for finding all pages with
'($area eq "' _ area _ '") && ($menu eq "' _ menu _ '")' if you see what I
mean. Constructing the query is quite annoying ;-)
I haven't figured out how I could make it so that I could write:
MetaCache.search(p.area == $area && p.menu.match(/$menu/))
ie, effectively allowing me to specify a TT expression so that it would be
consistent...
> Randal Schwartz had a column on this at one point, I believe, and he's
> posted his templates and code to the list; I'll see if I can dig up a
> reference to it.
Ok, thanks.
> > But I doubt that MACROs are recursion safe, are they?
> They are, since they are implemented as references to standard Perl
> subroutines, provided you terminate your recursion. Note that because
> they are implemented as subrefs, they are *not* subject to TT's normal
> recursion checks.
But they do overwrite global variables, and the PROCESS vs INCLUDE magic
didn't seem too compelling either ;-)
> > An even _further_ option would be to have the Perl function return a
> > specially formatted data structure which I could traverse with a
> > FOREACH loop and where each step contained information of whether to
> > go up a level (ie, close a </UL>) or go down one further (start a new
> > <UL>).
> This is the best way, I think; encapsulate the ugliness within straight
> perl (write a File::Find::Rule subclass that is META aware, for
> example), and then isolate your display code to a template.
OK. I guess that's what I will do then.
> > --
> > Principal Squirrel
> ^^^^^^^^^^^^^^^^^^
> Is that your *real* title?
The real title on the business cards is 'Technical Lead HA/Clustering'.
But you know. Collects kernels, builds clusters, prepares for bad times (in a
futile attempt)... sounds like a squirrel to me.
Sincerely,
Lars
--
"I'm extraordinarily patient provided I get my own way in the end."
-- Margeret Thatcher