Re: checking consistency between attributes
[email protected] (Stevan Little)
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
On Jul 14, 2008, at 5:35 PM, Charles Alderman wrote: > Besides defining negative and positive infinity, the only problem I > see is if both min and max are set at the same time, as in the > constructor. I don't know which error you'd get if the object was > initialized like this: > > my $foo = Foo->new( > min => 1, > max => -1, > ); Attributes are stored in a hash so there is no way to determine for sure which one will be created first. However I suspect that it wouldn't matter too much anyway. - Stevan > Charles Alderman > > ----- Original Message ----- > From: Guillaume Rousse <[email protected]> > Sent: Mon, 14 Jul 2008 23:15:49 +0200 > Re: checking consistency between attributes > > > >> Hello list. >> >> What's the best way to check consistency between attributes >> values ? Is >> there anything better than a dedicated BUILD method, such as: >> >> use Moose; >> use Carp; >> >> has 'min' => (is => 'rw', isa => 'Int'); >> has 'max' => (is => 'rw', isa => 'Int'); >> >> sub BUILD { >> my ($self, $params) = @_; >> >> my ($max, $min) = ($self->max(), $self->min()); >> croak "max < min" if defined $max && defined $min && $max < $min; >> } >> -- >> Guillaume Rousse >> Moyens Informatiques - INRIA Futurs >> Tel: 01 69 35 69 62 > > >