X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FViewPort%2FField%2FMutable%2FChooseOne.pm;h=903352821468c9a734fee4346fcc9e800d96f709;hb=62ffa273e3c709800ea7f4a19f9f28e9b1da5867;hp=f16ea664d4c24ec7e17101b188a6c684755c41a7;hpb=2490a71f2c09f04beefe516528c92274f6d06592;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm b/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm index f16ea66..9033528 100644 --- a/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm +++ b/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm @@ -5,28 +5,23 @@ use Scalar::Util (); class ChooseOne is 'Reaction::UI::ViewPort::Field', which { - does 'Reaction::UI::ViewPort::Field::Role::Mutable'; + does 'Reaction::UI::ViewPort::Field::Role::Mutable::Simple'; does 'Reaction::UI::ViewPort::Field::Role::Choices'; - around value => sub { - my $orig = shift; - my $self = shift; - return $orig->($self) unless @_; - my $value = shift; - if (defined $value) { - $value = $self->str_to_ident($value) if (!ref $value); - my $attribute = $self->attribute; - my $checked = $attribute->check_valid_value($self->model, $value); - unless (defined $checked) { - require Data::Dumper; - my $serialised = Data::Dumper->new([ $value ])->Indent(0)->Dump; - $serialised =~ s/^\$VAR1 = //; $serialised =~ s/;$//; - confess "${serialised} is not a valid value for ${\$attribute->name} on " - ."${\$attribute->associated_class->name}"; - } - $value = $checked; + implements adopt_value_string => as { + my ($self) = @_; + my $value = $self->value_string; + $value = $self->str_to_ident($value) if (!ref $value); + my $attribute = $self->attribute; + my $checked = $attribute->check_valid_value($self->model, $value); + unless (defined $checked) { + require Data::Dumper; + my $serialised = Data::Dumper->new([ $value ])->Indent(0)->Dump; + $serialised =~ s/^\$VAR1 = //; $serialised =~ s/;$//; + confess "${serialised} is not a valid value for ${\$attribute->name} on " + ."${\$attribute->associated_class->name}"; } - $orig->($self, $value); + $self->value($checked); }; around _value_string_from_value => sub { @@ -47,7 +42,6 @@ class ChooseOne is 'Reaction::UI::ViewPort::Field', which { return $self->obj_to_str($our_value) eq $check_value; }; - }; 1;