Subject: | wrap_children() fails with 'Can't call method "wrap_in" on an undefined value at...' |
The wrap_children() method fails with
Can't call method "wrap_in" on an undefined value at /usr/share/perl5/XML/Twig.pm line 9312.
when I do the following:
1. Read in an original twig.
2. Make a new twig and twig root.
3. Set the contents of the new twig's root to stuff I cut from the original twig.
4. Perform a wrap_children() on the new contents.
In the included testcase, somehow the handler that sets an ID on the <about> tag is related to the problem; commenting that handler averts the problem.
Subject: | wc_bug.pl |
#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig;
my $xml = <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<manual>
<about>
<title/>
<intro/>
</about>
</manual>
EOF
# read in original twig
my $origtwig=XML::Twig->new( twig_handlers => {
'about[!@id]' => sub { $_->set_att('id', 'ID123'); return 1; },
});
$origtwig->parse($xml);
# make a new twig and move contents over to it
my $bookmap = XML::Twig::Elt->new('bookmap');
my $newtwig=XML::Twig->new;
$newtwig->set_root($bookmap);
$bookmap->set_content($origtwig->root->cut_children);
#### broken ####
$bookmap->wrap_children('<about>', 'frontmatter');
#### broken ####
$newtwig->print(pretty_print => 'indented');