lib/HTML/FormFu/Role/Element/SingleValueField.pm

filter: Statementstmt 60.1% 89 / 148 Branchbran 42.8% 24 / 56 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 68.4% 13 / 19 Podpod 0.0% 0 / 8 totaltotal 54.5% 126 / 231 SCAR 46.4
CC
29
Cov
55%
validator
12.0
transformer
12.0
plugin
12.0
CRAP 103.6
« lib/HTML/FormFu/Role/CreateChildren.pm ↑ Summary lib/HTML/FormFu/Constraint.pm »
1 99 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Role::Element::SingleValueField;
4 99 $HTML::FormFu::Role::Element::SingleValueField::VERSION = '2.06';
5 99 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 99 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub add_error {
10 7 ▶ my ( $self, @errors ) = @_;
Subroutine add_error: called CC=1 SCAR=0.0
Pod undocumented
11  
12 7 push @{ $self->_errors }, @errors;
13  
14 7 return;
15 }
16  
17 sub deflator {
18 11 ▶ my ( $self, $arg ) = @_;
Subroutine deflator: called CC=3 SCAR=11.0
Pod undocumented
19 11 my @return;
20  
21 11 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 5 6 11
22 5 push @return, map { _single_deflator( $self, $_ ) } @$arg;
23 }
24 else {
25 6 push @return, _single_deflator( $self, $arg );
26 }
27  
28 11 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 11 0 11
29 }
30  
31 sub filter {
32 7 ▶ my ( $self, $arg ) = @_;
Subroutine filter: called CC=3 SCAR=11.0
Pod undocumented
33 7 my @return;
34  
35 7 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 1 6 7
36 1 push @return, map { _single_filter( $self, $_ ) } @$arg;
37 }
38 else {
39 6 push @return, _single_filter( $self, $arg );
40 }
41  
42 7 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 7 0 7
43 }
44  
45 sub constraint {
46 12 ▶ my ( $self, $arg ) = @_;
Subroutine constraint: called CC=3 SCAR=11.0
Pod undocumented
47 12 my @return;
48  
49 12 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 4 8 12
50 4 push @return, map { _single_constraint( $self, $_ ) } @$arg;
51 }
52 else {
53 8 push @return, _single_constraint( $self, $arg );
54 }
55  
56 12 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 11 1 12
57 }
58  
59 sub inflator {
60 13 ▶ my ( $self, $arg ) = @_;
Subroutine inflator: called CC=3 SCAR=11.0
Pod undocumented
61 13 my @return;
62  
63 13 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 1 12 13
64 1 push @return, map { _single_inflator( $self, $_ ) } @$arg;
65 }
66 else {
67 12 push @return, _single_inflator( $self, $arg );
68 }
69  
70 13 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 13 0 13
71 }
72  
73 sub validator {
74 0 ▶ my ( $self, $arg ) = @_;
Subroutine validator: not called CC=3 SCAR=24.8
Pod undocumented
75 0 my @return;
76  
77 0 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 0 0
78 0 push @return, map { _single_validator( $self, $_ ) } @$arg;
79 }
80 else {
81 0 push @return, _single_validator( $self, $arg );
82 }
83  
84 0 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 0 0 0
85 }
86  
87 sub transformer {
88 0 ▶ my ( $self, $arg ) = @_;
Subroutine transformer: not called CC=3 SCAR=24.8
Pod undocumented
89 0 my @return;
90  
91 0 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 0 0
92 0 push @return, map { _single_transformer( $self, $_ ) } @$arg;
93 }
94 else {
95 0 push @return, _single_transformer( $self, $arg );
96 }
97  
98 0 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 0 0 0
99 }
100  
101 sub plugin {
102 0 ▶ my ( $self, $arg ) = @_;
Subroutine plugin: not called CC=3 SCAR=24.8
Pod undocumented
103 0 my @return;
104  
105 0 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 0 0
106 0 push @return, map { _single_plugin( $self, $_ ) } @$arg;
107 }
108 else {
109 0 push @return, _single_plugin( $self, $arg );
110 }
111  
112 0 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 0 0 0
113 }
114  
115 BEGIN {
116 99 ▶ *constraints = \&constraint;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 99 *filters = \&filter;
118 99 *deflators = \&deflator;
119 99 *inflators = \&inflator;
120 99 *validators = \&validator;
121 99 *transformers = \&transformer;
122 99 *plugins = \&plugin;
123 }
124  
125 sub _single_deflator {
126 11 ▶ my ( $self, $arg ) = @_;
Subroutine _single_deflator: called CC=3 SCAR=11.1
127  
128 11 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 1 10 11
elsif (ref $arg eq 'HASH') { } 10 0 10
129 1 $arg = { type => $arg };
130 }
131 elsif ( ref $arg eq 'HASH' ) {
132 10 $arg = {%$arg}; # shallow clone
133 }
134 else {
135 0 croak 'invalid args';
136 }
137  
138 11 my @return;
139  
140 11 my $type = delete $arg->{type};
141  
142 11 my $new = $self->_require_deflator( $type, $arg );
143  
144 11 push @{ $self->_deflators }, $new;
145  
146 11 return $new;
147 }
148  
149 sub _single_filter {
150 7 ▶ my ( $self, $arg ) = @_;
Subroutine _single_filter: called CC=3 SCAR=11.1
151  
152 7 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 1 6 7
elsif (ref $arg eq 'HASH') { } 6 0 6
153 1 $arg = { type => $arg };
154 }
155 elsif ( ref $arg eq 'HASH' ) {
156 6 $arg = {%$arg}; # shallow clone
157 }
158 else {
159 0 croak 'invalid args';
160 }
161  
162 7 my @return;
163  
164 7 my $type = delete $arg->{type};
165  
166 7 my $new = $self->_require_filter( $type, $arg );
167  
168 7 push @{ $self->_filters }, $new;
169  
170 7 return $new;
171 }
172  
173 sub _single_constraint {
174 13 ▶ my ( $self, $arg ) = @_;
Subroutine _single_constraint: called CC=3 SCAR=11.1
175  
176 13 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 11 2 13
elsif (ref $arg eq 'HASH') { } 2 0 2
177 11 $arg = { type => $arg };
178 }
179 elsif ( ref $arg eq 'HASH' ) {
180 2 $arg = {%$arg}; # shallow clone
181 }
182 else {
183 0 croak 'invalid args';
184 }
185  
186 13 my @return;
187  
188 13 my $type = delete $arg->{type};
189  
190 13 my $new = $self->_require_constraint( $type, $arg );
191  
192 13 push @{ $self->_constraints }, $new;
193  
194 13 return $new;
195 }
196  
197 sub _single_inflator {
198 13 ▶ my ( $self, $arg ) = @_;
Subroutine _single_inflator: called CC=3 SCAR=11.5
199  
200 13 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 0 13 13
elsif (ref $arg eq 'HASH') { } 13 0 13
201 0 $arg = { type => $arg };
202 }
203 elsif ( ref $arg eq 'HASH' ) {
204 13 $arg = {%$arg}; # shallow clone
205 }
206 else {
207 0 croak 'invalid args';
208 }
209  
210 13 my @return;
211  
212 13 my $type = delete $arg->{type};
213  
214 13 my $new = $self->_require_inflator( $type, $arg );
215  
216 13 push @{ $self->_inflators }, $new;
217  
218 13 return $new;
219 }
220  
221 sub _single_validator {
222 0 ▶ my ( $self, $arg ) = @_;
Subroutine _single_validator: not called CC=3 SCAR=24.8
223  
224 0 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 0 0 0
elsif (ref $arg eq 'HASH') { } 0 0 0
225 0 $arg = { type => $arg };
226 }
227 elsif ( ref $arg eq 'HASH' ) {
228 0 $arg = {%$arg}; # shallow clone
229 }
230 else {
231 0 croak 'invalid args';
232 }
233  
234 0 my @return;
235  
236 0 my $type = delete $arg->{type};
237  
238 0 my $new = $self->_require_validator( $type, $arg );
239  
240 0 push @{ $self->_validators }, $new;
241  
242 0 return $new;
243 }
244  
245 sub _single_transformer {
246 0 ▶ my ( $self, $arg ) = @_;
Subroutine _single_transformer: not called CC=3 SCAR=24.8
247  
248 0 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 0 0 0
elsif (ref $arg eq 'HASH') { } 0 0 0
249 0 $arg = { type => $arg };
250 }
251 elsif ( ref $arg eq 'HASH' ) {
252 0 $arg = {%$arg}; # shallow clone
253 }
254 else {
255 0 croak 'invalid args';
256 }
257  
258 0 my @return;
259  
260 0 my $type = delete $arg->{type};
261  
262 0 my $new = $self->_require_transformer( $type, $arg );
263  
264 0 push @{ $self->_transformers }, $new;
265  
266 0 return $new;
267 }
268  
269 sub _single_plugin {
270 0 ▶ my ( $self, $arg ) = @_;
Subroutine _single_plugin: not called CC=3 SCAR=24.8
271  
272 0 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 0 0 0
elsif (ref $arg eq 'HASH') { } 0 0 0
273 0 $arg = { type => $arg };
274 }
275 elsif ( ref $arg eq 'HASH' ) {
276 0 $arg = {%$arg}; # shallow clone
277 }
278 else {
279 0 croak 'invalid args';
280 }
281  
282 0 my @return;
283  
284 0 my $type = delete $arg->{type};
285  
286 0 my $new = $self->_require_plugin( $type, $arg );
287  
288 0 push @{ $self->_plugins }, $new;
289  
290 0 return $new;
291 }
292  
293 99 1;
294  
295 __END__
296  
297 =pod
298  
299 =encoding UTF-8
300  
301 =head1 NAME
302  
303 HTML::FormFu::Role::Element::SingleValueField
304  
305 =head1 VERSION
306  
307 version 2.06
308  
309 =head1 AUTHOR
310  
311 Carl Franks <cpan@fireartist.com>
312  
313 =head1 COPYRIGHT AND LICENSE
314  
315 This software is copyright (c) 2018 by Carl Franks.
316  
317 This is free software; you can redistribute it and/or modify it under
318 the same terms as the Perl 5 programming language system itself.
319  
320 =cut
« lib/HTML/FormFu/Role/CreateChildren.pm ↑ Summary lib/HTML/FormFu/Constraint.pm »