Skip Menu |

This queue is for tickets about the XML-Twig CPAN distribution.

Report information
The Basics
Id: 129022
Status: new
Priority: 0/
Queue: XML-Twig

People
Owner: Nobody in particular
Requestors: chrispitude [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: XML::Twig::Elt->parse does not work when extended with elt_class
From: chrispitude [...] gmail.com
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.
Subject: x.pl
#!/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 }
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.
Subject: x.pl
#!/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 }