role Metamodel::MultipleInheritance {}

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.

Methods§

method add_parent§

method add_parent($obj$parent:$hides)

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§

method ^parents($obj:$all:$tree)

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.

class D { };
class C1 is D { };
class C2 is D { };
class B is C1 is C2 { };
class A 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§

method hides($obj)

Returns a list of all hidden parent classes.

method hidden§

method hidden($obj)

Returns a true value if (and only if) the class is marked with the trait is hidden.

method set_hidden§

method set_hidden($obj)

Marks the type as hidden.