lib/HTML/FormFu/Constraint/AllOrNone.pm

filter: Statementstmt 100% 38 / 38 Branchbran 85.0% 17 / 20 Conditioncond 75.0% 9 / 12 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 86.9% 73 / 84 SCAR 27.8
CC
16
Cov
91%
process
14.3
constrain_value
3.0
BEGIN
1.0
CRAP 16.2
« lib/HTML/FormFu/OutputProcessor/Indent.pm ↑ Summary lib/HTML/FormFu/Element/SimpleTable.pm »
1 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Constraint::AllOrNone;
4 8 $HTML::FormFu::Constraint::AllOrNone::VERSION = '2.06';
5 # ABSTRACT: Multi-field All or None Constraint
6  
7 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 extends 'HTML::FormFu::Constraint';
9  
10 8 with 'HTML::FormFu::Role::Constraint::Others';
11  
12 sub process {
13 18 ▶ my ( $self, $params ) = @_;
Subroutine process: called CC=14 SCAR=26.6
Pod undocumented
14  
15 # check when condition
16 18 ▶ return if !$self->_process_when($params);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_process_when($params) 0 18 18
17  
18 18 my $others = $self->others;
19 18 ▶ return if !defined $others;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $others 0 18 18
20  
21 18 my @names = ( $self->nested_name );
22 18 ▶ push @names, ref $others ? @{$others} : $others;
Branch: 1 branch
BranchTrueFalseTotal
ref $others ? : 11 7 18
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
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 6 48 54
31 6 my @errors = eval { $self->constrain_values( $value, $params ) };
32  
33 6 ▶ if ( !@errors && !$@ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@errors or $@) 6 0 6
Condition33%1/3
@errors or $@
l!l&&r!l&&!r
006
MC/DC0%0/2
@errors or $@
@errors $@
Truth table33%1/3
A or B
A= @errorsB= $@
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($ok and not $@) 25 23 48
Condition66%2/3
$ok and not $@
!ll&&!rl&&r
23025
MC/DC50%1/2
$ok and not $@
$ok not $@
Truth table66%2/3
A and not(B)
A= $okB= not $@
ABresult
0X0
100
111
41 25 $seen = 1;
42 }
43 }
44  
45 54 ▶ if ( !$seen ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen) 23 31 54
46 23 push @failed, $name;
47 }
48 }
49  
50 18 ▶ my $pass = @failed && scalar @failed != scalar @names ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
@failed && scalar @failed != scalar @names ? : 7 11 18
Condition100%3/3
@failed and scalar @failed != scalar @names
!ll&&!rl&&r
657
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
ABresult
0X0
100
111
51  
52 18 ▶ return $self->mk_errors(
Branch: 1 branch
BranchTrueFalseTotal
$pass ? : 11 7 18
53 { pass => $pass,
54 failed => $pass ? [] : \@failed,
55 names => \@names,
56 } );
57 }
58  
59 sub constrain_value {
60 60 ▶ my ( $self, $value ) = @_;
Subroutine constrain_value: called CC=3 SCAR=11.0
Pod undocumented
61  
62 60 ▶ return 0 if !defined $value || $value eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or $value eq "" 23 37 60
Condition100%3/3
not defined $value or $value eq ""
l!l&&r!l&&!r
17637
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 ""
ABresult
1X1
011
000
63  
64 37 return 1;
65 }
66  
67 8 __PACKAGE__->meta->make_immutable;
68  
69 8 1;
70  
71 __END__
72  
73 =pod
74  
75 =encoding UTF-8
76  
77 =head1 NAME
78  
79 HTML::FormFu::Constraint::AllOrNone - Multi-field All or None Constraint
80  
81 =head1 VERSION
82  
83 version 2.06
84  
85 =head1 SYNOPSIS
86  
87 type: AllOrNone
88 name: foo
89 others: [bar, baz]
90  
91 =head1 DESCRIPTION
92  
93 Ensure that either all or none of the named fields are present.
94  
95 By default, if some but not all fields are submitted, errors are attached to
96 those fields which weren't submitted. This behaviour can be changed by setting
97 any of L<HTML::FormFu::Role::Constraint::Others/attach_errors_to_base>,
98 L<HTML::FormFu::Role::Constraint::Others/attach_errors_to_others> or
99 L<HTML::FormFu::Role::Constraint::Others/attach_errors_to>.
100  
101 This constraint doesn't honour the C<not()> value.
102  
103 =head1 SEE ALSO
104  
105 Is a sub-class of, and inherits methods from
106 L<HTML::FormFu::Role::Constraint::Others>, L<HTML::FormFu::Constraint>
107  
108 L<HTML::FormFu>
109  
110 =head1 AUTHOR
111  
112 Carl Franks C<cfranks@cpan.org>
113  
114 =head1 LICENSE
115  
116 This library is free software, you can redistribute it and/or modify it under
117 the same terms as Perl itself.
118  
119 =head1 AUTHOR
120  
121 Carl Franks <cpan@fireartist.com>
122  
123 =head1 COPYRIGHT AND LICENSE
124  
125 This software is copyright (c) 2018 by Carl Franks.
126  
127 This is free software; you can redistribute it and/or modify it under
128 the same terms as the Perl 5 programming language system itself.
129  
130 =cut
« lib/HTML/FormFu/OutputProcessor/Indent.pm ↑ Summary lib/HTML/FormFu/Element/SimpleTable.pm »