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

filter: Statementstmt 82.7% 125 / 151 Branchbran 54.8% 34 / 62 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 95.0% 19 / 20 Podpod 0.0% 0 / 9 totaltotal 73.5% 178 / 242 CC 32 SCAR 14.6
CC
32
Cov
75%
nested_name
20.0
validator
3.4
transformer
3.4
CRAP 4.3
« lib/HTML/FormFu/Role/Populate.pm ↑ Summary lib/HTML/FormFu/Validator.pm »
1 343 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Role::Element::FieldMethods;
4 # ABSTRACT: Role for field methods
5 343 $HTML::FormFu::Role::Element::FieldMethods::VERSION = '2.09';
6 343 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 343 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub nested_name {
Subroutine nested_name: not called CC=4 SCAR=30.0
Pod undocumented
11 0 my ($self) = @_;
12  
13 0 ▶ croak 'cannot set nested_name' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 0 0
14  
15 0 ▶ return if !defined $self->name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->name 0 0 0
16  
17 0 my @names = $self->nested_names;
18  
19 0 ▶ if ( $self->form->nested_subscript ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form->nested_subscript) { } 0 0 0
20 0 my $name = shift @names;
21 0 map { $name .= "[$_]" } @names;
22  
23 # TODO - Mario Minati 19.05.2009
24 # Does this (name formatted as '[name]') collide with FF::Model::HashRef as
25 # it uses /_\d/ to parse repeatable names?
26 0 return $name;
27 }
28 else {
29 0 return join ".", @names;
30 }
31 }
32  
33 228 ▶sub add_error {
Subroutine add_error: called CC=1 SCAR=0.0
Pod undocumented
34 228 my ( $self, @errors ) = @_;
35  
36 228 push @{ $self->_errors }, @errors;
37  
38 228 return;
39 }
40  
41 13 ▶sub deflator {
Subroutine deflator: called CC=3 SCAR=11.0
Pod undocumented
42 13 my ( $self, $arg ) = @_;
43 13 my @return;
44  
45 13 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 4 9 13
46 4 push @return, map { _single_deflator( $self, $_ ) } @$arg;
47 }
48 else {
49 9 push @return, _single_deflator( $self, $arg );
50 }
51  
52 13 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 13 0 13
53 }
54  
55 29 ▶sub filter {
Subroutine filter: called CC=3 SCAR=11.0
Pod undocumented
56 29 my ( $self, $arg ) = @_;
57 29 my @return;
58  
59 29 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 12 17 29
60 12 push @return, map { _single_filter( $self, $_ ) } @$arg;
61 }
62 else {
63 17 push @return, _single_filter( $self, $arg );
64 }
65  
66 29 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 29 0 29
67 }
68  
69 140 ▶sub constraint {
Subroutine constraint: called CC=3 SCAR=11.0
Pod undocumented
70 140 my ( $self, $arg ) = @_;
71 140 my @return;
72  
73 140 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 60 80 140
74 60 push @return, map { _single_constraint( $self, $_ ) } @$arg;
75 }
76 else {
77 80 push @return, _single_constraint( $self, $arg );
78 }
79  
80 140 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 132 8 140
81 }
82  
83 14 ▶sub inflator {
Subroutine inflator: called CC=3 SCAR=11.0
Pod undocumented
84 14 my ( $self, $arg ) = @_;
85 14 my @return;
86  
87 14 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 3 11 14
88 3 push @return, map { _single_inflator( $self, $_ ) } @$arg;
89 }
90 else {
91 11 push @return, _single_inflator( $self, $arg );
92 }
93  
94 14 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 14 0 14
95 }
96  
97 3 ▶sub validator {
Subroutine validator: called CC=3 SCAR=12.3
Pod undocumented
98 3 my ( $self, $arg ) = @_;
99 3 my @return;
100  
101 3 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 3 3
102 0 push @return, map { _single_validator( $self, $_ ) } @$arg;
103 }
104 else {
105 3 push @return, _single_validator( $self, $arg );
106 }
107  
108 3 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 3 0 3
109 }
110  
111 5 ▶sub transformer {
Subroutine transformer: called CC=3 SCAR=12.3
Pod undocumented
112 5 my ( $self, $arg ) = @_;
113 5 my @return;
114  
115 5 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 5 5
116 0 push @return, map { _single_transformer( $self, $_ ) } @$arg;
117 }
118 else {
119 5 push @return, _single_transformer( $self, $arg );
120 }
121  
122 5 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 5 0 5
123 }
124  
125 1 ▶sub plugin {
Subroutine plugin: called CC=3 SCAR=12.3
Pod undocumented
126 1 my ( $self, $arg ) = @_;
127 1 my @return;
128  
129 1 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 1 1
130 0 push @return, map { _single_plugin( $self, $_ ) } @$arg;
131 }
132 else {
133 1 push @return, _single_plugin( $self, $arg );
134 }
135  
136 1 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 1 0 1
137 }
138  
139 343 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
140 343 *constraints = \&constraint;
141 343 *filters = \&filter;
142 343 *deflators = \&deflator;
143 343 *inflators = \&inflator;
144 343 *validators = \&validator;
145 343 *transformers = \&transformer;
146 343 *plugins = \&plugin;
147 }
148  
149 13 ▶sub _single_deflator {
Subroutine _single_deflator: called CC=3 SCAR=11.1
150 13 my ( $self, $arg ) = @_;
151  
152 13 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 1 12 13
elsif (ref $arg eq 'HASH') { } 12 0 12
153 1 $arg = { type => $arg };
154 }
155 elsif ( ref $arg eq 'HASH' ) {
156 12 $arg = {%$arg}; # shallow clone
157 }
158 else {
159 0 croak 'invalid args';
160 }
161  
162  
163 13 my $type = delete $arg->{type};
164  
165 13 my $new = $self->_require_deflator( $type, $arg );
166  
167 13 push @{ $self->_deflators }, $new;
168  
169 13 return $new;
170 }
171  
172 29 ▶sub _single_filter {
Subroutine _single_filter: called CC=3 SCAR=11.1
173 29 my ( $self, $arg ) = @_;
174  
175 29 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 19 10 29
elsif (ref $arg eq 'HASH') { } 10 0 10
176 19 $arg = { type => $arg };
177 }
178 elsif ( ref $arg eq 'HASH' ) {
179 10 $arg = {%$arg}; # shallow clone
180 }
181 else {
182 0 croak 'invalid args';
183 }
184  
185  
186 29 my $type = delete $arg->{type};
187  
188 29 my $new = $self->_require_filter( $type, $arg );
189  
190 29 push @{ $self->_filters }, $new;
191  
192 29 return $new;
193 }
194  
195 148 ▶sub _single_constraint {
Subroutine _single_constraint: called CC=3 SCAR=11.1
196 148 my ( $self, $arg ) = @_;
197  
198 148 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 88 60 148
elsif (ref $arg eq 'HASH') { } 60 0 60
199 88 $arg = { type => $arg };
200 }
201 elsif ( ref $arg eq 'HASH' ) {
202 60 $arg = {%$arg}; # shallow clone
203 }
204 else {
205 0 croak 'invalid args';
206 }
207  
208  
209 148 my $type = delete $arg->{type};
210  
211 148 my $new = $self->_require_constraint( $type, $arg );
212  
213 148 push @{ $self->_constraints }, $new;
214  
215 148 return $new;
216 }
217  
218 14 ▶sub _single_inflator {
Subroutine _single_inflator: called CC=3 SCAR=11.1
219 14 my ( $self, $arg ) = @_;
220  
221 14 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 9 5 14
elsif (ref $arg eq 'HASH') { } 5 0 5
222 9 $arg = { type => $arg };
223 }
224 elsif ( ref $arg eq 'HASH' ) {
225 5 $arg = {%$arg}; # shallow clone
226 }
227 else {
228 0 croak 'invalid args';
229 }
230  
231  
232 14 my $type = delete $arg->{type};
233  
234 14 my $new = $self->_require_inflator( $type, $arg );
235  
236 14 push @{ $self->_inflators }, $new;
237  
238 14 return $new;
239 }
240  
241 3 ▶sub _single_validator {
Subroutine _single_validator: called CC=3 SCAR=12.3
242 3 my ( $self, $arg ) = @_;
243  
244 3 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 3 0 3
elsif (ref $arg eq 'HASH') { } 0 0 0
245 3 $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 3 my $type = delete $arg->{type};
256  
257 3 my $new = $self->_require_validator( $type, $arg );
258  
259 3 push @{ $self->_validators }, $new;
260  
261 3 return $new;
262 }
263  
264 5 ▶sub _single_transformer {
Subroutine _single_transformer: called CC=3 SCAR=12.3
265 5 my ( $self, $arg ) = @_;
266  
267 5 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 5 0 5
elsif (ref $arg eq 'HASH') { } 0 0 0
268 5 $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 5 my $type = delete $arg->{type};
279  
280 5 my $new = $self->_require_transformer( $type, $arg );
281  
282 5 push @{ $self->_transformers }, $new;
283  
284 5 return $new;
285 }
286  
287 1 ▶sub _single_plugin {
Subroutine _single_plugin: called CC=3 SCAR=12.3
288 1 my ( $self, $arg ) = @_;
289  
290 1 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 1 0 1
elsif (ref $arg eq 'HASH') { } 0 0 0
291 1 $arg = { type => $arg };
292 }
293 elsif ( ref $arg eq 'HASH' ) {
294 0 $arg = {%$arg}; # shallow clone
295 }
296 else {
297 0 croak 'invalid args';
298 }
299  
300  
301 1 my $type = delete $arg->{type};
302  
303 1 my $new = $self->_require_plugin( $type, $arg );
304  
305 1 push @{ $self->_plugins }, $new;
306  
307 1 return $new;
308 }
309  
310 343 1;
311  
312 __END__
« lib/HTML/FormFu/Role/Populate.pm ↑ Summary lib/HTML/FormFu/Validator.pm »