[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] HTML::Template is non-reentrant under caching



Hi,

lately using HTML::Template I ran into two problems, which in fact turn
out to be the same.

First, I was using the module to generate html representing some
intricate data structures. These structures in fact also contain
sockets that have to be closed. I noticed this not happening after
the structure went out of scope.

Second, this datastructure is heavily recursive. So in fact I have
in the template a param corresponding to a function that again uses
my 'generate' routine to make the deeper structure into a string, and
returning that as a substitution value for the enclosing 'generate'.
However, the output would only contain the top level.

In fact I think both cases are caused by the fact that HTML::Template
witch cache=1 caches the previous structure INCLUDING the parameter
values (not just the names). So, in the first case, the cache kept the
data structure alive, in the second case the reuse of the same template
(while a previous one was still getting it's parameters set) stomped all
over these values.

Once I realized that, I simply solved it by setting cache to 0. But
that's a bit silly, since this is exectly the kind of case where
caching would be nice, since the recursion basically expands the
same template multiple times.

Looking at the code, I think that solving this basically needs a change
of the data structure. The thing returned from new() should be a pair
consisting of the (cached) parsed file structure and the current set of
parameters, instead of mixing them as now happens. Then when it goes out
of scope, the parameters will be unlinked too (and the cache keeps the
parsed file structure alive)

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe