Documentation for routine is required

Documentation for routine is required, assembled from the following types:

language documentation Typesystem

From Typesystem

(Typesystem) trait is required

Defined as:

multi sub trait_mod:<is>(Attribute $attr:$required!)

Marks a class or roles attribute as required. If the attribute is not initialized at object construction time throws X::Attribute::Required.

class Correct {
    has $.attr is required;
    submethod BUILD (:$attr{ $!attr = $attr }
}
say Correct.new(attr => 42);
# OUTPUT: «Correct.new(attr => 42)␤» 
 
class C {
    has $.attr is required;
}
C.new;
CATCH { default { say .^name => .Str } }
# OUTPUT: «X::Attribute::Required => The attribute '$!attr' is required, but you did not provide a value for it.␤» 

class Attribute

From Attribute

(Attribute) trait is required

multi sub trait_mod:<is> (Attribute $attr:$required!)

Marks an attribute as being required. If a value is not provided during object construction, an exception is thrown.

class Foo {
   has $.bar is required;
   has $.baz;
};
 
Foo.new(bar => 42); # works 
Foo.new(baz => 42);
CATCH { default { put .^name''.Str } };
# OUTPUT: «X::Attribute::Required: The attribute '$!bar' is required, but you did not provide a value for it.␤» 

is required doesn't just affect the default constructor, it checks for the attribute at a lower level, so it will work for custom constructors written using bless.