in reply to Re: Moose: mutualy exclusive bolean attributes.
in thread Moose: mutualy exclusive bolean attributes.

It's worth noting that your method doesn't prevent individual accessors.

has 'status' => ( is => 'rw', isa => 'Status|Undef', handles => { success => sub { ( $_[0]->status() // '' ) eq 'success' }, error => sub { ( $_[0]->status() // '' ) eq 'error' }, pending => sub { ( $_[0]->status() // '' ) eq 'pending' }, }, );

Replies are listed 'Best First'.
Re^3: Moose: mutualy exclusive bolean attributes.
by chrestomanci (Priest) on Dec 24, 2010 at 10:52 UTC

    Thank you. ikegami

    That looks like it handles the requirement for a getter for the success|error|pending attributes. I guess if I want a setter as well, I can expand those subs to larger ones that read the value of $_[1] as well.

    Combined with Arunbear's suggestion to use Moose::Util::TypeConstraints to get an enum on the underlying status field, I think I am three quarters of the way to what I want to achieve.

      I guess if I want a setter as well, I can expand those subs to larger ones that read the value of $_[1] as well.

      That doesn't make much sense. What would happen for

      $self->error(0);

        Change the status to undefined, but it would be better to do $self->pending(1)