| 1 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Constraint::AllOrNone; | ||||||||||||||||||||||||||||
| 4 | 10 | $HTML::FormFu::Constraint::AllOrNone::VERSION = '2.09'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Multi-field All or None Constraint | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 10 | extends 'HTML::FormFu::Constraint'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 10 | with 'HTML::FormFu::Role::Constraint::Others'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 18 | ▶ | sub process { | ||||||||||||||||||||||||||
|
Subroutine
process: called CC=14 SCAR=26.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 18 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # check when condition | ||||||||||||||||||||||||||||
| 16 | 18 | ▶ | return if !$self->_process_when($params); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 18 | my $others = $self->others; | |||||||||||||||||||||||||||
| 19 | 18 | ▶ | return if !defined $others; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 18 | my @names = ( $self->nested_name ); | |||||||||||||||||||||||||||
| 22 | 18 | ▶ | push @names, ref $others ? @{$others} : $others; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 18 | my @failed; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 18 | for my $name (@names) { | |||||||||||||||||||||||||||
| 27 | 54 | my $value = $self->get_nested_hash_value( $params, $name ); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 54 | my $seen = 0; | |||||||||||||||||||||||||||
| 30 | 54 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 6 | my @errors = eval { $self->constrain_values( $value, $params ) }; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6 | ▶ | if ( !@errors && !$@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@errors or $@
MC/DC0%0/2
@errors or $@
@errors
$@
Truth table33%1/3
A or B
A= @errorsB= $@
| |||||||||||||||||||||||||||||
| 34 | 6 | $seen = 1; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | else { | ||||||||||||||||||||||||||||
| 38 | 48 | my $ok = eval { $self->constrain_value($value) }; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 48 | ▶ | if ( $ok && !$@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ok and not $@
MC/DC50%1/2
$ok and not $@
$ok
not $@
Truth table66%2/3
A and not(B)
A= $okB= not $@
| |||||||||||||||||||||||||||||
| 41 | 25 | $seen = 1; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 54 | ▶ | if ( !$seen ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 23 | push @failed, $name; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 18 | ▶ | my $pass = @failed && scalar @failed != scalar @names ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@failed and scalar @failed != scalar @names
MC/DC100%2/2
@failed and scalar @failed != scalar @names
@failed
scalar @failed != scalar @names
Truth table100%3/3
A and B
A= @failedB= scalar @failed != scalar @names
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 18 | ▶ | return $self->mk_errors( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | { pass => $pass, | ||||||||||||||||||||||||||||
| 54 | failed => $pass ? [] : \@failed, | ||||||||||||||||||||||||||||
| 55 | names => \@names, | ||||||||||||||||||||||||||||
| 56 | } ); | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 60 | ▶ | sub constrain_value { | ||||||||||||||||||||||||||
|
Subroutine
constrain_value: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 60 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 60 | ▶ | return 0 if !defined $value || $value eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value or $value eq ""
MC/DC100%2/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 37 | return 1; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 10 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 10 | 1; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||