note
lima1
Your solution looks ok in my eyes. What's the problem? Adding enums is just another if statement (<i><b>Update: </b>when you want to implement them as described and not as a regex like </i><tt>qr{\A(?:red|green)\z}xms</tt>). For more exotic types just override the mutator, like the email example in the documentation:
<code>
# Only accept addresses which look valid.
sub email {
my($self) = shift;
my($email) = @_;
if( @_ ) { # Setting
require Email::Valid;
unless( Email::Valid->address($email) ) {
carp("$email doesn’t look like a valid address.");
return;
}
}
return $self->SUPER::email(@_);
}
</code>
I think if you are happy with [cpan://Class::Accessor], use it. I don't think you would save much lines of code with any other module.
643657
643657