在 Perl5 和 Moose 中,线性 isa或线性化 isa有助于理解类层次结构。
方法WHAT显示了值的具体类型:
> 42.WHAT
(Int)
我如何显示类似的东西
> 42.hypothetical-type-hierarchy
(Int) ┬ is (Cool) ─ is (Any) ─ is (Mu)
└ does (Real) ─ does (Numeric)
… 可能为每个消费角色添加更多台词?
编辑:具有两个角色的示例
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‽