Rather than copying the entire variable stash each time we need to create a localised variable scope (e.g. INCLUDE), TT3 creates a new, empty variable stash with a parent link pointing upwards to the stash of the calling context.
When a variable is first accessed, the stash fetches it from a parent, grandparent, great-grandparent, etc., walking up through the ancestral family tree until the variable is located. It then copies it into the current local stash, effectively caching it for any subsequents access. Any new variable values are written into the local stash, leaving any previous values untouched in the parent, grandparent, etc. At the end of the template, the local stash is throw away and we revert to the parent stash.
I like this a lot. That way, when a template developer does the right thing, he also makes it more efficient at the same time. i.e., the right thing to do, as I see it, is to treat an included template like a sub, and only use inside it the variables that are passed as parameters. That way you avoid both the overhead of copying and the dangers of side effects.
BTW, I just read in the documentation for INCLUDE that the localization is only skin-deep. So in TT2 INCLUDE would only have a large performance penalty vs. PROCESS if you have a lot of top-level template variables. In TT3, with on-demand copying, will they still only be skin-deep?
TTYL, Chad.
_______________________________________________ templates mailing list [email protected] http://lists.template-toolkit.org/mailman/listinfo/templates
