Commit | Line | Data |
ddccc6a2 |
1 | package Reaction::UI::ViewPort::Field::Array; |
7adfd53f |
2 | |
3 | use Reaction::Class; |
4 | use Scalar::Util 'blessed'; |
ddccc6a2 |
5 | use aliased 'Reaction::UI::ViewPort::Field'; |
7adfd53f |
6 | |
ddccc6a2 |
7 | class Array is Field, which { |
7adfd53f |
8 | has '+value' => (isa => 'ArrayRef'); |
7adfd53f |
9 | |
10 | has value_names => (isa => 'ArrayRef', is => 'ro', lazy_build => 1); |
7adfd53f |
11 | has value_map_method => ( |
12 | isa => 'Str', is => 'ro', required => 1, default => sub { 'display_name' }, |
13 | ); |
14 | |
89939ff9 |
15 | implements _build_value_names => as { |
7adfd53f |
16 | my $self = shift; |
7adfd53f |
17 | my $meth = $self->value_map_method; |
1734a92a |
18 | my @names = map { blessed($_) ? $_->$meth : $_ } @{ $self->value }; |
7adfd53f |
19 | return [ sort @names ]; |
20 | }; |
21 | |
1734a92a |
22 | implements _empty_value => as { [] }; |
7adfd53f |
23 | }; |
24 | |
25 | 1; |