| 1 | package FormValidator::Nested::Result; | ||||||||||||||
| 2 | 18 | ▶ | use Any::Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 18 | ▶ | use Any::Moose 'X::AttributeHelpers'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 18 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 18 | ▶ | use List::MoreUtils qw/any/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | has 'params' => ( | ||||||||||||||
| 9 | metaclass => 'Collection::Hash', | ||||||||||||||
| 10 | is => 'rw', | ||||||||||||||
| 11 | isa => 'HashRef[ArrayRef[FormValidator::Nested::Result::Param]]', | ||||||||||||||
| 12 | 714 | ▶ | default => sub { {} }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 18 | provides => { | |||||||||||||
| 14 | values => 'get_params', | ||||||||||||||
| 15 | get => 'get_param', | ||||||||||||||
| 16 | set => '_set_param', | ||||||||||||||
| 17 | exists => 'exists_param', | ||||||||||||||
| 18 | }, | ||||||||||||||
| 19 | ); | ||||||||||||||
| 20 | 18 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 21 | |||||||||||||||
| 22 | 146 | ▶ | sub has_error { | ||||||||||||
|
Subroutine
has_error: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 23 | 146 | my $self = shift; | |||||||||||||
| 24 | |||||||||||||||
| 25 | 146 | ▶ | if ( any { any { $_->has_error } @{$_} } $self->get_params ) { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||
| 26 | 81 | return 1; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | 65 | return 0; | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 97 | ▶ | sub error_params { | ||||||||||||
|
Subroutine
error_params: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 32 | 97 | my $self = shift; | |||||||||||||
| 33 | |||||||||||||||
| 34 | 97 | my %error_params = (); | |||||||||||||
| 35 | 97 | foreach my $param_array_ref ($self->get_params) { | |||||||||||||
| 36 | 188 | my @error_params = grep { $_->has_error } @{$param_array_ref}; | |||||||||||||
| 37 | 188 | ▶ | if ( @error_params ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | 56 | $error_params{$error_params[0]->key} = \@error_params; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | } | ||||||||||||||
| 41 | |||||||||||||||
| 42 | 97 | return \%error_params; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | |||||||||||||||
| 45 | # other_resultはResultでもResult::Paramでもおk | ||||||||||||||
| 46 | 1257 | ▶ | sub merge { | ||||||||||||
|
Subroutine
merge: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 47 | 1257 | my $self = shift; | |||||||||||||
| 48 | 1257 | my $other_result = shift; | |||||||||||||
| 49 | |||||||||||||||
| 50 | 1257 | ▶ | return if !blessed $other_result; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | |||||||||||||||
| 52 | 928 | ▶ | if ( $other_result->isa('FormValidator::Nested::Result') ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 53 | 588 | foreach my $param_array_ref ( $other_result->get_params ) { | |||||||||||||
| 54 | 307 | foreach my $param (@{$param_array_ref}) { | |||||||||||||
| 55 | 518 | $self->set_param($param); | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | } | ||||||||||||||
| 58 | } | ||||||||||||||
| 59 | elsif ( $other_result->isa('FormValidator::Nested::Result::Param') ) { | ||||||||||||||
| 60 | 340 | $self->set_param($other_result); | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | # result_paramはResult::Param | ||||||||||||||
| 65 | 858 | ▶ | sub set_param { | ||||||||||||
|
Subroutine
set_param: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 66 | 858 | my $self = shift; | |||||||||||||
| 67 | 858 | my $result_param = shift; | |||||||||||||
| 68 | |||||||||||||||
| 69 | 858 | ▶ | if ( $self->exists_param($result_param->key) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 70 | 322 | push @{$self->get_param($result_param->key)}, $result_param; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | else { | ||||||||||||||
| 73 | 536 | $self->_set_param($result_param->key, [$result_param]); | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | } | ||||||||||||||
| 76 | |||||||||||||||
| 77 | 0 | ▶ | sub count_params { | ||||||||||||
|
Subroutine
count_params: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 78 | 0 | my $self = shift; | |||||||||||||
| 79 | |||||||||||||||
| 80 | 0 | my $count = 0; | |||||||||||||
| 81 | 0 | foreach my $param_array_ref ( $self->get_params ) { | |||||||||||||
| 82 | 0 | $count += @{$param_array_ref}; | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 0 | return $count; | |||||||||||||
| 86 | } | ||||||||||||||
| 87 | |||||||||||||||
| 88 | 18 | 1; | |||||||||||||
| 89 | |||||||||||||||