in reply to XML::Twig parsefile_inplace misunderstanding

At first glance it looks like a bug in XML::Twig, but if you see the test suite you'll see the use-case, XML-Twig-3.44-new/t/test_3_26.t

XML::Twig->new( twig_handlers => { bar => sub { $_->set_tag( 'to +to')->flush; }}) ->parsefile_inplace( $file, '.bak');

The call to flush does printing (as well as eating of the tree), which you don't have

If you add  twig_handlers => { _all_ => sub { $_[0]->flush } } you'll get what you're after

Replies are listed 'Best First'.
Re^2: XML::Twig parsefile_inplace misunderstanding (xml_pp twig_handlers _all_ flush)
by Discipulus (Canon) on Jul 19, 2013 at 09:27 UTC
    thanks Corion and Anonymous,

    so the inplace options are valid only during the scope of the parse_inplace call? after this normal behaviour and handle are restored?

    So it can be used only with the on-the-fly processing style and not with the tree-processing one? Should be not difficult replicate the inplace behaviour but i prefer to use the XML::Twig method for shortness and laziness.

    thanks

    L*
    there are no rules, there are no thumbs..

      so the inplace options are valid only during the scope of the parse_inplace call?

      UTSL :) its

      select temp handle; parsefile; restore original handle; rename /backup;

      So it can be used only with the on-the-fly processing style and not with the tree-processing one?

      That is tree mode. If you change the flush to a print, you'll see lots and lots of duplicated output.

      but i prefer to use the XML::Twig method for shortness and laziness.

      short/lazy things are supposed to be easy/obvious to use, I think this one got kind of got away from mirod, but its not like I have better ideas, I mean come on :)

      $twig->infile('file.xml') ->backup('.bak') ->tempout ->parseit ->replaceoriginalwithtemp