1 package Reaction::UI::ViewPort::Field::Mutable::ChooseOne;
6 use namespace::clean -except => [ qw(meta) ];
7 extends 'Reaction::UI::ViewPort::Field';
9 with 'Reaction::UI::ViewPort::Field::Role::Mutable::Simple';
10 with 'Reaction::UI::ViewPort::Field::Role::Choices';
11 sub adopt_value_string {
13 my $value = $self->value_string;
14 if(!defined($value) or !length $value) {
18 $value = $self->str_to_ident($value) if (!ref $value);
19 my $attribute = $self->attribute;
20 my $checked = $attribute->check_valid_value($self->model, $value);
21 unless (defined $checked) {
23 my $serialised = Data::Dumper->new([ $value ])->Indent(0)->Dump;
24 $serialised =~ s/^\$VAR1 = //; $serialised =~ s/;$//;
25 confess "${serialised} is not a valid value for ${\$attribute->name} on "
26 ."${\$attribute->associated_class->name}";
28 $self->value($checked);
31 around _value_string_from_value => sub {
34 my $value = $self->$orig(@_);
36 # what's up with $value->{value} ?!
37 # and why are we calling obj_to_name here, shouldn't it be obj_to_str
38 # return $self->obj_to_name($value->{value}) if Scalar::Util::blessed($value);
39 # return $self->obj_to_name($value) if blessed $value;
41 return $self->obj_to_str($value) if Scalar::Util::blessed($value);
43 return "$value"; # force stringify. might work. probably won't.
45 sub is_current_value {
46 my ($self, $check_value) = @_;
47 return unless $self->_model_has_value;
48 my $our_value = $self->value;
49 return unless defined($our_value);
50 $check_value = $self->obj_to_str($check_value) if ref($check_value);
51 return $self->obj_to_str($our_value) eq $check_value;
54 __PACKAGE__->meta->make_immutable;