| 1 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Constraint::Equal; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | $HTML::FormFu::Constraint::Equal::VERSION = '2.09'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Multi-field Equality Constraint | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | extends 'HTML::FormFu::Constraint'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | with 'HTML::FormFu::Role::Constraint::Others'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use HTML::FormFu::Util qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | DEBUG_CONSTRAINTS | ||||||||||||||||||||||||||||||||||||||||||
| 14 | debug | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use List::Util 1.33 qw( all ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | our $EMPTY_STR = q{}; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 35 | ▶ | sub process { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=15 SCAR=27.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 35 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | # check when condition | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 35 | ▶ | return if !$self->_process_when($params); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 35 | my $others = $self->others; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 35 | ▶ | return if !defined $others; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 35 | my $value = $self->get_nested_hash_value( $params, $self->nested_name ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 35 | ▶ | DEBUG_CONSTRAINTS && debug( VALUE => $value ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 35 | ▶ | my @names = ref $others ? @{$others} : ($others); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 35 | my @failed; | |||||||||||||||||||||||||||||||||||||||||
| 35 | my %values; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 35 | for my $name (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 66 | my $other_value = $self->get_nested_hash_value( $params, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 66 | ▶ | DEBUG_CONSTRAINTS && debug( NAME => $name, VALUE => $value ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 66 | my $ok = _values_eq( $value, $other_value ); | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 66 | ▶ | if ( $self->not ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 28 | ▶ | if ( $value eq $EMPTY_STR ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # no error if both values are empty and not(1) is set | ||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | elsif ($ok) { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 6 | push @failed, $name; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | elsif ( !$ok ) { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 11 | push @failed, $name; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 66 | $values{$name} = $other_value; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # special case for $self->not() | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # no errors if all values are empty | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 35 | ▶ | if ( $self->not | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->not and $value eq $HTML::FormFu::Constraint::Equal::EMPTY_STR and &all(sub {
not defined $_ or $_ eq $EMPTY_STR;
}
, values %values)
$self->not and $value eq $HTML::FormFu::Constraint::Equal::EMPTY_STR
MC/DC100%3/3
$self->not and $value eq $HTML::FormFu::Constraint::Equal::EMPTY_STR and &all(sub {
not defined $_ or $_ eq $EMPTY_STR;
}
, values %values)
$self->not
$value eq $HTML::FormFu::Constraint::Equal::EMPTY_STR
&all(sub {
not defined $_ or $_ eq $EMPTY_STR;
}
, values %values)
Truth table100%4/4
A and B and C
A= $self->notB= $value eq $HTML::FormFu::Constraint::Equal::EMPTY_STRC= &all(sub {
not defined $_ or $_ eq $EMPTY_STR;
}
, values %values)
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | && $value eq $EMPTY_STR | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 10 | ▶ | && all { !defined || $_ eq $EMPTY_STR } values %values ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 33 | ▶ | return $self->mk_errors( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | { pass => @failed ? 0 : 1, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | failed => \@failed, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | names => [ $self->nested_name, @names ], | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 71 | ▶ | sub _values_eq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_values_eq: called CC=10 SCAR=23.9
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 71 | my ( $v1, $v2 ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | # the params should be coming from a CGI.pm compatible query object, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # so the value is either a string or an arrayref of strings | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 71 | ▶ | return 1 if !defined $v1 && !defined $v2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $v1 or defined $v2
MC/DC0%0/2
defined $v1 or defined $v2
defined $v1
defined $v2
Truth table33%1/3
A or B
A= defined $v1B= defined $v2
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 71 | ▶ | return if !defined $v1 || !defined $v2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $v1 and defined $v2
MC/DC50%1/2
defined $v1 and defined $v2
defined $v1
defined $v2
Truth table66%2/3
A and B
A= defined $v1B= defined $v2
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 69 | ▶ | if ( !ref $v1 && !ref $v2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
ref $v1 || ref $v2
MC/DC50%1/2
ref $v1 || ref $v2
ref $v1
ref $v2
Truth table66%2/3
A || B
A= ref $v1B= ref $v2
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 59 | ▶ | return 1 if $v1 eq $v2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ▶ | elsif ( ( ref $v1 eq 'ARRAY' ) && ( ref $v2 eq 'ARRAY' ) ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $v1 eq "ARRAY" and ref $v2 eq "ARRAY"
MC/DC50%1/2
ref $v1 eq "ARRAY" and ref $v2 eq "ARRAY"
ref $v1 eq "ARRAY"
ref $v2 eq "ARRAY"
Truth table66%2/3
A and B
A= ref $v1 eq "ARRAY"B= ref $v2 eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 8 | return _arrays_eq( $v1, $v2 ); | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 25 | return; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | ▶ | sub _arrays_eq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_arrays_eq: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | my @a1 = sort @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 8 | my @a2 = sort @{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 8 | ▶ | return if scalar @a1 != scalar @a2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 8 | for my $i ( 0 .. $#a1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 104 | 15 | ▶ | return if $a1[$i] ne $a2[$i]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 8 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub _localize_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_localize_args: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return $self->parent->label; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 11 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||||||||||||||||