role Metamodel::MethodDelegation

Metarole for delegating method dispatch
role Metamodel::MethodDelegation { }

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

Methods of Any and Mu can be invoked on roles, despite them not actually having these types as parents:

role Role { }

say Role.raku;                             # OUTPUT: «Role␤»
say Role.^pun.^parents(:all).map(*.^name); # OUTPUT: «()␤»

Metamodel::MethodDelegation is the metarole responsible for this behavior. Using the metamethods this provides, metaobjects can delegate method dispatch to another type object. This can be useful when implementing types that shouldn't store methods of their own through Metamodel::MethodContainer, but should still support method dispatch somehow.

All this metarole does is provide an interface for storing a type object to delegate methods to and provide a default find_method method for delegating method lookups to that type object if no other method lookup behavior for it exists; any other behavior related to methods is left up to the metaclasses that do this metarole to implement themselves.

Because method delegation is a property of the metaclass for a HOW, not HOWs themselves, the delegate_methods_to and delegating_methods_to metamethods this metarole provides must be invoked directly through a metaclass or HOW, not with .^ syntax:

say Role.HOW.delegating_methods_to.^name; # OUTPUT: «Any␤»

This metarole is commonly used in combination with Metamodel::TypePretense.

Methods

method delegate_methods_to

method delegate_methods_to($type)

Delegates methods to $type. This should be a type object, but may be any object with a find_method metamethod technically.

method delegating_methods_to

method delegating_methods_to()

Returns the type object a metaobject is delegating methods to.

method find_method

method find_method($obj, $name)

Looks up a method on the type object this metaobject is delegating method dispatch to.

See Also

role Metamodel::AttributeContainer

Metaobject that can hold attributes

role Metamodel::C3MRO

Metaobject that supports the C3 method resolution order

role Metamodel::Documenting

Metarole for documenting types.

role Metamodel::Finalization

Metaobject supporting object finalization

role Metamodel::MethodContainer

Metaobject that supports storing and introspecting methods

role Metamodel::Mixins

Metaobject for generating mixins

role Metamodel::MROBasedMethodDispatch

Metaobject that supports resolving inherited methods

role Metamodel::MultipleInheritance

Metaobject that supports multiple inheritance

role Metamodel::Naming

Metaobject that supports named types

role Metamodel::ParametricRoleGroupHOW

Represents a group of roles with different parameterizations

role Metamodel::ParametricRoleHOW

Represents a non-instantiated, parameterized, role.

role Metamodel::PrivateMethodContainer

Metaobject that supports private methods

role Metamodel::RoleContainer

Metaobject that supports holding/containing roles

role Metamodel::RolePunning

Metaobject that supports punning of roles.

role Metamodel::Stashing

Metarole for type stashes

role Metamodel::Trusting

Metaobject that supports trust relations between types

role Metamodel::TypePretense

Metarole for type pretenses

role Metamodel::Versioning

Metaobjects that support versioning

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.