| 1 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Constraint::Repeatable::Any; | ||||||||||||||||||||||||||||||||||
| 4 | 6 | $HTML::FormFu::Constraint::Repeatable::Any::VERSION = '2.09'; | |||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Ensure at least 1 of a repeated field is filled-in | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 6 | extends 'HTML::FormFu::Constraint'; | |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Scalar::Util qw( reftype ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | after BUILD => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 4 | $self->only_on_reps( [1] ); | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 4 | return; | |||||||||||||||||||||||||||||||||
| 20 | 6 | }; | |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | 34 | ▶ | sub process { | ||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 23 | 34 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 34 | ▶ | return unless $self->_run_this_rep; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | # check when condition | ||||||||||||||||||||||||||||||||||
| 28 | 16 | ▶ | return if !$self->_process_when($params); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | 16 | my $field = $self->field; | |||||||||||||||||||||||||||||||||
| 31 | 16 | my $repeatable = $field->get_parent( { type => 'Repeatable' } ); | |||||||||||||||||||||||||||||||||
| 32 | 16 | my $pass; | |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 16 | ▶ | my $original_name = $field->original_name || ''; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$field->original_name || ''
MC/DC100%1/1
$field->original_name || ''
$field->original_name
Truth table100%2/2
A
A= $field->original_name
| |||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | my @fields | ||||||||||||||||||||||||||||||||||
| 37 | 46 | = grep { $_->get_parent( { type => 'Repeatable' } ) == $repeatable } | |||||||||||||||||||||||||||||||||
| 38 | 52 | ▶ | grep { ( $_->original_name || '' ) eq $original_name } | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_->original_name || ''
MC/DC100%1/1
$_->original_name || ''
$_->original_name
Truth table100%2/2
A
A= $_->original_name
| |||||||||||||||||||||||||||||||||||
| 39 | 16 | @{ $repeatable->get_fields }; | |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 16 | my $increment_field_names = $repeatable->increment_field_names; | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 16 | for my $f (@fields) { | |||||||||||||||||||||||||||||||||
| 44 | 28 | my $value; | |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 28 | ▶ | if ($increment_field_names) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 47 | 22 | $value = $self->get_nested_hash_value( $params, $f->nested_name ); | |||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||||||||||||||||
| 50 | 6 | $value = _find_this_field_value( $self, $f, $repeatable, $params ); | |||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | 28 | my $ok = eval { $self->constrain_value($value) }; | |||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | 28 | ▶ | 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 $@
| |||||||||||||||||||||||||||||||||||
| 56 | 12 | $pass = 1; | |||||||||||||||||||||||||||||||||
| 57 | 12 | last; | |||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | 16 | return $self->mk_errors( { pass => $pass, } ); | |||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 6 | ▶ | sub _find_this_field_value { | ||||||||||||||||||||||||||||||||
|
Subroutine
_find_this_field_value: called CC=7 SCAR=20.5
| |||||||||||||||||||||||||||||||||||
| 65 | 6 | my ( $self, $field, $repeatable, $params ) = @_; | |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 6 | my $nested_name = $field->nested_name; | |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 6 | my $value = $self->get_nested_hash_value( $params, $nested_name ); | |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | my @fields_with_this_name | ||||||||||||||||||||||||||||||||||
| 72 | 6 | = @{ $repeatable->get_fields( { nested_name => $nested_name } ) }; | |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | 6 | ▶ | if ( @fields_with_this_name > 1 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 75 | 6 | my $index; | |||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 6 | ▶ | for ( my $i = 0; $i <= $#fields_with_this_name; ++$i ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 78 | 8 | ▶ | if ( $fields_with_this_name[$i] eq $field ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 79 | 6 | $index = $i; | |||||||||||||||||||||||||||||||||
| 80 | 6 | last; | |||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 6 | ▶ | croak 'did not find ourself - how can this happen?' | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 85 | if !defined $index; | ||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | 6 | ▶ | if ( reftype($value) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 88 | 6 | $value = $value->[$index]; | |||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||
| 90 | elsif ( $index == 0 ) { | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | # keep $value | ||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||||||||
| 95 | 0 | undef $value; | |||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 6 | return $value; | |||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | 28 | ▶ | sub constrain_value { | ||||||||||||||||||||||||||||||||
|
Subroutine
constrain_value: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 103 | 28 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | 28 | ▶ | return defined $value && length $value; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $value && length $value
MC/DC50%1/2
defined $value && length $value
defined $value
length $value
Truth table66%2/3
A && B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | sub _localize_args { | ||||||||||||||||||||||||||||||||
|
Subroutine
_localize_args: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||
| 109 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | return | ||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | $self->parent->label | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$self->parent->label || $self->parent->original_name || $self->parent->name
$self->parent->label or $self->parent->original_name
MC/DC0%0/3
$self->parent->label || $self->parent->original_name || $self->parent->name
$self->parent->label
$self->parent->original_name
$self->parent->name
Truth table25%1/4
A or B || C
A= $self->parent->labelB= $self->parent->original_nameC= $self->parent->name
| |||||||||||||||||||||||||||||||||||
| 113 | || $self->parent->original_name | ||||||||||||||||||||||||||||||||||
| 114 | || $self->parent->name; | ||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||
| 117 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | 6 | 1; | |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | __END__ | ||||||||||||||||||||||||||||||||||