Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by Jenda (Abbot)
on Oct 01, 2012 at 22:16 UTC ( #996759=note: print w/ replies, xml ) Need Help??


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

The thing is that you may very well want to have several different twig roots with different handlers and different piece of data to pass. XML::Twig could have given you a "pad" within the parser object that you could use to store something in between the handler calls, but (at least according to a quick scan ... I don't use XML::Twig myself) seems mirod did not think it's necessary.

Yes, I agree that other thread is a bit hard to find.

Jenda
Enoch was right!
Enjoy the last years of Rome.


Comment on Re^3: XML::Twig - provide additional parameters to twig_roots handlers
Re^4: XML::Twig - provide additional parameters to twig_roots handlers
by mirod (Canon) on Oct 03, 2012 at 12:34 UTC

    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.

      Or use a "hidden" attribute (one which names starts with '#') to

      I take it that means twig will ignore it?

      When I stashed data I usually prefer $$t{_anony_foo} or $$t{_progname_foo} or $$t{_subclassname_foo}

      The problem with adding own fields into the hashref is that you might unintentionally step over something. Or have an update to the module break your script, because the module starts using some key you added. That's why I specifically reserved $parser->{pad} as a place for user defined data attached to a parser and $parser->{parameters} as a place where you can find the additional parameter passed to the $parser->parse() call in XML::Rules.

      Agreed on the closure being the cleanest way.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

Re^4: XML::Twig - provide additional parameters to twig_roots handlers
by Anonymous Monk on Oct 03, 2012 at 15:11 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996759]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2014-08-28 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (263 votes), past polls