Fetching contributors…
Cannot retrieve contributors at this time
60 lines (39 sloc) 1.78 KB
=begin pod
=TITLE role Metamodel::C3MRO
=SUBTITLE Metaobject that supports the C3 method resolution order
role Metamodel::C3MRO { }
L<Meta model|/language/mop> role for the L<I<C3> method resolution order (MRO)|>.
The I<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
L<nextwith|/language/functions#sub_nextwith> or
=begin code
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)␤»
=end code
C3 is the default resolution order for classes and grammars in Perl 6.
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.
=head1 Methods
=head2 compute_mro
method compute_mro($type)
Computes the method resolution order.
=head2 mro
method mro($type)
Returns a list of types in the method resolution order, even those that are
marked C<is hidden>.
say Int.^mro; # OUTPUT: «((Int) (Cool) (Any) (Mu))␤»
=head2 mro_unhidden
method mro_unhidden($type)
Returns a list of types in method resolution order, excluding those that are
marked with C<is hidden>.
=end pod