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

filter: Statementstmt 60.2% 85 / 141 Branchbran 42.8% 24 / 56 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 68.4% 13 / 19 Podpod 0.0% 0 / 8 totaltotal 54.4% 122 / 224 CC 29 SCAR 18.3
CC
29
Cov
55%
validator
12.0
transformer
12.0
plugin
12.0
CRAP 6.3
« lib/HTML/FormFu/Constraint/File/MIME.pm ↑ Summary lib/HTML/FormFu/ObjectUtil.pm »
1 114 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Role::Element::SingleValueField;
4 # ABSTRACT: role for single value fields
5 114 $HTML::FormFu::Role::Element::SingleValueField::VERSION = '2.09';
6 114 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 114 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶sub add_error {
Subroutine add_error: called CC=1 SCAR=0.0
Pod undocumented
11 9 my ( $self, @errors ) = @_;
12  
13 9 push @{ $self->_errors }, @errors;
14  
15 9 return;
16 }
17  
18 11 ▶sub deflator {
Subroutine deflator: called CC=3 SCAR=11.0
Pod undocumented
19 11 my ( $self, $arg ) = @_;
20 11 my @return;
21  
22 11 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 5 6 11
23 5 push @return, map { _single_deflator( $self, $_ ) } @$arg;
24 }
25 else {
26 6 push @return, _single_deflator( $self, $arg );
27 }
28  
29 11 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 11 0 11
30 }
31  
32 7 ▶sub filter {
Subroutine filter: called CC=3 SCAR=11.0
Pod undocumented
33 7 my ( $self, $arg ) = @_;
34 7 my @return;
35  
36 7 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 1 6 7
37 1 push @return, map { _single_filter( $self, $_ ) } @$arg;
38 }
39 else {
40 6 push @return, _single_filter( $self, $arg );
41 }
42  
43 7 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 7 0 7
44 }
45  
46 14 ▶sub constraint {
Subroutine constraint: called CC=3 SCAR=11.0
Pod undocumented
47 14 my ( $self, $arg ) = @_;
48 14 my @return;
49  
50 14 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 6 8 14
51 6 push @return, map { _single_constraint( $self, $_ ) } @$arg;
52 }
53 else {
54 8 push @return, _single_constraint( $self, $arg );
55 }
56  
57 14 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 13 1 14
58 }
59  
60 13 ▶sub inflator {
Subroutine inflator: called CC=3 SCAR=11.0
Pod undocumented
61 13 my ( $self, $arg ) = @_;
62 13 my @return;
63  
64 13 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 1 12 13
65 1 push @return, map { _single_inflator( $self, $_ ) } @$arg;
66 }
67 else {
68 12 push @return, _single_inflator( $self, $arg );
69 }
70  
71 13 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 13 0 13
72 }
73  
74 0 ▶sub validator {
Subroutine validator: not called CC=3 SCAR=24.8
Pod undocumented
75 0 my ( $self, $arg ) = @_;
76 0 my @return;
77  
78 0 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 0 0
79 0 push @return, map { _single_validator( $self, $_ ) } @$arg;
80 }
81 else {
82 0 push @return, _single_validator( $self, $arg );
83 }
84  
85 0 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 0 0 0
86 }
87  
88 0 ▶sub transformer {
Subroutine transformer: not called CC=3 SCAR=24.8
Pod undocumented
89 0 my ( $self, $arg ) = @_;
90 0 my @return;
91  
92 0 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 0 0
93 0 push @return, map { _single_transformer( $self, $_ ) } @$arg;
94 }
95 else {
96 0 push @return, _single_transformer( $self, $arg );
97 }
98  
99 0 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 0 0 0
100 }
101  
102 0 ▶sub plugin {
Subroutine plugin: not called CC=3 SCAR=24.8
Pod undocumented
103 0 my ( $self, $arg ) = @_;
104 0 my @return;
105  
106 0 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 0 0
107 0 push @return, map { _single_plugin( $self, $_ ) } @$arg;
108 }
109 else {
110 0 push @return, _single_plugin( $self, $arg );
111 }
112  
113 0 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 0 0 0
114 }
115  
116 114 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
117 114 *constraints = \&constraint;
118 114 *filters = \&filter;
119 114 *deflators = \&deflator;
120 114 *inflators = \&inflator;
121 114 *validators = \&validator;
122 114 *transformers = \&transformer;
123 114 *plugins = \&plugin;
124 }
125  
126 11 ▶sub _single_deflator {
Subroutine _single_deflator: called CC=3 SCAR=11.1
127 11 my ( $self, $arg ) = @_;
128  
129 11 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 1 10 11
elsif (ref $arg eq 'HASH') { } 10 0 10
130 1 $arg = { type => $arg };
131 }
132 elsif ( ref $arg eq 'HASH' ) {
133 10 $arg = {%$arg}; # shallow clone
134 }
135 else {
136 0 croak 'invalid args';
137 }
138  
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 7 ▶sub _single_filter {
Subroutine _single_filter: called CC=3 SCAR=11.1
150 7 my ( $self, $arg ) = @_;
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  
163 7 my $type = delete $arg->{type};
164  
165 7 my $new = $self->_require_filter( $type, $arg );
166  
167 7 push @{ $self->_filters }, $new;
168  
169 7 return $new;
170 }
171  
172 15 ▶sub _single_constraint {
Subroutine _single_constraint: called CC=3 SCAR=11.1
173 15 my ( $self, $arg ) = @_;
174  
175 15 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 11 4 15
elsif (ref $arg eq 'HASH') { } 4 0 4
176 11 $arg = { type => $arg };
177 }
178 elsif ( ref $arg eq 'HASH' ) {
179 4 $arg = {%$arg}; # shallow clone
180 }
181 else {
182 0 croak 'invalid args';
183 }
184  
185  
186 15 my $type = delete $arg->{type};
187  
188 15 my $new = $self->_require_constraint( $type, $arg );
189  
190 15 push @{ $self->_constraints }, $new;
191  
192 15 return $new;
193 }
194  
195 13 ▶sub _single_inflator {
Subroutine _single_inflator: called CC=3 SCAR=11.7
196 13 my ( $self, $arg ) = @_;
197  
198 13 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 0 13 13
elsif (ref $arg eq 'HASH') { } 13 0 13
199 0 $arg = { type => $arg };
200 }
201 elsif ( ref $arg eq 'HASH' ) {
202 13 $arg = {%$arg}; # shallow clone
203 }
204 else {
205 0 croak 'invalid args';
206 }
207  
208  
209 13 my $type = delete $arg->{type};
210  
211 13 my $new = $self->_require_inflator( $type, $arg );
212  
213 13 push @{ $self->_inflators }, $new;
214  
215 13 return $new;
216 }
217  
218 0 ▶sub _single_validator {
Subroutine _single_validator: not called CC=3 SCAR=24.8
219 0 my ( $self, $arg ) = @_;
220  
221 0 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 0 0 0
elsif (ref $arg eq 'HASH') { } 0 0 0
222 0 $arg = { type => $arg };
223 }
224 elsif ( ref $arg eq 'HASH' ) {
225 0 $arg = {%$arg}; # shallow clone
226 }
227 else {
228 0 croak 'invalid args';
229 }
230  
231  
232 0 my $type = delete $arg->{type};
233  
234 0 my $new = $self->_require_validator( $type, $arg );
235  
236 0 push @{ $self->_validators }, $new;
237  
238 0 return $new;
239 }
240  
241 0 ▶sub _single_transformer {
Subroutine _single_transformer: not called CC=3 SCAR=24.8
242 0 my ( $self, $arg ) = @_;
243  
244 0 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 0 0 0
elsif (ref $arg eq 'HASH') { } 0 0 0
245 0 $arg = { type => $arg };
246 }
247 elsif ( ref $arg eq 'HASH' ) {
248 0 $arg = {%$arg}; # shallow clone
249 }
250 else {
251 0 croak 'invalid args';
252 }
253  
254  
255 0 my $type = delete $arg->{type};
256  
257 0 my $new = $self->_require_transformer( $type, $arg );
258  
259 0 push @{ $self->_transformers }, $new;
260  
261 0 return $new;
262 }
263  
264 0 ▶sub _single_plugin {
Subroutine _single_plugin: not called CC=3 SCAR=24.8
265 0 my ( $self, $arg ) = @_;
266  
267 0 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 0 0 0
elsif (ref $arg eq 'HASH') { } 0 0 0
268 0 $arg = { type => $arg };
269 }
270 elsif ( ref $arg eq 'HASH' ) {
271 0 $arg = {%$arg}; # shallow clone
272 }
273 else {
274 0 croak 'invalid args';
275 }
276  
277  
278 0 my $type = delete $arg->{type};
279  
280 0 my $new = $self->_require_plugin( $type, $arg );
281  
282 0 push @{ $self->_plugins }, $new;
283  
284 0 return $new;
285 }
286  
287 114 1;
288  
289 __END__
« lib/HTML/FormFu/Constraint/File/MIME.pm ↑ Summary lib/HTML/FormFu/ObjectUtil.pm »