| 1 | package Reaction::UI::ViewPort::Field::Mutable::ChooseMany; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use Reaction::Class; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | my $listify = sub{ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | return [] unless defined($_[0]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | return ref $_[0] eq 'ARRAY' ? $_[0] : [$_[0]]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 8 | 4 | }; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use namespace::clean -except => [ qw(meta) ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use MooseX::Types::Moose qw/ArrayRef/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | extends 'Reaction::UI::ViewPort::Field'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 4 | with 'Reaction::UI::ViewPort::Field::Role::Mutable' => { value_type => 'ArrayRef' }; | |||||||||||||||||||||||||||
| 15 | 4 | with 'Reaction::UI::ViewPort::Field::Role::Choices'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | #MUST BE HERE, BELOW THE 'does', OR THE TRIGGER WILL NOT HAPPEN! | ||||||||||||||||||||||||||||
| 18 | #has '+value' => (isa => ArrayRef); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1206 | ▶ | around value => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||
| 21 | 1206 | my $orig = shift; | |||||||||||||||||||||||||||
| 22 | 1206 | my $self = shift; | |||||||||||||||||||||||||||
| 23 | 1206 | ▶ | return $orig->($self) unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 2 | my $value = $listify->(shift); | |||||||||||||||||||||||||||
| 25 | 2 | $_ = $self->str_to_ident($_) for @$value; | |||||||||||||||||||||||||||
| 26 | 2 | my $checked = $self->attribute->check_valid_value($self->model, $value); | |||||||||||||||||||||||||||
| 27 | # i.e. fail if any of the values fail | ||||||||||||||||||||||||||||
| 28 | confess "Not a valid set of values" | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if (@$checked < @$value || grep { !defined($_) } @$checked); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$checked < @$value or grep {not defined $_;} @$checked
MC/DC0%0/2
@$checked < @$value or grep {not defined $_;} @$checked
@$checked < @$value
grep {not defined $_;} @$checked
Truth table33%1/3
A or B
A= @$checked < @$valueB= grep {not defined $_;} @$checked
| |||||||||||||||||||||||||||||
| 30 | 2 | $orig->($self, $checked); | |||||||||||||||||||||||||||
| 31 | 4 | }; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 3 | ▶ | around _value_string_from_value => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||
| 35 | 3 | my $orig = shift; | |||||||||||||||||||||||||||
| 36 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 0 | join(", ", (map {$self->obj_to_name($_->{value}) } @{ $self->current_value_choices })); | |||||||||||||||||||||||||||
| 38 | 4 | }; | |||||||||||||||||||||||||||
| 39 | 1200 | ▶ | sub is_current_value { | ||||||||||||||||||||||||||
|
Subroutine
is_current_value: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 1200 | my ($self, $check_value) = @_; | |||||||||||||||||||||||||||
| 41 | 1200 | ▶ | return unless $self->_model_has_value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 1200 | ▶ | my @our_values = @{$self->value || []}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->value || []
MC/DC0%0/1
$self->value || []
$self->value
Truth table50%1/2
A
A= $self->value
| |||||||||||||||||||||||||||||
| 43 | 1200 | ▶ | $check_value = $self->obj_to_str($check_value) if ref($check_value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | return grep { $self->obj_to_str($_) eq $check_value } @our_values; | |||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||
| 46 | 9 | ▶ | sub current_value_choices { | ||||||||||||||||||||||||||
|
Subroutine
current_value_choices: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 9 | my @all = grep { $self->is_current_value($_->{value}) } @{$self->value_choices}; | |||||||||||||||||||||||||||
| 49 | 9 | return [ @all ]; | |||||||||||||||||||||||||||
| 50 | }; | ||||||||||||||||||||||||||||
| 51 | 3 | ▶ | sub available_value_choices { | ||||||||||||||||||||||||||
|
Subroutine
available_value_choices: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 53 | 3 | my @all = grep { !$self->is_current_value($_->{value}) } @{$self->value_choices}; | |||||||||||||||||||||||||||
| 54 | 3 | return [ @all ]; | |||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | around handle_events => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=31.7
| |||||||||||||||||||||||||||||
| 58 | 2 | my $orig = shift; | |||||||||||||||||||||||||||
| 59 | 2 | my ($self, $events) = @_; | |||||||||||||||||||||||||||
| 60 | 2 | ▶ | $events->{value} = [] if $events->{no_current_value}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 2 | my $ev_value = $listify->($events->{value}); | |||||||||||||||||||||||||||
| 62 | 2 | ▶ | if (delete $events->{add_all_values}) { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 63 | 0 | $events->{value} = [map {$self->obj_to_str($_)} @{$self->valid_values}]; | |||||||||||||||||||||||||||
| 64 | ▶ | } elsif (exists $events->{add_values} && delete $events->{do_add_values}) { | |||||||||||||||||||||||||||
|
Condition33%1/3
exists $events->{"add_values"} and delete $events->{"do_add_values"}
MC/DC0%0/2
exists $events->{"add_values"} and delete $events->{"do_add_values"}
exists $events->{"add_values"}
delete $events->{"do_add_values"}
Truth table33%1/3
A and B
A= exists $events->{"add_values"}B= delete $events->{"do_add_values"}
| |||||||||||||||||||||||||||||
| 65 | 0 | my $add = $listify->(delete $events->{add_values}); | |||||||||||||||||||||||||||
| 66 | 0 | $events->{value} = [ @{$ev_value}, @$add ]; | |||||||||||||||||||||||||||
| 67 | } elsif (delete $events->{remove_all_values}) { | ||||||||||||||||||||||||||||
| 68 | 0 | $events->{value} = []; | |||||||||||||||||||||||||||
| 69 | ▶ | }elsif (exists $events->{remove_values} && delete $events->{do_remove_values}) { | |||||||||||||||||||||||||||
|
Condition33%1/3
exists $events->{"remove_values"} and delete $events->{"do_remove_values"}
MC/DC0%0/2
exists $events->{"remove_values"} and delete $events->{"do_remove_values"}
exists $events->{"remove_values"}
delete $events->{"do_remove_values"}
Truth table33%1/3
A and B
A= exists $events->{"remove_values"}B= delete $events->{"do_remove_values"}
| |||||||||||||||||||||||||||||
| 70 | 0 | my $remove = $listify->(delete $events->{remove_values}); | |||||||||||||||||||||||||||
| 71 | 0 | my %r = map { ($_ => 1) } @$remove; | |||||||||||||||||||||||||||
| 72 | 0 | $events->{value} = [ grep { !$r{$_} } @{$ev_value} ]; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | return $orig->(@_); | |||||||||||||||||||||||||||
| 76 | 4 | }; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 4 | 1; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 NAME | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Reaction::UI::ViewPort::Field::Mutable::ChooseMany | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head1 METHODS | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head2 is_current_value | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head2 current_values | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head2 available_values | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head2 available_value_names | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head2 L<Reaction::UI::ViewPort::Field> | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | See L<Reaction::Class> for authors. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | See L<Reaction::Class> for the license. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||||||||||