GrandFather has asked for the wisdom of the Perl Monks concerning the following question:

In playing around with code for a recent SoPW answer I got distracted by what seems to be a bug in XML::Twig. I updated to the current version and the problem seems to have changed somewhat (the "answer" code now works if a flush is removed), but there seems to be a related error:

use strict; use warnings; use XML::Twig; my $org = <<XML; <XXX> </XXX> XML print "XML::Twig version $XML::Twig::VERSION\n"; my $twig = XML::Twig->new ( twig_roots => {'head' => \&editNode,}, twig_print_outside_roots => 1 ); $twig->parse ($org); $twig->flush (); sub editNode { my ($t, $elt) = @_; $t->flush (); }

Prints:

XML::Twig version 3.32 <XXX> </XXX> </XXX>

Note the duplicated close tag. Removing the flush after the parse fixes the problem, but the documentation and samples mention in several places that it should be there.

Is it a bug? Should I report it?

Update reported as rt://39848.


Perl reduces RSI - it saves typing

Replies are listed 'Best First'.
Re: XML::Twig - bug or something else?
by mirod (Canon) on Oct 07, 2008 at 11:20 UTC

    It's a bug: when the root triggers are never activated, then the root end tag gets output twice. It's caused by the new code that makes the final flush optional (as long as flush has been called at least once during parsing). It seemed to be a common mistake, so I tried preventing it from happening.

    The development version on the XML::Twig site is fixed (but I haven't added a test yet).

Re: XML::Twig - bug or something else?
by dHarry (Abbot) on Oct 07, 2008 at 07:25 UTC

    I don’t think it’s a bug, is it? I encountered something similar, see for example Putting XML::Twig to the test. I did some performance tests with XML::Twig using different approaches and also ran into similar things. Normally I blame my code.

    As is said in the online tutorial:
    Note: as of XML::Twig 3.23, there is no longer any need to call flush one last time after the document is completely parsed. If the document was flushed, then it will be "auto-flushed" (to the same filehandle used for the first flush) after the parse.

    Maybe the man can shine his light on this one?

    cheers
    dHarry

Re: XML::Twig - bug or something else?
by Anonymous Monk on Oct 07, 2008 at 00:47 UTC
    Is it a bug? Should I report it?
    yes and yes