Subject: | Paste operation in twig_handlers apparently broken in 3.40 |
A simple paste operation I was using for years is broken in 3.40 but
works in 3.39. Maybe I'm doing it wrong, of course, but here is the
code.
Rolling back to 3.39, ceteris paribus, MODIFIED TWIG is identical to NEW
XML. In 3.40, they are identical for a ->cut operation, but for the -
Show quoted text
>paste shown below, NEW XML does not show the pasted element. Behavior
is different between cut and paste. Performing a ->cut and then a -
Show quoted text>paste in the same handler will result in the ->cut op expressed in NEW
XML, but not the ->paste.
I had the same problem when I created an ::Elt from scratch and used
that - shouldn't matter I suppose. In real life the tag I want to paste
is more complicated so I use the method below.
#!/usr/bin/perl
use common::sense;
use XML::Twig;
my $t = XML::Twig->new(
twig_handlers => { '//plant/fruit' => \&h_paste }
);
$t->parse(\*DATA);
print "NEW XML:\n" . $t->sprint() . "\n";
sub h_paste {
my ( $twig, $elt ) = @_;
my $tag = '<berry>Tomato</berry>';
my $new_twig = XML::Twig->new( pretty_print => 'indented' )-
Show quoted text>parse($tag);
$new_twig->root->paste($elt);
print "MODIFIED TWIG:\n" . $twig->sprint() . "\n";
}
__DATA__
<plant>
<flower>Rose</flower>
<fruit>
<berry>Blackberry</berry>
</fruit>
<veggie>Carrot</veggie>
</plant>