Rules / Types, classes & roles / metamodel

Metamodel::AttributeContainer Reference

Metaobject that can hold attributes

What it is #

Position in the hierarchy #

Routines #

Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.

method add_attribute #

method add_attribute($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.

method attributes #

method attributes($obj)

Returns a list of attributes. For most Raku types, these will be objects of type Attribute.

method set_rw #

method set_rw($obj)

Marks a type whose attributes default to having a write accessor. For example in 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;

method rw #

method rw($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. TODO: compose_attributes, get_attribute_for_usage Also TODO: describe :local, :excl, :all options of method attributes

Examples, run three ways #

Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.

3 no-output

role Metamodel::AttributeContainer {}

Not executed: the documentation states no expected output for this example.

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

Not executed: the documentation states no expected output for this example.

my $p = Point.new(x => 1, y => 2);
$p.x = 42;

Not executed: the documentation states no expected output for this example.