yngwi has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I've been trying to search for a solution to this for days; any help would be appreciated. Basically, I have a series of classes inheriting from each other, for example, class B is a subclass of class A, and class C is a subclass of class B.
There is an A->source() method defined, which may be overridden in class B. Now in a separate method defined in class A, say:
sub readsource { my $Class = shift; ... $Class->source(); }
So in this method I would like to know in which class the call to $Class->source() will find the source() method.
That is, if source() is not overridden in class B, then calling C->readsource() should know that it accesses A->source() when it calls C->source(). But if source() is overridden, then it should know that it uses B->source().
I would use this information in readsource() to create a new method in the class where I've found source(), a bit like what happens in Class::Data::Inheritable (which appears to use closures to remember where the accessor was defined).
Is there a way to do this without manually parsing the @ISA of all the classes involved?
|
---|