How can I discover all the roles a Perl 6 type does?

  • A+
Category:Languages

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)) 

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])) 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: