trait is required (Attribute)

Documentation for trait is required (Attribute) assembled from the following types:

class Attribute

From Attribute

(Attribute) trait is required (Attribute)

The trait is required will mark the attribute as to be filled with a value when the object is instantiated. Failing to do so will result in a runtime error.

class C {
    has $.a is required
my $c =;
CATCH{ default { say .^name''.Str } }
# OUTPUT: «X::Attribute::Required: The attribute '$!a' is required, but you did not provide a value for it.␤» 

You can also specify a reason why the attribute is required:

class D {
    has $.a is required("it is a good idea");
my $d =;
CATCH{ default { say .^name''.Str } }
# OUTPUT: «X::Attribute::Required: The attribute '$!a' is required because it is a good idea,␤but you did not provide a value for it.␤»