Types, classes & roles
The metaobject protocol .^
FullIntrospect types through their metaobject — MRO, parents, attributes, and signatures.
The .^ operator calls a metamethod — a method on a type's metaobject — to ask about its structure: its ancestors, attributes, and more.
Method resolution order — .^mro #
.^mro lists a type and its ancestors, in the order methods are resolved.
say Int.^mro.map(*.^name);
Output
(Int Cool Any Mu)Attributes — .^attributes #
.^attributes returns a class's attributes; .name gives each one's $!-twigil name.
class Point { has $.x; has $.y }
say Point.^attributes.map(*.name);
Output
($!x $!y)Introspecting a routine's signature #
&sub.signature.params returns the parameter objects, so you can inspect a routine's interface reflectively.
sub area($w, $h) {}
say &area.signature.params.map(*.name);
Output
($w $h)Notes #
.^name(the type's name) is fully supported — see The type tower & introspection;.^parentsgives the immediate superclasses..isatests strict class inheritance (5.isa(Numeric)isFalse, sinceNumericis a role) — use~~for role/type membership..^methodslists a type's methods; note it does not include the auto-generated bookkeeping methods (likePOPULATE) that Rakudo also surfaces — the user-declared ones are all there.