It seems that at the heart of it it seems that theres a missing event that has access to self? My inital though was to just create a type that was min, but types loose there context. I've been trying to wrap my head around the code for this to see if there was some way to try and have some other specified global structure that would still be in scope, but I alway get lost in the passing of things when I look at the type code.
I was able to trick things out but it requires that most of the 'built in' code structure gets re-done in BUILD, thus you have access to self and you end up forcing a system where everything passes thru a trigger. This allows you to check for any thing, but it does seem like much more of a hack then the inital example... It's a bit tedious so I posted it elsewhere: http://develonizer.com/svn/misc/min_max.pl On 7/14/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > How about this: > > has 'min' => ( > is => 'rw', > isa => 'Int', > default => sub { NEGATIVE_INFINITY }, > trigger => sub { > my ( $self, $val ) = @_; > carp "min is > max" unless $val <= $self->max; > } > ); > > has 'max' => ( > is => 'rw', > isa => 'Int', > default => sub { POSITIVE_INFINITY }, > trigger => sub { > my ( $self, $val ) = @_; > carp "max is < min" unless $val >= $self->min; > } > ); > > No BUILD needed. Consistency checked by the triggers whenever min and max > are set... > > 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, > ); > > 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 > > > > > > -- benh~