http://www.perlmonks.org?node_id=997048


in reply to Re^3: XML::Twig - provide additional parameters to twig_roots handlers
in thread XML::Twig - provide additional parameters to twig_roots handlers

Well, the XML::Twig object is an old fashion hashref, and I have no plan to change this, so you can always add your own fields to it. Or use a "hidden" attribute (one which names starts with '#') to attach private data to any element, including the root.

A closure is the cleanest way to go though. It's not a trick, it's just a common idiom.

BTW, a google search on "XML::Twig passing data to handlers" (or using "arguments" instead of data) returns plenty of answers to that question.