role Metamodel::ParametricRoleHOW
Represents a non-instantiated, parameterized, role.
does Metamodel::Namingdoes Metamodel::Documentingdoes Metamodel::Versioningdoes Metamodel::MethodContainerdoes Metamodel::PrivateMethodContainerdoes Metamodel::MultiMethodContainerdoes Metamodel::AttributeContainerdoes Metamodel::RoleContainerdoes Metamodel::MultipleInheritancedoes Metamodel::Stashingdoes Metamodel::TypePretensedoes Metamodel::RolePunningdoes Metamodel::ArrayType
Warning: this class is part of the Rakudo implementation, and is not a part of the language specification.
A Metamodel::ParametricRoleHOW
represents a non-instantiated, possibly parameterized, role:
([::T] ).HOW.say;# OUTPUT: «Perl6::Metamodel::ParametricRoleHOW.new»( ).HOW.say; # OUTPUT: «Perl6::Metamodel::ParametricRoleHOW.new»
As usual, .new_type
will create a new object of this class.
my \zipi := Metamodel::ParametricRoleHOW.new_type( name => "zape", group => "Zape");say zipi.HOW; # OUTPUT: «Perl6::Metamodel::ParametricRoleHOW.new»
The extra group
argument will need to be used to integrate it in a parametric role group, which will need to be defined in advance.
Note: As most of the Metamodel
classes, this one is here mainly for illustration purposes and it's not intended for the final user to instantiate, unless their intention is really to create a parametric role group.
Type Graph
Routines supplied by role Metamodel::Naming
Metamodel::ParametricRoleHOW does role Metamodel::Naming, which provides the following routines:
(Metamodel::Naming) method name
method name()
Returns the name of the metaobject, if any.
say 42.^name; # OUTPUT: «Int»
(Metamodel::Naming) method set_name
method set_name(, )
Sets the new name of the metaobject.
Routines supplied by role Metamodel::Documenting
Metamodel::ParametricRoleHOW does role Metamodel::Documenting, which provides the following routines:
(Metamodel::Documenting) method set_why
method set_why()
Sets the documentation for a type to $why
.
(Metamodel::Documenting) method WHY
method WHY()
Returns the documentation for a type.
Routines supplied by role Metamodel::Versioning
Metamodel::ParametricRoleHOW does role Metamodel::Versioning, which provides the following routines:
(Metamodel::Versioning) method ver
method ver()
Returns the version of the metaobject, if any, otherwise returns Mu.
(Metamodel::Versioning) method auth
method auth()
Returns the author of the metaobject, if any, otherwise returns an empty string.
(Metamodel::Versioning) method api
method api()
Returns the API of the metaobject, if any, otherwise returns an empty string.
(Metamodel::Versioning) method set_ver
method set_ver(, )
Sets the version of the metaobject.
(Metamodel::Versioning) method set_auth
method set_auth(, )
Sets the author of the metaobject.
(Metamodel::Versioning) method set_api
method set_api(, )
Sets the API of the metaobject.
Routines supplied by role Metamodel::MethodContainer
Metamodel::ParametricRoleHOW does role Metamodel::MethodContainer, which provides the following routines:
(Metamodel::MethodContainer) method add_method
method add_method(Metamodel::MethodContainer: , , )
Adds a method to the metaclass, to be called with name $name
. This should only be done before a type is composed.
(Metamodel::MethodContainer) method methods
method methods(Metamodel::MethodContainer: , :, :)
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.
(Metamodel::MethodContainer) method method_table
method method_table(Metamodel::MethodContainer: --> 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.
(Metamodel::MethodContainer) method lookup
method lookup(Metamodel::MethodContainer: , --> 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").perl: # OUTPUT: «method sqrt (Rat $: *%_) ...»say Str.^lookup("BUILD").perl; # OUTPUT: «submethod BUILD (Str $: :$value = "", *%_ --> Nil) ...»say Int.^lookup("does-not-exist"); # OUTPUT: «(Mu)»
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.
Routines supplied by role Metamodel::PrivateMethodContainer
Metamodel::ParametricRoleHOW does role Metamodel::PrivateMethodContainer, which provides the following routines:
(Metamodel::PrivateMethodContainer) method add_private_method
method add_private_method(Metamodel::PrivateMethodContainer: , , )
Adds a private method $code
with name $name
.
(Metamodel::PrivateMethodContainer) method private_method_table
method private_method_table(Metamodel::PrivateMethodContainer: )
Returns a hash of name => &method_object
Routines supplied by role Metamodel::AttributeContainer
Metamodel::ParametricRoleHOW does role Metamodel::AttributeContainer, which provides the following routines:
(Metamodel::AttributeContainer) method add_attribute
method add_attribute(Metamodel::AttributeContainer: , )
Adds an attribute. $attribute
must be an object that supports the methods name
, type
and package
, which are called without arguments. It can for example be of type Attribute.
(Metamodel::AttributeContainer) method attributes
method attributes(Metamodel::AttributeContainer: )
Returns a list of attributes. For most Raku types, these will be objects of type Attribute.
(Metamodel::AttributeContainer) method set_rw
method set_rw(Metamodel::AttributeContainer: )
Marks a type whose attributes default to having a write accessor. For example in
is rw
The 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;
(Metamodel::AttributeContainer) method rw
method rw(Metamodel::AttributeContainer: )
Returns a true value if method set_rw has been called on this object, that is, if new public attributes are writable by default.
Routines supplied by role Metamodel::RoleContainer
Metamodel::ParametricRoleHOW does role Metamodel::RoleContainer, which provides the following routines:
(Metamodel::RoleContainer) method add_role
method add_role(Metamodel::RoleContainer: , Mu )
Adds the $role
to the list of roles to be composed.
(Metamodel::RoleContainer) method roles_to_compose
method roles_to_compose(Metamodel::RoleContainer: --> List)
returns a list of roles added with add_role
, which are to be composed at type composition time.
Routines supplied by role Metamodel::MultipleInheritance
Metamodel::ParametricRoleHOW does role Metamodel::MultipleInheritance, which provides the following routines:
(Metamodel::MultipleInheritance) method add_parent
method add_parent(Metamodel::MultipleInheritance: , , :)
Adds $parent
as a parent type. If $hides
is set to a true value, the parent type is added as a hidden parent.
$parent
must be a fully composed typed. Otherwise an exception of type X::Inheritance::NotComposed is thrown.
(Metamodel::MultipleInheritance) method parents
method parents(Metamodel::MultipleInheritance: , :, :)
Returns the list of parent classes. By default it stops at Cool, Any or Mu, which you can suppress by supplying the :all
adverb. With :tree
, a nested list is returned.
;is D ;is D ;is C1 is C2 ;is B ;say A.^parents(:all).perl;# OUTPUT: «(B, C1, C2, D, Any, Mu)»say A.^parents(:all, :tree).perl;# OUTPUT: «[B, ([C1, [D, [Any, [Mu]]]], [C2, [D, [Any, [Mu]]]])]»
(Metamodel::MultipleInheritance) method hides
method hides(Metamodel::MultipleInheritance: )
Returns a list of all hidden parent classes.
(Metamodel::MultipleInheritance) method hidden
method hidden(Metamodel::MultipleInheritance: )
Returns a true value if (and only if) the class is marked with the trait is hidden
.
(Metamodel::MultipleInheritance) method set_hidden
method set_hidden(Metamodel::MultipleInheritance: )
Marks the type as hidden.
Routines supplied by role Metamodel::Stashing
Metamodel::ParametricRoleHOW does role Metamodel::Stashing, which provides the following routines:
(Metamodel::Stashing) method add_stash
method add_stash()
Creates and sets a stash for a type, returning $type_obj
.
This method is typically called as the last step of creating a new type. For example, this is how it would be used in a minimal HOW that only supports naming and stashing:
does Metamodel::Namingdoes Metamodel::Stashingmy Mu constant WithStash = WithStashHOW.new_type: :name<WithStash>;say WithStash.WHO; # OUTPUT: «WithStash»