diff options
Diffstat (limited to 'lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm')
-rw-r--r-- | lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm b/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm index f6b679a..dba1a6d 100644 --- a/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm +++ b/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm @@ -3,45 +3,45 @@ package Reaction::UI::ViewPort::Field::Mutable::ChooseOne; use Reaction::Class; use Scalar::Util (); -class ChooseOne is 'Reaction::UI::ViewPort::Field', which { - - does 'Reaction::UI::ViewPort::Field::Role::Mutable::Simple'; - does 'Reaction::UI::ViewPort::Field::Role::Choices'; - - 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}"; - } - $self->value($checked); - }; +use namespace::clean -except => [ qw(meta) ]; +extends 'Reaction::UI::ViewPort::Field'; + +with 'Reaction::UI::ViewPort::Field::Role::Mutable::Simple'; +with 'Reaction::UI::ViewPort::Field::Role::Choices'; +sub adopt_value_string { + 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}"; + } + $self->value($checked); +}; - around _value_string_from_value => sub { - my $orig = shift; - my $self = shift; - my $value = $self->$orig(@_); - return $self->obj_to_name($value->{value}) if Scalar::Util::blessed($value); - return $self->obj_to_name($value) if blessed $value; - return "$value"; # force stringify. might work. probably won't. - }; +around _value_string_from_value => sub { + my $orig = shift; + my $self = shift; + my $value = $self->$orig(@_); + return $self->obj_to_name($value->{value}) if Scalar::Util::blessed($value); + return $self->obj_to_name($value) if blessed $value; + return "$value"; # force stringify. might work. probably won't. +}; +sub is_current_value { + my ($self, $check_value) = @_; + return unless $self->_model_has_value; + my $our_value = $self->value; + return unless defined($our_value); + $check_value = $self->obj_to_str($check_value) if ref($check_value); + return $self->obj_to_str($our_value) eq $check_value; +}; - implements is_current_value => as { - my ($self, $check_value) = @_; - return unless $self->_model_has_value; - my $our_value = $self->value; - return unless defined($our_value); - $check_value = $self->obj_to_str($check_value) if ref($check_value); - return $self->obj_to_str($our_value) eq $check_value; - }; +__PACKAGE__->meta->make_immutable; -}; 1; |