role Metamodel::ConcreteRoleHOW

Provides an implementation of a concrete instance of a role

class Metamodel::ConcreteRoleHOW
    does Metamodel::Naming
    does Metamodel::Versioning
    does Metamodel::PrivateMethodContainer
    does Metamodel::MethodContainer
    does Metamodel::MultiMethodContainer
    does Metamodel::AttributeContainer
    does Metamodel::RoleContainer
    does Metamodel::MultipleInheritance
    does Metamodel::ArrayType
    does Metamodel::Concretization {}

You can use this to build roles, in the same way that ClassHOW can be used to build classes:

my $a = Metamodel::ConcreteRoleHOW.new_type(name => "Bar");
$a.^compose;
say $a.^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.

Type Graph

Type relations for Metamodel::ConcreteRoleHOW
perl6-type-graph Metamodel::ConcreteRoleHOW Metamodel::ConcreteRoleHOW Any Any Metamodel::ConcreteRoleHOW->Any Metamodel::Naming Metamodel::Naming Metamodel::ConcreteRoleHOW->Metamodel::Naming Metamodel::Versioning Metamodel::Versioning Metamodel::ConcreteRoleHOW->Metamodel::Versioning Metamodel::PrivateMethodContainer Metamodel::PrivateMethodContainer Metamodel::ConcreteRoleHOW->Metamodel::PrivateMethodContainer Metamodel::MethodContainer Metamodel::MethodContainer Metamodel::ConcreteRoleHOW->Metamodel::MethodContainer Metamodel::MultiMethodContainer Metamodel::MultiMethodContainer Metamodel::ConcreteRoleHOW->Metamodel::MultiMethodContainer Metamodel::AttributeContainer Metamodel::AttributeContainer Metamodel::ConcreteRoleHOW->Metamodel::AttributeContainer Metamodel::RoleContainer Metamodel::RoleContainer Metamodel::ConcreteRoleHOW->Metamodel::RoleContainer Metamodel::MultipleInheritance Metamodel::MultipleInheritance Metamodel::ConcreteRoleHOW->Metamodel::MultipleInheritance Mu Mu Any->Mu

Expand above chart

Routines supplied by role Metamodel::Naming

Metamodel::ConcreteRoleHOW does role Metamodel::Naming, which provides the following routines:

(Metamodel::Naming) method name

method name($type)

Returns the name of the metaobject, if any.

say 42.^name;       # OUTPUT: «Int␤»

(Metamodel::Naming) method set_name

method set_name($type$new_name)

Sets the new name of the metaobject.

Routines supplied by role Metamodel::Versioning

Metamodel::ConcreteRoleHOW does role Metamodel::Versioning, which provides the following routines:

(Metamodel::Versioning) method ver

method ver($obj)

Returns the version of the metaobject, if any, otherwise returns Mu.

(Metamodel::Versioning) method auth

method auth($obj)

Returns the author of the metaobject, if any, otherwise returns an empty string.

(Metamodel::Versioning) method api

method api($obj)

Returns the API of the metaobject, if any, otherwise returns an empty string.

(Metamodel::Versioning) method set_ver

method set_ver($obj$ver)

Sets the version of the metaobject.

(Metamodel::Versioning) method set_auth

method set_auth($obj$auth)

Sets the author of the metaobject.

(Metamodel::Versioning) method set_api

method set_api($obj$api)

Sets the API of the metaobject.

Routines supplied by role Metamodel::PrivateMethodContainer

Metamodel::ConcreteRoleHOW does role Metamodel::PrivateMethodContainer, which provides the following routines:

(Metamodel::PrivateMethodContainer) method add_private_method

method add_private_method(Metamodel::PrivateMethodContainer: $obj$name$code)

Adds a private method $code with name $name.

(Metamodel::PrivateMethodContainer) method private_method_table

method private_method_table(Metamodel::PrivateMethodContainer: $obj)

Returns a hash of name => &method_object

Routines supplied by role Metamodel::MethodContainer

Metamodel::ConcreteRoleHOW does role Metamodel::MethodContainer, which provides the following routines:

(Metamodel::MethodContainer) method add_method

method add_method(Metamodel::MethodContainer: $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.

(Metamodel::MethodContainer) method methods

method methods(Metamodel::MethodContainer: $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();                   # x 
say 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:D: $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.

(Metamodel::MethodContainer) method lookup

method lookup(Metamodel::MethodContainer: $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").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::AttributeContainer

Metamodel::ConcreteRoleHOW does role Metamodel::AttributeContainer, which provides the following routines:

(Metamodel::AttributeContainer) method add_attribute

method add_attribute(Metamodel::AttributeContainer: $obj$attribute)

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: $obj)

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: $obj)

Marks a type whose attributes default to having a write accessor. For example in

class Point is rw {
    has $.x;
    has $.y;
}

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 $p = Point.new(x => 1=> 2);
$p.x = 42;

(Metamodel::AttributeContainer) method rw

method rw(Metamodel::AttributeContainer: $obj)

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::ConcreteRoleHOW does role Metamodel::RoleContainer, which provides the following routines:

(Metamodel::RoleContainer) method add_role

method add_role(Metamodel::RoleContainer:D: $objMu $role)

Adds the $role to the list of roles to be composed.

(Metamodel::RoleContainer) method roles_to_compose

method roles_to_compose(Metamodel::RoleContainer:D: $obj --> List:D)

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::ConcreteRoleHOW does role Metamodel::MultipleInheritance, which provides the following routines:

(Metamodel::MultipleInheritance) method add_parent

method add_parent(Metamodel::MultipleInheritance:D: $Obj$parent:$hides)

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:D: $obj:$all:$tree)

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.

class D { };
class C1 is D { };
class C2 is D { };
class B is C1 is C2 { };
class A 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:D: $obj)

Returns a list of all hidden parent classes.

(Metamodel::MultipleInheritance) method hidden

method hidden(Metamodel::MultipleInheritance:D: $obj)

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:D: $obj)

Marks the type as hidden.