Subject: | Multiple inheritance fails randomly |
Date: | Wed, 05 Nov 2008 12:11:15 +0100 |
To: | bug-Exception-Class [...] rt.cpan.org. |
From: | Peter Mogensen <apm [...] one.com> |
I experience this error:
Using
Exception::Class 1.23
perl 5.8.8
Debian Edge/Ubuntu Hardy
With an hierarchy where an exception class has more than one parent this
code in Class.pm sub _make_parent fails:
====================================
foreach my $c ( @{ $needs->{$subclass}{parents} } )
{
# It's been made
next if $CLASSES{$c} || keys %{"$c\::"};
die "There appears to be some circularity involving $subclass\n"
if $seen->{$subclass};
$seen->{$subclass} = 1;
$class->_make_parents( $needs, $c, $seen, $subclass );
}
=====================================
Which (when you look at it long enough) is obvious since it will never
be able to run through that loop more than once with undefined parents.
The second time $seen->{$subclass} has been set and it will die.
So you can never have a class with more than one uninstantiated parent
at that point.... which seems to be random determined by the keys operator.
At least on my perl installation this will reproduce the error:
=====================================
use Exception::Class (
'RootEx' => {},
'AEx' =>
{ isa => 'RootEx' },
'BEx' =>
{ isa => 'RootEx' },
'ABEx' =>
{ isa => ['AEx','BEx'] },
'AB1Ex' =>
{ isa => 'ABEx' },
'AB2Ex' =>
{ isa => 'ABEx' },
'X1Ex' =>
{ isa => 'BEx'},
'XL1Ex' =>
{ isa => ['X1Ex', 'AB1Ex']},
);
=====================================
The solution might be to just move the "die" statement out just before
the foreach loop.
/Peter