work in progress, listview still broken
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field / Mutable / ChooseOne.pm
CommitLineData
ddccc6a2 1package Reaction::UI::ViewPort::Field::Mutable::ChooseOne;
2
3use Reaction::Class;
4
5class ChooseOne is 'Reaction::UI::ViewPort::Field', which {
6
c8fbb8ad 7 does 'Reaction::UI::ViewPort::Field::Role::Mutable';
8 does 'Reaction::UI::ViewPort::Field::Role::Choices';
ddccc6a2 9
10 around value => sub {
11 my $orig = shift;
12 my $self = shift;
13 return $orig->($self) unless @_;
14 my $value = shift;
15 if (defined $value) {
16 $value = $self->str_to_ident($value) if (!ref $value);
17 my $checked = $self->attribute->check_valid_value($self->action, $value);
18 confess "${value} is not a valid value" unless defined($checked);
19 $value = $checked;
20 }
21 $orig->($self, $value);
22 };
23
24 implements is_current_value => as {
25 my ($self, $check_value) = @_;
26 my $our_value = $self->value;
27 return unless ref($our_value);
28 $check_value = $self->obj_to_str($check_value) if ref($check_value);
29 return $self->obj_to_str($our_value) eq $check_value;
30 };
31
32
33};
34
351;