| 1 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Constraint::Equal; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | $HTML::FormFu::Constraint::Equal::VERSION = '2.06'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Multi-field Equality Constraint | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | extends 'HTML::FormFu::Constraint'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | with 'HTML::FormFu::Role::Constraint::Others'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | use HTML::FormFu::Util qw( | |||||||||||||||||||||||||||||||||||||||||
| 13 | DEBUG_CONSTRAINTS | ||||||||||||||||||||||||||||||||||||||||||
| 14 | debug | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use List::Util 1.33 qw( all ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | our $EMPTY_STR = q{}; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | sub process { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 35 | ▶ | my ( $self, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=15 SCAR=27.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 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 {
$self->not and $value eq $HTML::FormFu::Constraint::Equal::EMPTY_STR
MC/DC0%0/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 table50%2/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 | 9 | ▶ | && 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 | sub _values_eq { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 71 | ▶ | my ( $v1, $v2 ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_values_eq: called CC=10 SCAR=23.9
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | sub _arrays_eq { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | my @a1 = sort @{ $_[0] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_arrays_eq: called CC=4 SCAR=14.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 | sub _localize_args { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_localize_args: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return $self->parent->label; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 9 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | HTML::FormFu::Constraint::Equal - Multi-field Equality Constraint | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | version 2.06 | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | - type: Password | ||||||||||||||||||||||||||||||||||||||||||
| 137 | name: password | ||||||||||||||||||||||||||||||||||||||||||
| 138 | constraints: | ||||||||||||||||||||||||||||||||||||||||||
| 139 | - type: Equal | ||||||||||||||||||||||||||||||||||||||||||
| 140 | others: repeat_password | ||||||||||||||||||||||||||||||||||||||||||
| 141 | - type: Password | ||||||||||||||||||||||||||||||||||||||||||
| 142 | name: repeat_password | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | All fields named in L<HTML::FormFu::Role::Constraint::Others/others> must have an equal value to the field this | ||||||||||||||||||||||||||||||||||||||||||
| 147 | constraint is attached to. | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | Is a sub-class of, and inherits methods from | ||||||||||||||||||||||||||||||||||||||||||
| 152 | L<HTML::FormFu::Role::Constraint::Others>, L<HTML::FormFu::Constraint> | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | L<HTML::FormFu> | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | Carl Franks C<cfranks@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | This library is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 163 | the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | Carl Franks <cpan@fireartist.com> | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | This software is copyright (c) 2018 by Carl Franks. | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 174 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | =cut | ||||||||||||||||||||||||||||||||||||||||||