On Thu, Nov 26, 2009 at 10:46 AM, Ovid <publiustemp-catal...@yahoo.com> wrote: > I have two attributes, 'xml' and 'xml_file' for an object. One or the other > must be supplied, but not both. > > Must I validated this in BUILD or is there another way of doing this?
Well, I would use a trigger and predicate. Triggers are fired AFTER the attribute is set in the constructor or with an explicit call to the setter. I don't like to have BUILD unless I need it, and this will check runtime sets too. So you have something like has 'foo' => ( isa => 'Int' , is => 'rw' , predicate => 'has_foo' , trigger => \&consistancy ); has 'bar' => ( isa => 'Int' , is => 'rw' , predicate => 'has_bar' , trigger => \&consistancy ); sub consistancy { my $self = shift; throw_error('OVID SAYS NO NO') if $self->has_foo && $self->has_bar ; } -- Evan Carroll System Lord of the Internets http://www.evancarroll.com