1 package Reaction::UI::ViewPort::Field::ChooseOne;
5 use Scalar::Util 'blessed';
7 class ChooseOne is 'Reaction::UI::ViewPort::Field', which {
9 has '+layout' => (default => 'select');
11 has valid_values => (isa => 'ArrayRef', is => 'ro', lazy_build => 1);
12 has value_choices => (isa => 'ArrayRef', is => 'ro', lazy_build => 1);
14 has value_map_method => (
15 isa => 'Str', is => 'ro', required => 1, default => sub { 'display_name' },
25 $value = $self->str_to_ident($value);
27 my $checked = $self->attribute->check_valid_value($self->action, $value);
28 confess "${value} is not a valid value" unless defined($checked);
31 $orig->($self, $value);
37 implements build_valid_values => as {
39 return [ $self->attribute->all_valid_values($self->action) ];
42 implements build_value_choices => sub{
44 my @pairs = map{{value => $self->obj_to_str($_), name => $self->obj_to_name($_)}}
45 @{ $self->valid_values };
46 return [ sort { $a->{name} cmp $b->{name} } @pairs ];
49 implements is_current_value => as {
50 my ($self, $check_value) = @_;
51 my $our_value = $self->value;
52 return unless ref($our_value);
53 $check_value = $self->obj_to_str($check_value) if ref($check_value);
54 return $self->obj_to_str($our_value) eq $check_value;
57 implements str_to_ident => as {
58 my ($self, $str) = @_;
59 my $u = URI->new('','http');
61 return { $u->query_form };
64 implements obj_to_str => as {
65 my ($self, $obj) = @_;
66 return $obj unless ref($obj);
67 confess "${obj} not an object" unless blessed($obj);
68 my $ident = $obj->ident_condition;
69 my $u = URI->new('', 'http');
70 $u->query_form(%$ident);
74 implements obj_to_name => as {
75 my ($self, $obj) = @_;
76 return $obj unless ref($obj);
77 confess "${obj} not an object" unless blessed($obj);
78 my $meth = $self->value_map_method;
88 Reaction::UI::ViewPort::Field::ChooseOne
94 =head2 is_current_value
100 =head2 valid_value_names
102 =head2 value_to_name_map
104 =head2 name_to_value_map
112 =head2 L<Reaction::UI::ViewPort::Field>
116 See L<Reaction::Class> for authors.
120 See L<Reaction::Class> for the license.