In Perl5 and Moose, linear isa or linearized isa helps make sense of class hierarchies.
The method WHAT shows the concrete type of a value:
> 42.WHAT
(Int)
How do I show something like
> 42.hypothetical-type-hierarchy
(Int) ┬ is (Cool) ─ is (Any) ─ is (Mu)
└ does (Real) ─ does (Numeric)
… possibly with further lines for each consumed role?
edit: example with two strands of roles
class Beta {}
role Delta {}
role Gamma does Delta {}
role Eta {}
role Zeta does Eta {}
role Epsilon does Zeta {}
class Alpha is Beta does Gamma does Epsilon {}
# (Alpha) ┬ is (Beta)
# ├ does (Gamma) ─ does (Delta)
# └ does (Epsilon) ─ does (Zeta) ─ does (Eta)
my $ai = Alpha.new
$ai.^mro # ((Alpha) (Beta) (Any) (Mu))
$ai.^roles # ((Epsilon) (Zeta) (Eta) (Gamma) (Delta))
# flat list, not two-element list of a tuple and triple‽
You can query the meta object with
where
mro
stand for method resolution order andYou can control which roles are returned via the adverbs
:local
(exlude roles inherited from parent classes - only available on classes) and:!transitive
(exclude roles composed via another role - available on both roles and classes).The following should get you started:
Given your example code with slight modifications
it produces the output