Types, classes & roles

The metaobject protocol .^

Full

Introspect 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 #