class Metamodel::EnumHOW
Metaobject representing a Perl 6 enum.
does Metamodel::Namingdoes Metamodel::Documentingdoes Metamodel::Stashingdoes Metamodel::AttributeContainerdoes Metamodel::MethodContainerdoes Metamodel::MultiMethodContainerdoes Metamodel::RoleContainerdoes Metamodel::BaseTypedoes Metamodel::MROBasedMethodDispatchdoes Metamodel::MROBasedTypeCheckingdoes Metamodel::BUILDPLANdoes Metamodel::BoolificationProtocoldoes Metamodel::REPRComposeProtocoldoes Metamodel::InvocationProtocoldoes Metamodel::Mixins
Metamodel::EnumHOW
is the meta class behind the enum
keyword.
<1 2>;say numbers.HOW ~~ Metamodel::EnumHOW # OUTPUT: «True»
Warning: This class is part of the Rakudo implementation, and is not a part of the language specification.
Methods
method add_enum_value
method add_enum_value(Metamodel::ClassHOW: , )
Adds a value to this enum.
method enum_values
method enum_values(Metamodel::ClassHOW: )
Returns the values for the enum.
<10 20>;say numbers.^enum_values; # OUTPUT: {10 => 0, 20 => 1}
method elems
method elems(Metamodel::ClassHOW: )
Returns the number of values.
<10 20>;say numbers.^elems; # OUTPUT: 2
method enum_from_value
method enum_from_value(Metamodel::ClassHOW: , )
Given a numeric value, return the corresponding enum.
<10 20>;say numbers.^enum_from_value(0) # OUTPUT: 10
method enum_value_list
method enum_value_list(Metamodel::ClassHOW: )
Returns a list of the enum values.
<10 20>;say numbers.^enum_value_list; # OUTPUT: (10 20)
Type Graph
Metamodel::EnumHOW
Routines supplied by role Metamodel::Naming
Metamodel::EnumHOW does role Metamodel::Naming, which provides the following routines:
(Metamodel::Naming) method name
method name()
Returns the name of the meta object, if any.
say 42.^name; # OUTPUT: «Int»
(Metamodel::Naming) method set_name
method set_name(, )
Sets the new name of the meta object.
Routines supplied by role Metamodel::AttributeContainer
Metamodel::EnumHOW 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 Perl 6 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 meta class, 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::MethodContainer
Metamodel::EnumHOW does role Metamodel::MethodContainer, which provides the following routines:
(Metamodel::MethodContainer) method add_method
method add_method(Metamodel::MethodContainer: , , )
Adds a method to the meta class, 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 Perl 6 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)»
Routines supplied by role Metamodel::RoleContainer
Metamodel::EnumHOW 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::MROBasedMethodDispatch
Metamodel::EnumHOW does role Metamodel::MROBasedMethodDispatch, which provides the following routines:
(Metamodel::MROBasedMethodDispatch) method find_method
method find_method(, , , *)
Given a method name, it returns the method object of that name which is closest in the method resolution order (MRO). If no method can be found, it returns a VM-specific sentinel value (typically a low-level NULL value) that can be tested for with a test for definedness:
for <upper-case uc># OUTPUT:# method `upper-case` not found# FOO
If :no_fallback
is supplied, fallback methods are not considered.
(Metamodel::MROBasedMethodDispatch) method find_method_qualified
method find_method_qualified(, , )
Given a method name and a type, returns the method from that type. This is used in calls like
self.SomeParentClass::the_method();
(Metamodel::MROBasedMethodDispatch) method can
can(, )
Returns the list of methods of that name the object can do.
(Metamodel::MROBasedMethodDispatch) method publish_method_cache
Defined as:
method publish_method_cache()
Walk MRO and add methods to cache, unless another method lower in the class hierarchy "shadowed" it.