Is there a standard CPAN way of finding out all the superclasses of a Perl class (or better yet entire superclass tree, up to UNIVERSAL)?
Or is the best practice to simply examine @{"${$class}::ISA"}
for each class, class's parents etc...?
Is there a standard CPAN way of finding out all the superclasses of a Perl class (or better yet entire superclass tree, up to UNIVERSAL)?
Or is the best practice to simply examine @{"${$class}::ISA"}
for each class, class's parents etc...?
There is no "standard way" because this is not a standard thing you want to do. For anything other than visualization it is an OO red flag to want to inspect your inheritance tree.
In addition to Class::ISA, there is mro::get_linear_isa(). Both have been in core for a while so they could be considered "standard" for some definition. Both of those show inheritance as a flat list, not a tree, which is useful mostly for deep magic.
The perl5i meta object provides both linear_isa(), like mro (it just calls mro), and ISA() which returns the class'
@ISA
. It can be used to construct a tree using simple recursion without getting into symbol tables.I think Class::ISA is something like you are looking for
Prints:
However, it's not some kind of "best practice" since the whole task isn't something Perl programmers do every day.
Most likely these days you want to use one of the functions from
mro
, such asmro::get_linear_isa
.I don't believe that there is something like a "standard CPAN way". Examining
@ISA
is common practice - and also plausible, since techniques likeuse base qw(...)
anduse parent -norequire, ...
also operate on top of@ISA
...