4cc556c2e143af9d25ebd8f45df124a6973a90e8
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field / Mutable / Array.pm
1 package Reaction::UI::ViewPort::Field::Mutable::Array;
2
3 use Reaction::Class;
4
5 use namespace::clean -except => [ qw(meta) ];
6 extends 'Reaction::UI::ViewPort::Field::Array';
7
8 with 'Reaction::UI::ViewPort::Field::Role::Mutable';
9
10 around value => sub {
11   my $orig = shift;
12   my $self = shift;
13   return $orig->($self) unless @_;
14   my $value = defined $_[0] ? $_[0] : [];
15   $orig->($self, (ref $value eq 'ARRAY' ? $value : [ $value ]));
16 };
17
18 # value_string doesn't make sense in an Array field
19 override _value_string_from_value => sub { shift->_empty_string_value };
20
21 __PACKAGE__->meta->make_immutable;
22
23 1;
24