develooper Front page | perl.perl5.porters | Postings from May 2008

Recursive inheritance detected while looking for method - Why

From:
Lyle
Date:
May 8, 2008 04:34
Subject:
Recursive inheritance detected while looking for method - Why
Message ID:
4821E1E0.6070001@cosmicperl.com
Trying out some object methods the other day I came across this error.

I'm wondering why this behaviour is possible. Forgive me if I don't 
illustrate this well as I'm not totally up with the correct lingo.

The way I see if you have:-

package a;
##base

package b
@ISA = qw( a );

package c
@ISA = qw( a );

package d
@ISA = qw( a );


This all runs smoothly. If you have an object of 'd' then it'll also 
look for methods in a then give up.
If you then update 'd' to also have 'c'.
push @ISA, 'c';

Looking for the objects method will first go to d, then a, then c, than 
needlessly back to a before it gives up.

If you then update 'd' to also have 'b'.
push @ISA, 'b';

Looking for the objects method will first go:-
d, a, c, a, b, a
And so on with needless re-checks in packages it's already been too.

Of course if you set 'a' ISA 'b', then it's going to go into an infinate 
loop and you'll get the "Recursive inheritance detected while looking 
for method" error.


What I don't understand is.. and forgive me if I'm missing something.. 
why doesn't the method lookup for an object remember which packages it's 
already been to and no recheck them. In the examples above wouldn't this 
be quicker? It would also allow recursive inheritance, which I'm 
guessing is a bad thing, but could be useful in places.


Lyle




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About