package Appointment; use Moose; # automatically turns on strict and warnings use Moose::Util::TypeConstraints; my @freq_valid = (qw/OneTime Daily Monthly Quarterly/); has 'Month' => ( is => 'ro', isa => subtype( 'Int' => where { $_ > 0 and $_ < 13 } ), required => 1, ); has 'Day' => ( is => 'ro', isa => 'Int', required => 1, ); has 'Freq' => ( is => 'ro', isa => 'Str', default => 'OneTime', ); sub BUILD { my $self = shift; if ($self->Month == 12 and $self->Day == 1){ die "I'm having a bad Moose day."; } } 1; #### package Appointment; use Moose; # automatically turns on strict and warnings use Moose::Util::TypeConstraints; use List::Util qw/any/; my @freq_valid = (qw/OneTime Daily Monthly Quarterly/); subtype 'AppointmentFreq' => as 'Str' => where { my $arg = $_; any{ $_ eq $arg } @freq_valid } => message { 'The Freq you provided is not valid' }; has 'Month' => ( is => 'ro', isa => subtype( 'Int' => where { $_ > 0 and $_ < 13 } ), required => 1, ); has 'Day' => ( is => 'ro', isa => 'Int', required => 1, ); has 'Freq' => ( is => 'ro', isa => 'AppointmentFreq', default => 'OneTime', ); sub BUILD { my $self = shift; if ($self->Month == 12 and $self->Day == 1){ die "I'm having a bad Moose day."; } } 1;