Subject: | HTML::Element broken when passing a subclassed object to new_from_lol |
If you subclass HTML::Element, and then pass an object of the subclass
to new_from_lol (or push_content) inside an ARRAYREF, it crashes out with
Can't use string ("1") as a HASH ref while "strict refs" in use at
/usr/lib/perl5/site_perl/5.8.5/HTML/Element.pm line 905.
The problem is that line 3393 (in the anonymous sub inside new_from_lol)
it claims unowned elements by setting their _parent property to 1,
relying on line 3413 to correct this illegal situation.
But 3413 is inside the condition "if($class eq __PACKAGE__)" - so if the
element is not of class HTML::Element, but a derived class, it misses
this code and leaves the invalid '1' in the parent properties.
Example code:
#! /usr/bin/perl -w
use HTML::Element;
my $div1 = new HTML::Element('div');
$div1->push_content('Contents of div1');
my $mydiv = new MyElement('div');
$mydiv->push_content(
['div', $div1]
);
package MyElement;
use base 'HTML::Element';
sub new
{
my $invoker = shift;
my $class = ref $invoker || $invoker;
return $class->SUPER::new(@_);
}
=====================================================
It seems to me that a fix is to replace line 3418
$node->push_content(@children) if @children;
by
$node->push_content(
map {$_->{'_parent'} = $node if ref $_; $_} @children) if @children;
[Fedora 7, Perl 5.8.5, but I don't believe these are relevant]
Colin Fine
Engineering Tools Group
Pace plc