如何发现Perl 6类型的所有角色? [英] How can I discover all the roles a Perl 6 type does?
本文介绍了如何发现Perl 6类型的所有角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用.does
,我可以检查某个类型是否具有我已经知道的角色.我想获取角色列表.继承具有.^mro
,但对于元模型中的角色,我没有看到类似的内容.
With .does
I can check if a type has the role I already know. I'd like to get the list of roles. Inheritance has .^mro
but I didn't see anything like that for roles in the meta model stuff.
此外,给定一个类型",如何确定它是定义为类还是角色?
Along with that, given a "type", how can I tell if it was defined as a class or a role?
推荐答案
.^roles
say Rat.^roles; # ((Rational[Int,Int]) (Real) (Numeric))
默认情况下,它包括每个角色,包括其他角色带来的角色.要只获得第一级,请使用:!transitive
By default it includes every role, including roles brought in by other roles. To only get the first level use :!transitive
Rat.^roles(:!transitive); # ((Rational[Int,Int]))
这篇关于如何发现Perl 6类型的所有角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文