In Type system§
See primary documentation in context for trait is required
multi trait_mod:<is>(Attribute , :!)multi trait_mod:<is>(Parameter , :!)
Marks a class or roles attribute as required. If the attribute is not initialized at object construction time throws X::Attribute::Required
.
say Correct.new(attr => 42);# OUTPUT: «Correct.new(attr => 42)»C.new;CATCH# OUTPUT: «X::Attribute::Required => The attribute '$!attr' is required, but you did not provide a value for it.»
Note a class with a private attribute will give the same error:
D.new;CATCH# OUTPUT: «X::Attribute::Required => The attribute '$!attr' is required, but you did not provide a value for it.»
You can provide a reason why it's required as an argument to is required
;say Correct.new();# OUTPUT: «The attribute '$!attr' is required because it's so cool,but you did not provide a value for it.»