I saw that but don't think it is meant for this sort of problem. That requires that I write into some "other" scratch area of the document currently being parsed. I'd do this in an obfu but not for production code. | [reply] |
Note that you can store anything in a private attribute, not just text, it's just a regular Perl variable, so an array ref is perfectly OK. (note to self, add this to the docs... done ;--)
| [reply] |
This is just an FYI but I didn't get the sense from the documentation that this was something to be used as a shared scratchpad. On re-reading it just now it occurs to me that I don't know what the private attribute is supposed to be written to or what its lifetime is.
| [reply] |
The "private" attributes are just like regular attributes, they can be accessed just like regular ones, they are just not output. So they live with the element they are attached to, and disappear when it does, either when the whole twig element goes out of scope or when the element is deleted/purged or flushed.
I usually use private attributes to store information that is attached to a part of the tree, what you call a scratchpad I guess. But I have also used it to store data for the whole document, as an "official" way to store attributes in the OO sense. This way I know that even if the author changed the underlying implementation of the twig this method would still be valid ;--)
| [reply] |