Provides an implementation of a concrete instance of a role
does Metamodel::Namingdoes Metamodel::Versioningdoes Metamodel::PrivateMethodContainerdoes Metamodel::MethodContainerdoes Metamodel::MultiMethodContainerdoes Metamodel::AttributeContainerdoes Metamodel::RoleContainerdoes Metamodel::MultipleInheritancedoes Metamodel::ArrayTypedoes Metamodel::Concretization
Warning: this class is part of the Rakudo implementation, and is not a part of the language specification.
You can use this to build roles, in the same way that
ClassHOW can be used to build classes:
my = Metamodel::ConcreteRoleHOW.new_type(name => "Bar");.^compose;say .^roles; # OUTPUT: «(Mu)␤»
The main difference with
ClassHOW.new_type is that you can mix-in roles in this newly created one.
This class is Rakudo specific, and provided only for completeness. Not really intended to be used by the final user.
Metamodel::ConcreteRoleHOW does role Metamodel::Naming, which provides the following routines:
Returns the name of the metaobject, if any.
say 42.^name; # OUTPUT: «Int␤»
method set_name(, )
Sets the new name of the metaobject.
Metamodel::ConcreteRoleHOW does role Metamodel::Versioning, which provides the following routines:
Returns the version of the metaobject, if any, otherwise returns Mu.
Returns the author of the metaobject, if any, otherwise returns an empty string.
Returns the API of the metaobject, if any, otherwise returns an empty string.
method set_ver(, )
Sets the version of the metaobject.
method set_auth(, )
Sets the author of the metaobject.
method set_api(, )
Sets the API of the metaobject.
Metamodel::ConcreteRoleHOW does role Metamodel::PrivateMethodContainer, which provides the following routines:
method add_private_method(, , )
Adds a private method
$code with name
Returns a hash of
name => &method_object
Returns a list of private method names.
method find_private_method(, )
Locates a private method. Otherwise, returns
Mu if it doesn't exist.
Metamodel::ConcreteRoleHOW does role Metamodel::MethodContainer, which provides the following routines:
method add_method(, , )
Adds a method to the metaclass, to be called with name
$name. This should only be done before a type is composed.
method methods(, :, :)
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.
say A.^methods(); # xsay A.^methods(:all); # x infinite defined ...
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( --> Hash)
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(, --> Method)
Returns the first matching method object of the provided
(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; # OUTPUT: «method sqrt (Rat $: *%_) ...␤»say Str.^lookup("BUILD").raku; # OUTPUT: «submethod BUILD (Str $: :$value = "", *%_ --> Nil) ...␤»say Int.^lookup("does-not-exist"); # OUTPUT: «(Mu)␤»
The difference between
lookup are that
find_method will use a default candidate for parametric roles, whereas
lookup throws an exception in this case, and that
FALLBACK methods, which
lookup does not.
Metamodel::ConcreteRoleHOW does role Metamodel::AttributeContainer, which provides the following routines:
method add_attribute(, )
Adds an attribute.
$attribute must be an object that supports the methods
package, which are called without arguments. It can for example be of type Attribute.
Returns a list of attributes. For most Raku types, these will be objects of type Attribute.
Marks a type whose attributes default to having a write accessor. For example in
is rw trait on the class calls the
set_rw method on the metaclass, making all the attributes implicitly writable, so that you can write;
my = Point.new(x => 1, y => 2);.x = 42;
Returns a true value if method set_rw has been called on this object, that is, if new public attributes are writable by default.
Metamodel::ConcreteRoleHOW does role Metamodel::RoleContainer, which provides the following routines:
method add_role(, Mu )
$role to the list of roles to be composed.
method roles_to_compose( --> List)
returns a list of roles added with
add_role, which are to be composed at type composition time.
Metamodel::ConcreteRoleHOW does role Metamodel::MultipleInheritance, which provides the following routines:
method add_parent(, , :)
$parent as a parent type. If
$hides is set to a true value, the parent type is added as a hidden parent.
method parents(, :, :)
;is D ;is D ;is C1 is C2 ;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]]]])]␤»
Returns a list of all hidden parent classes.
Returns a true value if (and only if) the class is marked with the trait
Marks the type as hidden.