Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: accessor generation with constraints

by lima1 (Curate)
on Oct 09, 2007 at 13:57 UTC ( #643694=note: print w/replies, xml ) Need Help??

in reply to accessor generation with constraints

Your solution looks ok in my eyes. What's the problem? Adding enums is just another if statement (Update: when you want to implement them as described and not as a regex like qr{\A(?:red|green)\z}xms). For more exotic types just override the mutator, like the email example in the documentation:
# 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(@_); }
I think if you are happy with Class::Accessor, use it. I don't think you would save much lines of code with any other module.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://643694]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2021-04-19 12:26 GMT
Find Nodes?
    Voting Booth?

    No recent polls found