role Metamodel::MethodContainer { }
Warning : this role is part of the Rakudo implementation, and is not a part of the language specification.
Roles, classes, grammars and enums can contain methods. This role implements the API around storing and introspecting them.
say . name for Int . ^ methods ( : all );
Int . ^ add_method ( ' double ' , method ( $ x : ) { 2 * $ x } );
say 21 . double ;
method add_method ( $ obj , $ name , $ code )
Adds a method to the metaclass, to be called with name $name
. This should only be done before a type is composed.
method methods ( $ obj , : $ all , : $ local )
Returns a list of public methods available on the class (which includes methods from superclasses and roles). By default this stops at the classes Cool , Any or Mu ; to really get all methods, use the :all
adverb. If :local
is set, only methods declared directly in the class are returned.
class A {
method x () { } ;
}
say A . ^ methods ();
say A . ^ methods ( : all );
The returned list contains objects of type Method , which you can use to introspect their signatures and call them.
Some introspection method-look-alikes like WHAT
will not show up, although they are present in any Raku object. They are handled at the grammar level and will likely remain so for bootstrap reasons.
method method_table ( $ obj --> Hash : D )
Returns a hash where the keys are method names, and the values are methods . Note that the keys are the names by which the methods can be called, not necessarily the names by which the methods know themselves.
method lookup ( $ obj , $ name --> Method )
Returns the first matching method object of the provided $name
or (Mu)
if no method object was found. The search for a matching method object is done by following the mro of $obj
. Note that lookup
is supposed to be used for introspection, if you're after something which can be invoked you probably want to use find_method instead.
say 2.5 . ^ lookup ( " sqrt " ) . raku ;
say Str . ^ lookup ( " BUILD " ) . raku ;
say Int . ^ lookup ( " does-not-exist " );
The difference between find_method
and lookup
are that find_method
will use a default candidate for parametric roles, whereas lookup
throws an exception in this case, and that find_method
honors FALLBACK
methods, which lookup
does not.
Type relations for Metamodel::MethodContainer
perl6-type-graph
Metamodel::MethodContainer
Metamodel::MethodContainer
Mu
Mu
Any
Any
Any->Mu
Metamodel::Naming
Metamodel::Naming
Metamodel::Versioning
Metamodel::Versioning
Metamodel::PrivateMethodContainer
Metamodel::PrivateMethodContainer
Metamodel::MultiMethodContainer
Metamodel::MultiMethodContainer
Metamodel::AttributeContainer
Metamodel::AttributeContainer
Metamodel::RoleContainer
Metamodel::RoleContainer
Metamodel::MultipleInheritance
Metamodel::MultipleInheritance
Metamodel::ConcreteRoleHOW
Metamodel::ConcreteRoleHOW
Metamodel::ConcreteRoleHOW->Metamodel::MethodContainer
Metamodel::ConcreteRoleHOW->Any
Metamodel::ConcreteRoleHOW->Metamodel::Naming
Metamodel::ConcreteRoleHOW->Metamodel::Versioning
Metamodel::ConcreteRoleHOW->Metamodel::PrivateMethodContainer
Metamodel::ConcreteRoleHOW->Metamodel::MultiMethodContainer
Metamodel::ConcreteRoleHOW->Metamodel::AttributeContainer
Metamodel::ConcreteRoleHOW->Metamodel::RoleContainer
Metamodel::ConcreteRoleHOW->Metamodel::MultipleInheritance
Metamodel::Documenting
Metamodel::Documenting
Metamodel::Stashing
Metamodel::Stashing
Metamodel::Finalization
Metamodel::Finalization
Metamodel::DefaultParent
Metamodel::DefaultParent
Metamodel::C3MRO
Metamodel::C3MRO
Metamodel::MROBasedMethodDispatch
Metamodel::MROBasedMethodDispatch
Metamodel::MROBasedTypeChecking
Metamodel::MROBasedTypeChecking
Metamodel::Trusting
Metamodel::Trusting
Metamodel::BUILDPLAN
Metamodel::BUILDPLAN
Metamodel::Mixins
Metamodel::Mixins
Metamodel::BoolificationProtocol
Metamodel::BoolificationProtocol
Metamodel::ClassHOW
Metamodel::ClassHOW
Metamodel::ClassHOW->Metamodel::MethodContainer
Metamodel::ClassHOW->Any
Metamodel::ClassHOW->Metamodel::Naming
Metamodel::ClassHOW->Metamodel::Versioning
Metamodel::ClassHOW->Metamodel::PrivateMethodContainer
Metamodel::ClassHOW->Metamodel::MultiMethodContainer
Metamodel::ClassHOW->Metamodel::AttributeContainer
Metamodel::ClassHOW->Metamodel::RoleContainer
Metamodel::ClassHOW->Metamodel::MultipleInheritance
Metamodel::ClassHOW->Metamodel::Documenting
Metamodel::ClassHOW->Metamodel::Stashing
Metamodel::ClassHOW->Metamodel::Finalization
Metamodel::ClassHOW->Metamodel::DefaultParent
Metamodel::ClassHOW->Metamodel::C3MRO
Metamodel::ClassHOW->Metamodel::MROBasedMethodDispatch
Metamodel::ClassHOW->Metamodel::MROBasedTypeChecking
Metamodel::ClassHOW->Metamodel::Trusting
Metamodel::ClassHOW->Metamodel::BUILDPLAN
Metamodel::ClassHOW->Metamodel::Mixins
Metamodel::ClassHOW->Metamodel::BoolificationProtocol
Metamodel::BaseType
Metamodel::BaseType
Metamodel::EnumHOW
Metamodel::EnumHOW
Metamodel::EnumHOW->Metamodel::MethodContainer
Metamodel::EnumHOW->Any
Metamodel::EnumHOW->Metamodel::Naming
Metamodel::EnumHOW->Metamodel::MultiMethodContainer
Metamodel::EnumHOW->Metamodel::AttributeContainer
Metamodel::EnumHOW->Metamodel::RoleContainer
Metamodel::EnumHOW->Metamodel::Stashing
Metamodel::EnumHOW->Metamodel::MROBasedMethodDispatch
Metamodel::EnumHOW->Metamodel::MROBasedTypeChecking
Metamodel::EnumHOW->Metamodel::BUILDPLAN
Metamodel::EnumHOW->Metamodel::Mixins
Metamodel::EnumHOW->Metamodel::BoolificationProtocol
Metamodel::EnumHOW->Metamodel::BaseType
Metamodel::TypePretense
Metamodel::TypePretense
Metamodel::RolePunning
Metamodel::RolePunning
Metamodel::ParametricRoleHOW
Metamodel::ParametricRoleHOW
Metamodel::ParametricRoleHOW->Metamodel::MethodContainer
Metamodel::ParametricRoleHOW->Any
Metamodel::ParametricRoleHOW->Metamodel::Naming
Metamodel::ParametricRoleHOW->Metamodel::Versioning
Metamodel::ParametricRoleHOW->Metamodel::PrivateMethodContainer
Metamodel::ParametricRoleHOW->Metamodel::MultiMethodContainer
Metamodel::ParametricRoleHOW->Metamodel::AttributeContainer
Metamodel::ParametricRoleHOW->Metamodel::RoleContainer
Metamodel::ParametricRoleHOW->Metamodel::MultipleInheritance
Metamodel::ParametricRoleHOW->Metamodel::Documenting
Metamodel::ParametricRoleHOW->Metamodel::Stashing
Metamodel::ParametricRoleHOW->Metamodel::TypePretense
Metamodel::ParametricRoleHOW->Metamodel::RolePunning
Expand above chart