role Metamodel::C3MRO

Metaobject that supports the C3 method resolution order

role Metamodel::C3MRO { }

Warning: this role is part of the Rakudo implementation, and is not a part of the language specification.

Metamodel role for the C3 method resolution order (MRO). Note: this method, along with almost the whole metamodel, is part of the Rakudo implementation.

The method resolution order for a type is a flat list of types including the type itself, and (recursively) all super classes. It determines in which order the types will be visited for determining which method to call with a given name, or for finding the next method in a chain with nextsame, callsame, nextwith or callwith.

class CommonAncestor { };   # implicitly inherits from Any 
class Child1 is CommonAncestor { }
class Child2 is CommonAncestor { }
class GrandChild2 is Child2 { }
class Weird is Child1 is GrandChild2 { };
 
say Weird.^mro# OUTPUT: «(Weird) (Child1) (GrandChild2) (Child2) (CommonAncestor) (Any) (Mu)␤» 

C3 is the default resolution order for classes and grammars in Raku. Note that roles generally do not appear in the method resolution order (unless they are punned into a class, from which another type inherits), because methods are copied into classes at role application time.

Methods

method compute_mro

method compute_mro($type)

Computes the method resolution order.

method mro

method mro($type)

Returns a list of types in the method resolution order, even those that are marked is hidden.

say Int.^mro;   # OUTPUT: «((Int) (Cool) (Any) (Mu))␤»

method mro_unhidden

method mro_unhidden($type)

Returns a list of types in method resolution order, excluding those that are marked with is hidden.

Type Graph

Type relations for Metamodel::C3MRO
perl6-type-graph Metamodel::C3MRO Metamodel::C3MRO Mu Mu Any Any Any->Mu Metamodel::Naming Metamodel::Naming Metamodel::Documenting Metamodel::Documenting Metamodel::Versioning Metamodel::Versioning Metamodel::Stashing Metamodel::Stashing Metamodel::MultipleInheritance Metamodel::MultipleInheritance Metamodel::MROBasedMethodDispatch Metamodel::MROBasedMethodDispatch Metamodel::MROBasedTypeChecking Metamodel::MROBasedTypeChecking Metamodel::NativeHOW Metamodel::NativeHOW Metamodel::NativeHOW->Metamodel::C3MRO Metamodel::NativeHOW->Any Metamodel::NativeHOW->Metamodel::Naming Metamodel::NativeHOW->Metamodel::Documenting Metamodel::NativeHOW->Metamodel::Versioning Metamodel::NativeHOW->Metamodel::Stashing Metamodel::NativeHOW->Metamodel::MultipleInheritance Metamodel::NativeHOW->Metamodel::MROBasedMethodDispatch Metamodel::NativeHOW->Metamodel::MROBasedTypeChecking Metamodel::AttributeContainer Metamodel::AttributeContainer Metamodel::Finalization Metamodel::Finalization Metamodel::MethodContainer Metamodel::MethodContainer Metamodel::PrivateMethodContainer Metamodel::PrivateMethodContainer Metamodel::MultiMethodContainer Metamodel::MultiMethodContainer Metamodel::RoleContainer Metamodel::RoleContainer Metamodel::DefaultParent Metamodel::DefaultParent Metamodel::Trusting Metamodel::Trusting Metamodel::BUILDPLAN Metamodel::BUILDPLAN Metamodel::Mixins Metamodel::Mixins Metamodel::BoolificationProtocol Metamodel::BoolificationProtocol Metamodel::ClassHOW Metamodel::ClassHOW Metamodel::ClassHOW->Metamodel::C3MRO Metamodel::ClassHOW->Any Metamodel::ClassHOW->Metamodel::Naming Metamodel::ClassHOW->Metamodel::Documenting Metamodel::ClassHOW->Metamodel::Versioning Metamodel::ClassHOW->Metamodel::Stashing Metamodel::ClassHOW->Metamodel::MultipleInheritance Metamodel::ClassHOW->Metamodel::MROBasedMethodDispatch Metamodel::ClassHOW->Metamodel::MROBasedTypeChecking Metamodel::ClassHOW->Metamodel::AttributeContainer Metamodel::ClassHOW->Metamodel::Finalization Metamodel::ClassHOW->Metamodel::MethodContainer Metamodel::ClassHOW->Metamodel::PrivateMethodContainer Metamodel::ClassHOW->Metamodel::MultiMethodContainer Metamodel::ClassHOW->Metamodel::RoleContainer Metamodel::ClassHOW->Metamodel::DefaultParent Metamodel::ClassHOW->Metamodel::Trusting Metamodel::ClassHOW->Metamodel::BUILDPLAN Metamodel::ClassHOW->Metamodel::Mixins Metamodel::ClassHOW->Metamodel::BoolificationProtocol

Expand above chart