I am extending XML::Twig::Elt by defining a twig with the elt_class option. When I use the parse() method of the extended class, the new elements are of the base class (XML::Twig::Elt) and the extended methods are not known:
====
Can't locate object method "get_refs_to" via package "XML::Twig::Elt" at ./x.pl line 11.
====
The culprit appears to be that the temporary twig used internally by parse() does not inherit the elt_class.
Sample testcase attached.
#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig;
import myelt;
my $root = XML::Twig->new(elt_class => 'my_elt')->parse('<grammar/>')->root;
$root->get_refs_to('foo'); ## this succeeds
my $div = XML::Twig::Elt->parse('<div/>')->insert('last_child', $root);
$div->get_refs_to('foo'); ## this fails
package my_elt;
use XML::Twig;
use base 'XML::Twig::Elt';
sub get_refs_to {
my ($elt, $name) = @_;
return $elt->descendants("ref[\@name='$name']"); ## what this does is not important
}