fix matching passwords stuff
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field / Mutable / ChooseOne.pm
CommitLineData
ddccc6a2 1package Reaction::UI::ViewPort::Field::Mutable::ChooseOne;
2
3use Reaction::Class;
9757d0cf 4use Scalar::Util ();
ddccc6a2 5
81393881 6use namespace::clean -except => [ qw(meta) ];
7extends 'Reaction::UI::ViewPort::Field';
8
9with 'Reaction::UI::ViewPort::Field::Role::Mutable::Simple';
10with 'Reaction::UI::ViewPort::Field::Role::Choices';
11sub adopt_value_string {
12 my ($self) = @_;
13 my $value = $self->value_string;
14 $value = $self->str_to_ident($value) if (!ref $value);
15 my $attribute = $self->attribute;
16 my $checked = $attribute->check_valid_value($self->model, $value);
17 unless (defined $checked) {
18 require Data::Dumper;
19 my $serialised = Data::Dumper->new([ $value ])->Indent(0)->Dump;
20 $serialised =~ s/^\$VAR1 = //; $serialised =~ s/;$//;
21 confess "${serialised} is not a valid value for ${\$attribute->name} on "
22 ."${\$attribute->associated_class->name}";
23 }
24 $self->value($checked);
25};
ddccc6a2 26
81393881 27around _value_string_from_value => sub {
28 my $orig = shift;
29 my $self = shift;
30 my $value = $self->$orig(@_);
31 return $self->obj_to_name($value->{value}) if Scalar::Util::blessed($value);
32 return $self->obj_to_name($value) if blessed $value;
33 return "$value"; # force stringify. might work. probably won't.
34};
35sub is_current_value {
36 my ($self, $check_value) = @_;
37 return unless $self->_model_has_value;
38 my $our_value = $self->value;
39 return unless defined($our_value);
40 $check_value = $self->obj_to_str($check_value) if ref($check_value);
41 return $self->obj_to_str($our_value) eq $check_value;
42};
cc44a337 43
81393881 44__PACKAGE__->meta->make_immutable;
ddccc6a2 45
ddccc6a2 46
471;