DavidSzczesniak
12/22/2017 - 2:43 PM

Required attributes

By default, all attributes are optional and don't need to be provided when creating each new object. However, if u want to make an attribute required, simply set the 'required' option to true.

has 'name' => (
  is => 'ro',
  required => 1,
);

# note: if you define a clearer method inside a required attribute, the clearer will work.
# This is because all that 'required' means is that the attribute(name) must be provided.
# It doesn't say anything about its value, so it could be undefined. 
# However, there is obviously little sense in providing a clearer to a required attribute.