slight change for saner behavior when munging names
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / DisplayField / Collection.pm
CommitLineData
7adfd53f 1package Reaction::UI::ViewPort::DisplayField::Collection;
2
3use Reaction::Class;
4use Scalar::Util 'blessed';
5
6class Collection is 'Reaction::UI::ViewPort::DisplayField', which {
7 has '+value' => (isa => 'ArrayRef');
8 has '+layout' => (default => 'displayfield/list');
9
10 has value_names => (isa => 'ArrayRef', is => 'ro', lazy_build => 1);
11
12 has value_map_method => (
13 isa => 'Str', is => 'ro', required => 1, default => sub { 'display_name' },
14 );
15
16 override build_value => sub {
f670cfd0 17 return [super()->members];
7adfd53f 18 };
19
20 implements build_value_names => as {
21 my $self = shift;
22 my @all = @{$self->value||[]};
23 my $meth = $self->value_map_method;
24 my @names = map { blessed $_ ? $_->$meth : $_ } @all;
25 return [ sort @names ];
26 };
27};
28
291;