Pretty much what Tanktalus said earlier. This code is a vastly simplified example piece that reproduces the issue in question. I tried to trim out as much unnecessary cruft to make the example as small and concise as possible while still remaining relevant

In answer to some of your questions:

  1. the way you set up the handler made me immediatly suspicious.

    the live code has some additional processing that happens after the twig is processed. It would look something like the following simplified example:

    sub { my $local_state = _move(@_); $global_state = _do_stuff_with_local_state($local_state->{SUMMARY}, \%VARS);  1; },
  2. The, perfectly correct and valid, style to call a sub with &subname

    Correct. The actual code passes extra variables to the twig processing subroutine in addition to the default TWIG and ELEMENT variables passed to the handler:

    sub { _move(@_, $local_state, \%OPTIONS, $warning_flag); 1; },
  3. For the rest I can say that, also you have an unneeded 1; as last thing in your sub.

    Pretty much what Tanktalus said earlier.

    The function called by the handler returns '1' in my simplified example (instead of variables) because it is an explicit 'true' return value

    The anonymous sub returns '1' because there are multiple twig handlers that may apply to a given twig:

    '/shipment/box' => sub { _move(@_); 1; }, '/shipment/box[@location='Vault_111']' => sub { _moveAgain(@_); 1; },

Hope that clarifies things.


In reply to Re^2: Moving elements with XML::Twig: Document root closing tag is duplicated on output -- solution by ateague
in thread [SOLVED] Moving elements with XML::Twig: Document root closing tag is duplicated on output by ateague

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.