Metaobject that supports multiple inheritance
Warning: this role is part of the Rakudo implementation, and is not a part of the language specification.
Classes, roles and grammars can have parent classes, that is, classes to which method lookups fall back to, and to whose type the child class conforms to.
This role implements the capability of having zero, one or more parent (or super) classes.
In addition, it supports the notion of hidden classes, whose methods are excluded from the normal dispatching chain, so that for example nextsame
ignores it.
This can come in two flavors: methods from a class marked as is hidden
are generally excluded from dispatching chains, and class A hides B
adds B
as a parent class to A
, but hides it from the method resolution order, so that mro_unhidden skips it.
method add_parent(, , :)
Adds $parent
as a parent type. If $hides
is set to a true value, the parent type is added as a hidden parent.
$parent
must be a fully composed typed. Otherwise an exception of type X::Inheritance::NotComposed is thrown.
method parents(, :, :)
Returns the list of parent classes. By default it stops at Cool, Any or Mu, which you can suppress by supplying the :all
adverb. With :tree
, a nested list is returned.
;is D ;is D ;is C1 is C2 ;is B ;say A.^parents(:all).raku;# OUTPUT: «(B, C1, C2, D, Any, Mu)»say A.^parents(:all, :tree).raku;# OUTPUT: «[B, ([C1, [D, [Any, [Mu]]]], [C2, [D, [Any, [Mu]]]])]»
method hides()
Returns a list of all hidden parent classes.
method hidden()
Returns a true value if (and only if) the class is marked with the trait is hidden
.
method set_hidden()
Marks the type as hidden.