What is the typical approach for custom initialization of certain attributes when using Moose?
For instance, suppose I take two dates in string format as input to my class:
has startdate => (is => 'ro', isa => 'Str', required => 1);
has enddate => (is => 'ro', isa => 'Str');
These dates come in as strings, but I need them formatted in a specific date format (ISO8601), without Moose I would just initialize them in new()
but I am unsure about with Moose.
It seems that the viable options from reading the docs are in BUILDARGS
, BUILD
, or using coercion. Which of these would be most appropriate given that I have a function _format_as_iso8601()
that can take a date and return it formatted correctly?