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

filter: Statementstmt 80.3% 405 / 504 Branchbran 57.9% 138 / 238 Conditioncond 72.5% 111 / 153 MC/DCmcdc 58.5% 48 / 82 Subroutinesub 75.8% 47 / 62 Podpod 42.1% 8 / 19 totaltotal 71.5% 757 / 1058 CC 185 SCAR 28.5
CC
185
Cov
73%
_string_field_start
72.0
_render_error_class
57.0
_string_field_end
56.0
CRAP 17.4
« lib/HTML/FormFu/Role/Element/Group.pm ↑ Summary lib/HTML/FormFu/Element/Block.pm »
1 415 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Role::Element::Field;
4 415 $HTML::FormFu::Role::Element::Field::VERSION = '2.09';
5 # ABSTRACT: Role for all form-field elements
6  
7 415 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 415 ▶use MooseX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 415 with 'HTML::FormFu::Role::ContainsElementsSharedWithField',
11 'HTML::FormFu::Role::NestedHashUtils',
12 'HTML::FormFu::Role::FormBlockAndFieldMethods',
13 'HTML::FormFu::Role::Element::Layout';
14  
15 415 ▶use HTML::FormFu::Attribute qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
16 mk_attrs
17 mk_output_accessors
18 415 );
19 415 ▶use HTML::FormFu::Constants qw( $EMPTY_STR );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 415 ▶use HTML::FormFu::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 _parse_args append_xml_attribute
22 xml_escape require_class
23 process_attrs _filter_components
24 415 );
25 415 ▶use Class::MOP::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 415 ▶use Clone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 415 ▶use List::Util 1.45 qw( uniq );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 415 ▶use Carp qw( croak carp );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 415 __PACKAGE__->mk_attrs( qw(
31 comment_attributes
32 container_attributes
33 label_attributes
34 error_attributes
35 error_container_attributes
36 ) );
37  
38 415 has _constraints => ( is => 'rw', traits => ['Chained'] );
39 415 has _filters => ( is => 'rw', traits => ['Chained'] );
40 415 has _inflators => ( is => 'rw', traits => ['Chained'] );
41 415 has _deflators => ( is => 'rw', traits => ['Chained'] );
42 415 has _validators => ( is => 'rw', traits => ['Chained'] );
43 415 has _transformers => ( is => 'rw', traits => ['Chained'] );
44 415 has _plugins => ( is => 'rw', traits => ['Chained'] );
45 415 has _errors => ( is => 'rw', traits => ['Chained'] );
46 415 has container_tag => ( is => 'rw', traits => ['Chained'] );
47 415 has field_filename => ( is => 'rw', traits => ['Chained'] );
48 415 has label_filename => ( is => 'rw', traits => ['Chained'] );
49 415 has label_tag => ( is => 'rw', traits => ['Chained'] );
50 415 has retain_default => ( is => 'rw', traits => ['Chained'] );
51 415 has force_default => ( is => 'rw', traits => ['Chained'] );
52 415 has javascript => ( is => 'rw', traits => ['Chained'] );
53 415 has non_param => ( is => 'rw', traits => ['Chained'] );
54 415 has reverse_single => ( is => 'rw', traits => ['Chained'] );
55 415 has reverse_multi => ( is => 'rw', traits => ['Chained'] );
56 415 has multi_value => ( is => 'rw', traits => ['Chained'] );
57 415 has original_name => ( is => 'rw', traits => ['Chained'] );
58 415 has original_nested_name => ( is => 'rw', traits => ['Chained'] );
59 415 has default_empty_value => ( is => 'rw', traits => ['Chained'] );
60  
61 415 __PACKAGE__->mk_output_accessors(qw( comment label value ));
62  
63 415 alias( "default", "value" );
64 415 alias( "default_xml", "value_xml" );
65 415 alias( "default_loc", "value_loc" );
66  
67 1365 ▶after BUILD => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
68 1365 my $self = shift;
69  
70 1365 $self->_constraints( [] );
71 1365 $self->_filters( [] );
72 1365 $self->_deflators( [] );
73 1365 $self->_inflators( [] );
74 1365 $self->_validators( [] );
75 1365 $self->_transformers( [] );
76 1365 $self->_plugins( [] );
77 1365 $self->_errors( [] );
78 1365 $self->comment_attributes( {} );
79 1365 $self->container_attributes( {} );
80 1365 $self->label_attributes( {} );
81 1365 $self->error_attributes( {} );
82 1365 $self->error_container_attributes( {} );
83 1365 $self->label_filename('field_layout_label');
84 1365 $self->label_tag('label');
85 1365 $self->container_tag('div');
86 1365 $self->is_field(1);
87  
88 1365 return;
89 415 };
90  
91 1045 ▶sub nested {
Subroutine nested: called CC=8 SCAR=20.9
Pod undocumented
92 1045 my ($self) = @_;
93  
94 1045 ▶ croak 'cannot set nested' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 1045 1045
95  
96 1045 ▶ if ( defined $self->name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->name) 1045 0 1045
97 1045 my $parent = $self;
98  
99 1045 ▶ while ( defined( $parent = $parent->parent ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($parent = $parent->parent)) 1327 790 2117
100  
101 1327 ▶ if ( $parent->can('is_field') && $parent->is_field ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->can('is_field') and $parent->is_field) { } 97 1230 1327
Condition100%3/3
$parent->can("is_field") and $parent->is_field
!ll&&!rl&&r
79044097
MC/DC100%2/2
$parent->can("is_field") and $parent->is_field
$parent->can("is_field") $parent->is_field
Truth table100%3/3
A and B
A= $parent->can("is_field")B= $parent->is_field
ABresult
0X0
100
111
102 97 ▶ return 1 if defined $parent->name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent->name 97 0 97
103 }
104 else {
105 1230 ▶ return 1 if defined $parent->nested_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent->nested_name 158 1072 1230
106 }
107 }
108 }
109  
110 790 return;
111 }
112  
113 20880 ▶sub nested_name {
Subroutine nested_name: called CC=4 SCAR=15.8
Pod undocumented
114 20880 my ($self) = @_;
115  
116 20880 ▶ croak 'cannot set nested_name' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 20880 20880
117  
118 20880 ▶ return if !defined $self->name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->name 260 20620 20880
119  
120 20620 my @names = $self->nested_names;
121  
122 20620 ▶ if ( $self->form->nested_subscript ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form->nested_subscript) { } 0 20620 20620
123 0 my $name = shift @names;
124 0 map { $name .= "[$_]" } @names;
125  
126 # TODO - Mario Minati 19.05.2009
127 # Does this (name formatted as '[name]') collide with FF::Model::HashRef as
128 # it uses /_\d/ to parse repeatable names?
129 0 return $name;
130 }
131 else {
132 20620 return join ".", @names;
133 }
134 }
135  
136 18590 ▶sub nested_names {
Subroutine nested_names: called CC=11 SCAR=24.0
Pod undocumented
137 18590 my ($self) = @_;
138  
139 18590 ▶ croak 'cannot set nested_names' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 18590 18590
140  
141 18590 ▶ if ( defined( my $name = $self->name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $self->name)) 18590 0 18590
142 18590 my @names;
143 18590 my $parent = $self;
144  
145 # micro optimization! this method's called a lot, so access
146 # parent hashkey directly, instead of calling parent()
147 18590 ▶ while ( defined( $parent = $parent->{parent} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($parent = $parent->{"parent"})) 30680 18590 49270
148  
149 30680 ▶ if ( $parent->can('is_field') && $parent->is_field ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($parent->can('is_field') and $parent->is_field) { } 535 30145 30680
elsif ($parent->can('is_repeatable') and $parent->is_repeatable) { } 3885 26260 30145
Condition100%3/3
$parent->can("is_field") and $parent->is_field
!ll&&!rl&&r
1859011555535
MC/DC100%2/2
$parent->can("is_field") and $parent->is_field
$parent->can("is_field") $parent->is_field
Truth table100%3/3
A and B
A= $parent->can("is_field")B= $parent->is_field
ABresult
0X0
100
111
150  
151 # handling Field
152 535 ▶ push @names, $parent->name
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent->name 451 84 535
153 if defined $parent->name;
154 }
155 ▶ elsif ( $parent->can('is_repeatable') && $parent->is_repeatable ) {
Condition100%3/3
$parent->can("is_repeatable") and $parent->is_repeatable
!ll&&!rl&&r
1859076703885
MC/DC100%2/2
$parent->can("is_repeatable") and $parent->is_repeatable
$parent->can("is_repeatable") $parent->is_repeatable
Truth table100%3/3
A and B
A= $parent->can("is_repeatable")B= $parent->is_repeatable
ABresult
0X0
100
111
156  
157 # handling Repeatable
158 # ignore Repeatables nested_name attribute as it is provided
159 # by the childrens Block elements
160 }
161 else {
162  
163 # handling 'not Field' and 'not Repeatable'
164 26260 ▶ push @names, $parent->nested_name
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent->nested_name 3884 22376 26260
165 if defined $parent->nested_name;
166 }
167 }
168  
169 18590 ▶ if (@names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names) 4213 14377 18590
170 4213 return reverse $name, @names;
171 }
172 }
173  
174 14377 return ( $self->name );
175 }
176  
177 432 ▶sub build_original_nested_name {
Subroutine build_original_nested_name: called CC=4 SCAR=16.8
Pod undocumented
178 432 my ($self) = @_;
179  
180 432 ▶ croak 'cannot set build_original_nested_name' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 432 432
181  
182 432 ▶ return if !defined $self->name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->name 0 432 432
183  
184 432 my @names = $self->build_original_nested_names;
185  
186 432 ▶ if ( $self->form->nested_subscript ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form->nested_subscript) { } 0 432 432
187 0 my $name = shift @names;
188 0 map { $name .= "[$_]" } @names;
189  
190 # TODO - Mario Minati 19.05.2009
191 # Does this (name formatted as '[name]') collide with FF::Model::HashRef as
192 # it uses /_\d/ to parse repeatable names?
193 0 return $name;
194 }
195 else {
196 432 return join ".", @names;
197 }
198 }
199  
200 432 ▶sub build_original_nested_names {
Subroutine build_original_nested_names: called CC=15 SCAR=29.7
Pod undocumented
201 432 my ($self) = @_;
202  
203 432 ▶ croak 'cannot set build_original_nested_names' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 432 432
204  
205 # TODO - Mario Minati 19.05.2009
206 # Maybe we have to use original_name instead of name.
207 # Yet there is no testcase, which is currently failing.
208  
209 432 ▶ if ( defined( my $name = $self->name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $self->name)) 432 0 432
210 432 my @names;
211 432 my $parent = $self;
212  
213 # micro optimization! this method's called a lot, so access
214 # parent hashkey directly, instead of calling parent()
215 432 ▶ while ( defined( $parent = $parent->{parent} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($parent = $parent->{"parent"})) 909 432 1341
216  
217 909 ▶ if ( $parent->can('is_field') && $parent->is_field ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($parent->can('is_field') and $parent->is_field) { } 10 899 909
elsif ($parent->can('is_repeatable') and $parent->is_repeatable) { } 434 465 899
Condition100%3/3
$parent->can("is_field") and $parent->is_field
!ll&&!rl&&r
43246710
MC/DC100%2/2
$parent->can("is_field") and $parent->is_field
$parent->can("is_field") $parent->is_field
Truth table100%3/3
A and B
A= $parent->can("is_field")B= $parent->is_field
ABresult
0X0
100
111
218  
219 # handling Field
220 10 ▶ if ( defined $parent->original_name ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $parent->original_name) { } 10 0 10
elsif (defined $parent->name) { } 0 0 0
221 10 push @names, $parent->original_name;
222 }
223 elsif ( defined $parent->name ) {
224 0 push @names, $parent->name;
225 }
226 }
227 ▶ elsif ( $parent->can('is_repeatable') && $parent->is_repeatable ) {
Condition100%3/3
$parent->can("is_repeatable") and $parent->is_repeatable
!ll&&!rl&&r
43233434
MC/DC100%2/2
$parent->can("is_repeatable") and $parent->is_repeatable
$parent->can("is_repeatable") $parent->is_repeatable
Truth table100%3/3
A and B
A= $parent->can("is_repeatable")B= $parent->is_repeatable
ABresult
0X0
100
111
228  
229 # handling Repeatable
230 # TODO - Mario Minati 19.05.2009
231 # Do we have to take care of chains of Repeatable elements, if the Block
232 # elements have already been created for the outer Repeatable elements to
233 # avoid 'outer.outer_1.inner'
234 # Yet there is no failing testcase. All testcases in FF and FF::Model::DBIC
235 # which have nested repeatable elements are passing currently.
236 434 ▶ push @names, $parent->original_nested_name
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent->original_nested_name 432 2 434
237 if defined $parent->original_nested_name;
238 }
239 else {
240  
241 # handling 'not Field' and 'not Repeatable'
242 465 ▶ if ( $parent->can('original_nested_name')
Branch: 2 branches
BranchTrueFalseTotal
if ($parent->can('original_nested_name') and defined $parent->original_nested_name) { } 0 465 465
elsif (defined $parent->nested_name) { } 0 465 465
Condition66%2/3
$parent->can("original_nested_name") and defined $parent->original_nested_name
!ll&&!rl&&r
432330
MC/DC0%0/2
$parent->can("original_nested_name") and defined $parent->original_nested_name
$parent->can("original_nested_name") defined $parent->original_nested_name
Truth table66%2/3
A and B
A= $parent->can("original_nested_name")B= defined $parent->original_nested_name
ABresult
0X0
100
111
243 && defined $parent->original_nested_name )
244 {
245 0 push @names, $parent->original_nested_name;
246 }
247 elsif ( defined $parent->nested_name ) {
248 0 push @names, $parent->nested_name;
249 }
250 }
251 }
252  
253 432 ▶ if (@names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names) 432 0 432
254 432 return reverse $name, @names;
255 }
256 }
257  
258 0 return ( $self->name );
259 }
260  
261 0 ▶sub nested_base {
Subroutine nested_base: not called CC=4 SCAR=30.0
Pod undocumented
262 0 my ($self) = @_;
263  
264 0 ▶ croak 'cannot set nested_base' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 0 0
265  
266 0 my $parent = $self;
267  
268 0 ▶ while ( defined( $parent = $parent->parent ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($parent = $parent->parent)) 0 0 0
269  
270 0 ▶ return $parent->nested_name if defined $parent->nested_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent->nested_name 0 0 0
271 }
272 }
273  
274 111 ▶sub get_deflators {
Subroutine get_deflators: called CC=1 SCAR=0.0
Pod documented
275 111 my $self = shift;
276 111 my %args = _parse_args(@_);
277  
278 111 my @x = @{ $self->_deflators };
279  
280 111 return _filter_components( \%args, \@x );
281 }
282  
283 1518 ▶sub get_filters {
Subroutine get_filters: called CC=1 SCAR=0.0
Pod documented
284 1518 my $self = shift;
285 1518 my %args = _parse_args(@_);
286  
287 1518 my @x = @{ $self->_filters };
288  
289 1518 return _filter_components( \%args, \@x );
290 }
291  
292 1535 ▶sub get_constraints {
Subroutine get_constraints: called CC=1 SCAR=0.0
Pod documented
293 1535 my $self = shift;
294 1535 my %args = _parse_args(@_);
295  
296 1535 my @x = @{ $self->_constraints };
297  
298 1535 return _filter_components( \%args, \@x );
299 }
300  
301 1169 ▶sub get_inflators {
Subroutine get_inflators: called CC=1 SCAR=0.0
Pod documented
302 1169 my $self = shift;
303 1169 my %args = _parse_args(@_);
304  
305 1169 my @x = @{ $self->_inflators };
306  
307 1169 return _filter_components( \%args, \@x );
308 }
309  
310 983 ▶sub get_validators {
Subroutine get_validators: called CC=1 SCAR=0.0
Pod documented
311 983 my $self = shift;
312 983 my %args = _parse_args(@_);
313  
314 983 my @x = @{ $self->_validators };
315  
316 983 return _filter_components( \%args, \@x );
317 }
318  
319 981 ▶sub get_transformers {
Subroutine get_transformers: called CC=1 SCAR=0.0
Pod documented
320 981 my $self = shift;
321 981 my %args = _parse_args(@_);
322  
323 981 my @x = @{ $self->_transformers };
324  
325 981 return _filter_components( \%args, \@x );
326 }
327  
328 9277 ▶sub get_errors {
Subroutine get_errors: called CC=2 SCAR=6.9
Pod documented
329 9277 my $self = shift;
330 9277 my %args = _parse_args(@_);
331  
332 9277 my @x = @{ $self->_errors };
333  
334 9277 _filter_components( \%args, \@x );
335  
336 9277 ▶ if ( !$args{forced} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"forced"}) 7604 1673 9277
337 7604 @x = grep { !$_->forced } @x;
338 }
339  
340 9277 return \@x;
341 }
342  
343 1410 ▶sub clear_errors {
Subroutine clear_errors: called CC=1 SCAR=0.0
Pod documented
344 1410 my ($self) = @_;
345  
346 1410 $self->_errors( [] );
347  
348 1410 return;
349 }
350  
351 1494 ▶after pre_process => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
352 1494 my $self = shift;
353  
354 1494 for my $plugin ( @{ $self->_plugins } ) {
355 2 $plugin->pre_process;
356 }
357  
358 1494 return;
359 415 };
360  
361 1807 ▶after process => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
362 1807 my $self = shift;
363  
364 1807 for my $plugin ( @{ $self->_plugins } ) {
365 2 $plugin->process;
366 }
367  
368 1807 return;
369 415 };
370  
371 1807 ▶after post_process => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
372 1807 my $self = shift;
373  
374 1807 for my $plugin ( @{ $self->_plugins } ) {
375 2 $plugin->post_process;
376 }
377  
378 1807 return;
379 415 };
380  
381 1539 ▶sub process_input {
Subroutine process_input: called CC=13 SCAR=25.8
Pod undocumented
382 1539 my ( $self, $input ) = @_;
383  
384 1539 my $submitted = $self->form->submitted;
385 1539 my $default = $self->default;
386 1539 my $original = $self->value;
387 1539 my $name = $self->nested_name;
388  
389 # a field without a name has no input to process
390 1539 ▶ return if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 16 1523 1539
391  
392 # set input to default value (defined before calling FormFu->process)
393 1523 ▶ if ( $submitted && $self->force_default && defined $default ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($submitted and $self->force_default and defined $default) { } 33 1490 1523
elsif ($submitted and $self->force_default and $self->can('checked') and $self->checked) { } 8 1482 1490
elsif ($submitted and $self->force_default and not defined $default and defined $original) { } 8 2930 2938
Condition83%5/6
$submitted and $self->force_default and defined $default
!ll&&!rl&&r
14563433
$submitted and $self->force_default
!ll&&!rl&&r
0145667
MC/DC66%2/3
$submitted and $self->force_default and defined $default
$submitted $self->force_default defined $default
Truth table75%3/4
A and B and C
A= $submittedB= $self->force_defaultC= defined $default
ABCresult
0XX0
10X0
1100
1111
394 33 $self->set_nested_hash_value( $input, $name, $default );
395 }
396  
397 # checkbox, radio
398 ▶ elsif ($submitted
Condition88%8/9
$submitted and $self->force_default and $self->can("checked") and $self->checked
!ll&&!rl&&r
1457258
$submitted and $self->force_default and $self->can("checked")
!ll&&!rl&&r
1456133
$submitted and $self->force_default
!ll&&!rl&&r
0145634
MC/DC75%3/4
$submitted and $self->force_default and $self->can("checked") and $self->checked
$submitted $self->force_default $self->can("checked") $self->checked
Truth table80%4/5
A and B and C and D
A= $submittedB= $self->force_defaultC= $self->can("checked")D= $self->checked
ABCDresult
0XXX0
10XX0
110X0
11100
11111
399 && $self->force_default
400 && $self->can('checked')
401 && $self->checked )
402 {
403  
404 # the checked attribute is set, so force input to be the original value
405 8 $self->set_nested_hash_value( $input, $name, $original );
406 }
407  
408 # checkbox, radio
409 ▶ elsif ($submitted
Condition77%7/9
$submitted and $self->force_default and not defined $default and defined $original
!ll&&!rl&&r
1456188
$submitted and $self->force_default and not defined $default
!ll&&!rl&&r
1456026
$submitted and $self->force_default
!ll&&!rl&&r
0145626
MC/DC50%2/4
$submitted and $self->force_default and not defined $default and defined $original
$submitted $self->force_default not defined $default defined $original
Truth table60%3/5
A and B and not(C) and D
A= $submittedB= $self->force_defaultC= not defined $defaultD= defined $original
ABCDresult
0XXX0
10XX0
110X0
11100
11111
410 && $self->force_default
411 && !defined $default
412 && defined $original )
413 {
414  
415 # default and value are not equal, so this element is not checked by default
416 8 $self->set_nested_hash_value( $input, $name, undef );
417 }
418  
419 1523 return;
420 }
421  
422 1302 ▶sub prepare_id {
Subroutine prepare_id: called CC=7 SCAR=19.5
Pod undocumented
423 1302 my ( $self, $render ) = @_;
424  
425 1302 ▶ if ( !defined $render->{attributes}{id}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $render->{"attributes"}{"id"} and defined $self->auto_id and length $self->auto_id) 39 1263 1302
Condition83%5/6
not defined $render->{"attributes"}{"id"} and defined $self->auto_id and length $self->auto_id
!ll&&!rl&&r
1263039
not defined $render->{"attributes"}{"id"} and defined $self->auto_id
!ll&&!rl&&r
5125839
MC/DC66%2/3
not defined $render->{"attributes"}{"id"} and defined $self->auto_id and length $self->auto_id
not defined $render->{"attributes"}{"id"} defined $self->auto_id length $self->auto_id
Truth table75%3/4
not(A) and B and C
A= not defined $render->{"attributes"}{"id"}B= defined $self->auto_idC= length $self->auto_id
ABCresult
0XX0
10X0
1100
1111
426 && defined $self->auto_id
427 && length $self->auto_id )
428 {
429 39 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 31 8 39
430 = defined $self->form->id
431 ? $self->form->id
432 : $EMPTY_STR;
433  
434 my $field_name
435 = defined $render->{nested_name}
436 ? $render->{nested_name}
437 39 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 39 0 39
438  
439 39 my %string = (
440 f => $form_name,
441 n => $field_name,
442 );
443  
444 39 my $id = $self->auto_id;
445 39 $id =~ s/%([fn])/$string{$1}/g;
446  
447 39 ▶ if ( defined( my $count = $self->repeatable_count ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $count = $self->repeatable_count)) 4 35 39
448 4 $id =~ s/%r/$count/g;
449 }
450  
451 39 $render->{attributes}{id} = $id;
452 }
453  
454 1302 return;
455 }
456  
457 1238 ▶sub process_value {
Subroutine process_value: called CC=12 SCAR=24.9
Pod undocumented
458 1238 my ( $self, $value ) = @_;
459  
460 1238 my $submitted = $self->form->submitted;
461 1238 my $default = $self->default;
462  
463 1238 my $new;
464  
465 1238 ▶ if ($submitted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($submitted) { } 452 786 1238
466 452 ▶ if ( defined $value ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $value) { } 360 92 452
elsif (defined $default) { } 41 51 92
467 360 $new = $value;
468 }
469 elsif ( defined $default ) {
470 41 $new = $EMPTY_STR;
471 }
472 }
473 else {
474 786 $new = $default;
475 }
476  
477 1238 ▶ if ( $submitted
Branch: 1 branch
BranchTrueFalseTotal
if ($submitted and $self->retain_default and defined $new and $new eq $HTML::FormFu::Role::Element::Field::EMPTY_STR) 12 1226 1238
Condition77%7/9
$submitted and $self->retain_default and defined $new and $new eq $HTML::FormFu::Role::Element::Field::EMPTY_STR
!ll&&!rl&&r
1226012
$submitted and $self->retain_default and defined $new
!ll&&!rl&&r
1226012
$submitted and $self->retain_default
!ll&&!rl&&r
78644012
MC/DC50%2/4
$submitted and $self->retain_default and defined $new and $new eq $HTML::FormFu::Role::Element::Field::EMPTY_STR
$submitted $self->retain_default defined $new $new eq $HTML::FormFu::Role::Element::Field::EMPTY_STR
Truth table60%3/5
A and B and C and D
A= $submittedB= $self->retain_defaultC= defined $newD= $new eq $HTML::FormFu::Role::Element::Field::EMPTY_STR
ABCDresult
0XXX0
10XX0
110X0
11100
11111
478 && $self->retain_default
479 && defined $new
480 && $new eq $EMPTY_STR )
481 {
482 12 $new = $default;
483 }
484  
485 # if the default value has been changed after FormFu->process has been
486 # called we use it and set the value to that changed default again
487 1238 ▶ if ( $submitted
Branch: 1 branch
BranchTrueFalseTotal
if ($submitted and $self->force_default and defined $default and $new ne $default) 6 1232 1238
Condition100%9/9
$submitted and $self->force_default and defined $default and $new ne $default
!ll&&!rl&&r
1213196
$submitted and $self->force_default and defined $default
!ll&&!rl&&r
1207625
$submitted and $self->force_default
!ll&&!rl&&r
78642131
MC/DC100%4/4
$submitted and $self->force_default and defined $default and $new ne $default
$submitted $self->force_default defined $default $new ne $default
Truth table100%5/5
A and B and C and D
A= $submittedB= $self->force_defaultC= defined $defaultD= $new ne $default
ABCDresult
0XXX0
10XX0
110X0
11100
11111
488 && $self->force_default
489 && defined $default
490 && $new ne $default )
491 {
492 6 $new = $default;
493 }
494  
495 1238 return $new;
496 }
497  
498 1354 ▶around render_data_non_recursive => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
499 1354 my ( $orig, $self, $args ) = @_;
500  
501 1354 ▶ my $render = $self->$orig(
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 1325 29 1354
502 { nested_name => xml_escape( $self->nested_name ),
503 comment_attributes => xml_escape( $self->comment_attributes ),
504 container_attributes => xml_escape( $self->container_attributes ),
505 error_container_attributes => xml_escape( $self->error_container_attributes ),
506 label_attributes => xml_escape( $self->label_attributes ),
507 comment => xml_escape( $self->comment ),
508 label => xml_escape( $self->label ),
509 field_filename => $self->field_filename,
510 label_filename => $self->label_filename,
511 label_tag => $self->label_tag,
512 container_tag => $self->container_tag,
513 error_container_tag => $self->error_container_tag,
514 error_tag => $self->error_tag,
515 reverse_single => $self->reverse_single,
516 reverse_multi => $self->reverse_multi,
517 javascript => $self->javascript,
518 $args ? %$args : (),
519 } );
520  
521 1354 $self->_render_container_class($render);
522 1354 $self->_render_comment_class($render);
523 1354 $self->_render_label($render);
524 1354 $self->_render_value($render);
525 1354 $self->_render_constraint_class($render);
526 1354 $self->_render_inflator_class($render);
527 1354 $self->_render_validator_class($render);
528 1354 $self->_render_transformer_class($render);
529 1354 $self->_render_error_class($render);
530  
531 1354 return $render;
532 415 };
533  
534 1354 ▶sub _render_label {
Subroutine _render_label: called CC=19 SCAR=29.7
535 1354 my ( $self, $render ) = @_;
536  
537 1354 ▶ if ( !defined $render->{label}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $render->{"label"} and defined $self->auto_label and length $self->auto_label) 6 1348 1354
Condition83%5/6
not defined $render->{"label"} and defined $self->auto_label and length $self->auto_label
!ll&&!rl&&r
134806
not defined $render->{"label"} and defined $self->auto_label
!ll&&!rl&&r
10312456
MC/DC66%2/3
not defined $render->{"label"} and defined $self->auto_label and length $self->auto_label
not defined $render->{"label"} defined $self->auto_label length $self->auto_label
Truth table75%3/4
not(A) and B and C
A= not defined $render->{"label"}B= defined $self->auto_labelC= length $self->auto_label
ABCresult
0XX0
10X0
1100
1111
538 && defined $self->auto_label
539 && length $self->auto_label )
540 {
541 my %string = (
542 f => defined $self->form->id ? $self->form->id : '',
543 6 ▶ n => defined $render->{name} ? $render->{name} : '',
Branch: 2 branches
BranchTrueFalseTotal
defined $self->form->id ? : 2 4 6
defined $render->{'name'} ? : 6 0 6
544 );
545  
546 6 my $label = $self->auto_label;
547 6 $label =~ s/%([fn])/$string{$1}/g;
548  
549 6 $render->{label} = $self->form->localize($label);
550 }
551  
552 1354 ▶ if ( defined $render->{label}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"label"} and defined $self->auto_label_class and length $self->auto_label_class) 1 1353 1354
Condition83%5/6
defined $render->{"label"} and defined $self->auto_label_class and length $self->auto_label_class
!ll&&!rl&&r
135301
defined $render->{"label"} and defined $self->auto_label_class
!ll&&!rl&&r
12451081
MC/DC66%2/3
defined $render->{"label"} and defined $self->auto_label_class and length $self->auto_label_class
defined $render->{"label"} defined $self->auto_label_class length $self->auto_label_class
Truth table75%3/4
A and B and C
A= defined $render->{"label"}B= defined $self->auto_label_classC= length $self->auto_label_class
ABCresult
0XX0
10X0
1100
1111
553 && defined $self->auto_label_class
554 && length $self->auto_label_class )
555 {
556 1 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 0 1 1
557 = defined $self->form->id
558 ? $self->form->id
559 : $EMPTY_STR;
560  
561 my $field_name
562 = defined $render->{nested_name}
563 ? $render->{nested_name}
564 1 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 1 0 1
565  
566 1 my $type = lc $self->type;
567 1 $type =~ s/:://g;
568  
569 1 my %string = (
570 f => $form_name,
571 n => $field_name,
572 t => $type,
573 );
574  
575 1 my $class = $self->auto_label_class;
576 1 $class =~ s/%([fnt])/$string{$1}/g;
577  
578 1 append_xml_attribute( $render->{label_attributes}, 'class', $class );
579 }
580  
581 1354 ▶ if ( defined $render->{label}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"label"} and defined $self->auto_container_label_class and length $self->auto_container_label_class) 3 1351 1354
Condition83%5/6
defined $render->{"label"} and defined $self->auto_container_label_class and length $self->auto_container_label_class
!ll&&!rl&&r
135103
defined $render->{"label"} and defined $self->auto_container_label_class
!ll&&!rl&&r
12451063
MC/DC66%2/3
defined $render->{"label"} and defined $self->auto_container_label_class and length $self->auto_container_label_class
defined $render->{"label"} defined $self->auto_container_label_class length $self->auto_container_label_class
Truth table75%3/4
A and B and C
A= defined $render->{"label"}B= defined $self->auto_container_label_classC= length $self->auto_container_label_class
ABCresult
0XX0
10X0
1100
1111
582 && defined $self->auto_container_label_class
583 && length $self->auto_container_label_class )
584 {
585 3 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 2 1 3
586 = defined $self->form->id
587 ? $self->form->id
588 : $EMPTY_STR;
589  
590 my $field_name
591 = defined $render->{nested_name}
592 ? $render->{nested_name}
593 3 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 3 0 3
594  
595 3 my $type = lc $self->type;
596 3 $type =~ s/:://g;
597  
598 3 my %string = (
599 f => $form_name,
600 n => $field_name,
601 t => $type,
602 );
603  
604 3 my $class = $self->auto_container_label_class;
605 3 $class =~ s/%([fnt])/$string{$1}/g;
606  
607 append_xml_attribute( $render->{container_attributes},
608 3 'class', $class );
609 }
610  
611 # label "for" attribute
612 1354 ▶ if ( defined $render->{label}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"label"} and defined $render->{"attributes"}{"id"} and not exists $render->{"label_attributes"}{"for"}) 27 1327 1354
Condition83%5/6
defined $render->{"label"} and defined $render->{"attributes"}{"id"} and not exists $render->{"label_attributes"}{"for"}
!ll&&!rl&&r
1327027
defined $render->{"label"} and defined $render->{"attributes"}{"id"}
!ll&&!rl&&r
12458227
MC/DC66%2/3
defined $render->{"label"} and defined $render->{"attributes"}{"id"} and not exists $render->{"label_attributes"}{"for"}
defined $render->{"label"} defined $render->{"attributes"}{"id"} not exists $render->{"label_attributes"}{"for"}
Truth table75%3/4
A and B and not(C)
A= defined $render->{"label"}B= defined $render->{"attributes"}{"id"}C= not exists $render->{"label_attributes"}{"for"}
ABCresult
0XX0
10X0
1100
1111
613 && defined $render->{attributes}{id}
614 && !exists $render->{label_attributes}{for} )
615 {
616 27 $render->{label_attributes}{for} = $render->{attributes}{id};
617 }
618  
619 1354 return;
620 }
621  
622 1354 ▶sub _render_comment_class {
Subroutine _render_comment_class: called CC=11 SCAR=24.1
623 1354 my ( $self, $render ) = @_;
624  
625 1354 ▶ if ( defined $render->{comment}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"comment"} and defined $self->auto_comment_class and length $self->auto_comment_class) 3 1351 1354
Condition83%5/6
defined $render->{"comment"} and defined $self->auto_comment_class and length $self->auto_comment_class
!ll&&!rl&&r
135103
defined $render->{"comment"} and defined $self->auto_comment_class
!ll&&!rl&&r
1319323
MC/DC66%2/3
defined $render->{"comment"} and defined $self->auto_comment_class and length $self->auto_comment_class
defined $render->{"comment"} defined $self->auto_comment_class length $self->auto_comment_class
Truth table75%3/4
A and B and C
A= defined $render->{"comment"}B= defined $self->auto_comment_classC= length $self->auto_comment_class
ABCresult
0XX0
10X0
1100
1111
626 && defined $self->auto_comment_class
627 && length $self->auto_comment_class )
628 {
629 3 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 2 1 3
630 = defined $self->form->id
631 ? $self->form->id
632 : $EMPTY_STR;
633  
634 my $field_name
635 = defined $render->{nested_name}
636 ? $render->{nested_name}
637 3 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 3 0 3
638  
639 3 my %string = (
640 f => $form_name,
641 n => $field_name,
642 );
643  
644 3 my $class = $self->auto_comment_class;
645 3 $class =~ s/%([fn])/$string{$1}/g;
646  
647 3 append_xml_attribute( $render->{comment_attributes}, 'class', $class );
648 }
649  
650 1354 ▶ if ( defined $render->{comment}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"comment"} and defined $self->auto_container_comment_class and length $self->auto_container_comment_class) 3 1351 1354
Condition83%5/6
defined $render->{"comment"} and defined $self->auto_container_comment_class and length $self->auto_container_comment_class
!ll&&!rl&&r
135103
defined $render->{"comment"} and defined $self->auto_container_comment_class
!ll&&!rl&&r
1319323
MC/DC66%2/3
defined $render->{"comment"} and defined $self->auto_container_comment_class and length $self->auto_container_comment_class
defined $render->{"comment"} defined $self->auto_container_comment_class length $self->auto_container_comment_class
Truth table75%3/4
A and B and C
A= defined $render->{"comment"}B= defined $self->auto_container_comment_classC= length $self->auto_container_comment_class
ABCresult
0XX0
10X0
1100
1111
651 && defined $self->auto_container_comment_class
652 && length $self->auto_container_comment_class )
653 {
654 3 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 2 1 3
655 = defined $self->form->id
656 ? $self->form->id
657 : $EMPTY_STR;
658  
659 my $field_name
660 = defined $render->{nested_name}
661 ? $render->{nested_name}
662 3 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 3 0 3
663  
664 3 my %string = (
665 f => $form_name,
666 n => $field_name,
667 );
668  
669 3 my $class = $self->auto_container_comment_class;
670 3 $class =~ s/%([fn])/$string{$1}/g;
671  
672 append_xml_attribute( $render->{container_attributes},
673 3 'class', $class );
674 }
675  
676 1354 return;
677 }
678  
679 1354 ▶sub _render_value {
Subroutine _render_value: called CC=17 SCAR=28.4
680 1354 my ( $self, $render ) = @_;
681  
682 1354 my $form = $self->form;
683 1354 my $name = $self->nested_name;
684  
685 1354 my $input;
686  
687 1354 ▶ if ( $self->form->submitted
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form->submitted and defined $name and $self->nested_hash_key_exists($form->input, $name)) 418 936 1354
Condition100%6/6
$self->form->submitted and defined $name and $self->nested_hash_key_exists($form->input, $name)
!ll&&!rl&&r
85878418
$self->form->submitted and defined $name
!ll&&!rl&&r
82929496
MC/DC100%3/3
$self->form->submitted and defined $name and $self->nested_hash_key_exists($form->input, $name)
$self->form->submitted defined $name $self->nested_hash_key_exists($form->input, $name)
Truth table100%4/4
A and B and C
A= $self->form->submittedB= defined $nameC= $self->nested_hash_key_exists($form->input, $name)
ABCresult
0XX0
10X0
1100
1111
688 && defined $name
689 && $self->nested_hash_key_exists( $form->input, $name ) )
690 {
691 418 ▶ if ( $self->render_processed_value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->render_processed_value) { } 7 411 418
692 7 $input
693 = $self->get_nested_hash_value( $form->_processed_params,
694 $name, );
695 }
696 else {
697 411 $input = $self->get_nested_hash_value( $form->input, $name, );
698 }
699 }
700  
701 1354 ▶ if ( ref $input eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input eq "ARRAY") 24 1330 1354
702 24 my $elems = $self->form->get_fields( $self->name );
703 24 for ( 0 .. @$elems - 1 ) {
704 42 ▶ if ( $self == $elems->[$_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self == $elems->[$_]) 24 18 42
705 24 $input = $input->[$_];
706 }
707 }
708 }
709  
710 1354 my $value = $self->process_value($input);
711  
712 1354 ▶ if ( !$self->form->submitted
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->form->submitted or $self->render_processed_value and defined $value) 836 518 1354
Condition100%6/6
not $self->form->submitted or $self->render_processed_value and defined $value
l!l&&r!l&&!r
8297518
$self->render_processed_value and defined $value
!ll&&!rl&&r
51717
MC/DC100%3/3
not $self->form->submitted or $self->render_processed_value and defined $value
not $self->form->submitted $self->render_processed_value defined $value
Truth table100%4/4
not(A) or B and C
A= not $self->form->submittedB= $self->render_processed_valueC= defined $value
ABCresult
1XX1
0111
00X0
0100
713 || ( $self->render_processed_value && defined $value ) )
714 {
715 836 for my $deflator ( @{ $self->_deflators } ) {
716 31 $value = $deflator->process($value);
717 }
718 }
719  
720 # handle multiple values for the same name
721 1354 ▶ if ( ref $value eq 'ARRAY' && defined $self->name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY" and defined $self->name) 12 1342 1354
Condition66%2/3
ref $value eq "ARRAY" and defined $self->name
!ll&&!rl&&r
1342012
MC/DC50%1/2
ref $value eq "ARRAY" and defined $self->name
ref $value eq "ARRAY" defined $self->name
Truth table66%2/3
A and B
A= ref $value eq "ARRAY"B= defined $self->name
ABresult
0X0
100
111
722 12 my $max = $#$value;
723 12 my $fields = $self->form->get_fields( name => $self->name );
724  
725 12 for my $i ( 0 .. $max ) {
726 12 ▶ if ( defined $fields->[$i] && $fields->[$i] eq $self ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->[$i] and $fields->[$i] eq $self) 12 0 12
Condition33%1/3
defined $fields->[$i] and $fields->[$i] eq $self
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $fields->[$i] and $fields->[$i] eq $self
defined $fields->[$i] $fields->[$i] eq $self
Truth table33%1/3
A and B
A= defined $fields->[$i]B= $fields->[$i] eq $self
ABresult
0X0
100
111
727 12 $value = $value->[$i];
728 12 last;
729 }
730 }
731 }
732  
733 1354 $render->{value} = xml_escape($value);
734  
735 1354 return;
736 }
737  
738 1354 ▶sub _render_container_class {
Subroutine _render_container_class: called CC=5 SCAR=16.1
739 1354 my ( $self, $render ) = @_;
740  
741 1354 ▶ if ( defined $self->auto_container_class
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->auto_container_class and length $self->auto_container_class) 3 1351 1354
Condition66%2/3
defined $self->auto_container_class and length $self->auto_container_class
!ll&&!rl&&r
135103
MC/DC50%1/2
defined $self->auto_container_class and length $self->auto_container_class
defined $self->auto_container_class length $self->auto_container_class
Truth table66%2/3
A and B
A= defined $self->auto_container_classB= length $self->auto_container_class
ABresult
0X0
100
111
742 && length $self->auto_container_class )
743 {
744 3 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 2 1 3
745 = defined $self->form->id
746 ? $self->form->id
747 : $EMPTY_STR;
748  
749 my $field_name
750 = defined $render->{nested_name}
751 ? $render->{nested_name}
752 3 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 3 0 3
753  
754 3 my $type = lc $self->type;
755 3 $type =~ s/:://g;
756  
757 3 my %string = (
758 f => $form_name,
759 n => $field_name,
760 t => $type,
761 );
762  
763 3 my $class = $self->auto_container_class;
764 3 $class =~ s/%([fnt])/$string{$1}/g;
765  
766 append_xml_attribute( $render->{container_attributes},
767 3 'class', $class );
768 }
769  
770 1354 return;
771 }
772  
773 1354 ▶sub _render_constraint_class {
Subroutine _render_constraint_class: called CC=6 SCAR=18.1
774 1354 my ( $self, $render ) = @_;
775  
776 1354 my $auto_class = $self->auto_constraint_class;
777  
778 1354 ▶ return if !defined $auto_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $auto_class 1352 2 1354
779  
780 2 for my $c ( @{ $self->_constraints } ) {
781 my %string = (
782 f => defined $self->form->id ? $self->form->id : '',
783 2 ▶ n => defined $render->{name} ? $render->{name} : '',
Branch: 3 branches
BranchTrueFalseTotal
defined $self->form->id ? : 2 0 2
defined $render->{'name'} ? : 2 0 2
defined $c->type ? : 2 0 2
784 t => defined $c->type ? lc( $c->type ) : '',
785 );
786  
787 2 $string{t} =~ s/::/_/g;
788 2 $string{t} =~ s/\+//;
789  
790 2 my $class = $auto_class;
791  
792 2 $class =~ s/%([fnt])/$string{$1}/g;
793  
794 append_xml_attribute( $render->{container_attributes},
795 2 'class', $class, );
796 }
797  
798 2 return;
799 }
800  
801 1354 ▶sub _render_inflator_class {
Subroutine _render_inflator_class: called CC=6 SCAR=32.0
802 1354 my ( $self, $render ) = @_;
803  
804 1354 my $auto_class = $self->auto_inflator_class;
805  
806 1354 ▶ return if !defined $auto_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $auto_class 1354 0 1354
807  
808 0 for my $c ( @{ $self->_inflators } ) {
809 my %string = (
810 f => defined $self->form->id ? $self->form->id : '',
811 0 ▶ n => defined $render->{name} ? $render->{name} : '',
Branch: 3 branches
BranchTrueFalseTotal
defined $self->form->id ? : 0 0 0
defined $render->{'name'} ? : 0 0 0
defined $c->type ? : 0 0 0
812 t => defined $c->type ? lc( $c->type ) : '',
813 );
814  
815 0 $string{t} =~ s/::/_/g;
816 0 $string{t} =~ s/\+//;
817  
818 0 my $class = $auto_class;
819  
820 0 $class =~ s/%([fnt])/$string{$1}/g;
821  
822 append_xml_attribute( $render->{container_attributes},
823 0 'class', $class, );
824 }
825  
826 0 return;
827 }
828  
829 1354 ▶sub _render_validator_class {
Subroutine _render_validator_class: called CC=6 SCAR=32.0
830 1354 my ( $self, $render ) = @_;
831  
832 1354 my $auto_class = $self->auto_validator_class;
833  
834 1354 ▶ return if !defined $auto_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $auto_class 1354 0 1354
835  
836 0 for my $c ( @{ $self->_validators } ) {
837 my %string = (
838 f => defined $self->form->id ? $self->form->id : '',
839 0 ▶ n => defined $render->{name} ? $render->{name} : '',
Branch: 3 branches
BranchTrueFalseTotal
defined $self->form->id ? : 0 0 0
defined $render->{'name'} ? : 0 0 0
defined $c->type ? : 0 0 0
840 t => defined $c->type ? lc( $c->type ) : '',
841 );
842  
843 0 $string{t} =~ s/::/_/g;
844 0 $string{t} =~ s/\+//;
845  
846 0 my $class = $auto_class;
847  
848 0 $class =~ s/%([fnt])/$string{$1}/g;
849  
850 append_xml_attribute( $render->{container_attributes},
851 0 'class', $class, );
852 }
853  
854 0 return;
855 }
856  
857 1354 ▶sub _render_transformer_class {
Subroutine _render_transformer_class: called CC=6 SCAR=32.0
858 1354 my ( $self, $render ) = @_;
859  
860 1354 my $auto_class = $self->auto_transformer_class;
861  
862 1354 ▶ return if !defined $auto_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $auto_class 1354 0 1354
863  
864 0 for my $c ( @{ $self->_transformers } ) {
865 my %string = (
866 f => defined $self->form->id ? $self->form->id : '',
867 0 ▶ n => defined $render->{name} ? $render->{name} : '',
Branch: 3 branches
BranchTrueFalseTotal
defined $self->form->id ? : 0 0 0
defined $render->{'name'} ? : 0 0 0
defined $c->type ? : 0 0 0
868 t => defined $c->type ? lc( $c->type ) : '',
869 );
870  
871 0 $string{t} =~ s/::/_/g;
872 0 $string{t} =~ s/\+//;
873  
874 0 my $class = $auto_class;
875  
876 0 $class =~ s/%([fnt])/$string{$1}/g;
877  
878 append_xml_attribute( $render->{container_attributes},
879 0 'class', $class, );
880 }
881  
882 0 return;
883 }
884  
885 1354 ▶sub _render_error_class {
Subroutine _render_error_class: called CC=15 SCAR=40.4
886 1354 my ( $self, $render ) = @_;
887  
888 1354 my @errors = @{ $self->get_errors( { forced => 1 } ) };
889  
890 1354 ▶ return if !@errors;
Branch: 1 branch
BranchTrueFalseTotal
unless @errors 1303 51 1354
891  
892 51 @errors = map { $_->render_data } @errors;
893  
894 51 $render->{errors} = \@errors;
895  
896 # auto_error_field_class
897 51 my $field_class = $self->auto_error_field_class;
898  
899 51 ▶ if ( defined $field_class && length $field_class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $field_class and length $field_class) 1 50 51
Condition66%2/3
defined $field_class and length $field_class
!ll&&!rl&&r
5001
MC/DC50%1/2
defined $field_class and length $field_class
defined $field_class length $field_class
Truth table66%2/3
A and B
A= defined $field_classB= length $field_class
ABresult
0X0
100
111
900 my %string = (
901 0 ▶ f => sub { defined $self->form->id ? $self->form->id : '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 0 0 0
902 0 ▶ n => sub { defined $render->{name} ? $render->{name} : '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'name'} ? : 0 0 0
903 1 );
904  
905 0 $field_class =~ s/%([fn])/$string{$1}->()/ge;
906  
907 1 append_xml_attribute( $render->{attributes}, 'class', $field_class );
908 }
909  
910 51 my @container_class;
911  
912 # auto_container_error_class
913 51 my $auto_class = $self->auto_container_error_class;
914  
915 51 ▶ if ( defined $auto_class && length $auto_class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $auto_class and length $auto_class) 2 49 51
Condition66%2/3
defined $auto_class and length $auto_class
!ll&&!rl&&r
4902
MC/DC50%1/2
defined $auto_class and length $auto_class
defined $auto_class length $auto_class
Truth table66%2/3
A and B
A= defined $auto_classB= length $auto_class
ABresult
0X0
100
111
916 my %string = (
917 0 ▶ f => sub { defined $self->form->id ? $self->form->id : '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 0 0 0
918 0 ▶ n => sub { defined $render->{name} ? $render->{name} : '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'name'} ? : 0 0 0
919 2 );
920  
921 0 $auto_class =~ s/%([fn])/$string{$1}->()/ge;
922  
923 2 push @container_class, $auto_class;
924 }
925  
926 # auto_container_per_error_class
927 51 my $item_class = $self->auto_container_per_error_class;
928  
929 51 ▶ if ( defined $item_class && length $item_class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $item_class and length $item_class) 1 50 51
Condition66%2/3
defined $item_class and length $item_class
!ll&&!rl&&r
5001
MC/DC50%1/2
defined $item_class and length $item_class
defined $item_class length $item_class
Truth table66%2/3
A and B
A= defined $item_classB= length $item_class
ABresult
0X0
100
111
930 1 for my $error (@errors) {
931 my %string = (
932 0 ▶ f => sub { defined $self->form->id ? $self->form->id : '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 0 0 0
933 0 ▶ n => sub { defined $render->{name} ? $render->{name} : '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'name'} ? : 0 0 0
934 1 ▶ s => sub { $error->{stage} },
Subroutine __ANON__: called CC=1 SCAR=0.0
935 1 ▶ t => sub { lc $error->{type} },
Subroutine __ANON__: called CC=1 SCAR=0.0
936 1 );
937  
938 1 my $string = $item_class;
939 1 $string =~ s/%([fnst])/$string{$1}->()/ge;
940  
941 1 push @container_class, $string;
942 }
943 }
944  
945 51 map { append_xml_attribute( $render->{container_attributes}, 'class', $_ ) }
946 uniq @container_class;
947  
948 51 my @error_container_class;
949  
950 51 ▶ if ( $self->error_container_tag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error_container_tag) 0 51 51
951  
952 # auto_error_container_class
953 0 my $auto_class = $self->auto_error_container_class;
954  
955 0 ▶ if ( defined $auto_class && length $auto_class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $auto_class and length $auto_class) 0 0 0
Condition0%0/3
defined $auto_class and length $auto_class
!ll&&!rl&&r
000
MC/DC0%0/2
defined $auto_class and length $auto_class
defined $auto_class length $auto_class
Truth table0%0/3
A and B
A= defined $auto_classB= length $auto_class
ABresult
0X0
100
111
956 my %string = (
957 0 ▶ f => sub { defined $self->form->id ? $self->form->id : '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 0 0 0
958 0 ▶ n => sub { defined $render->{name} ? $render->{name} : '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'name'} ? : 0 0 0
959 0 );
960  
961 0 $auto_class =~ s/%([fn])/$string{$1}->()/ge;
962  
963 0 push @error_container_class, $auto_class;
964 }
965  
966 # auto_container_per_error_class
967 0 my $item_class = $self->auto_container_per_error_class;
968  
969 0 ▶ if ( defined $item_class && length $item_class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $item_class and length $item_class) 0 0 0
Condition0%0/3
defined $item_class and length $item_class
!ll&&!rl&&r
000
MC/DC0%0/2
defined $item_class and length $item_class
defined $item_class length $item_class
Truth table0%0/3
A and B
A= defined $item_classB= length $item_class
ABresult
0X0
100
111
970 0 for my $error (@errors) {
971 my %string = (
972 0 ▶ f => sub { defined $self->form->id ? $self->form->id : '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 0 0 0
973 0 ▶ n => sub { defined $render->{name} ? $render->{name} : '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'name'} ? : 0 0 0
974 0 ▶ s => sub { $error->{stage} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
975 0 ▶ t => sub { lc $error->{type} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
976 0 );
977  
978 0 my $string = $item_class;
979 0 $string =~ s/%([fnst])/$string{$1}->()/ge;
980  
981 0 push @error_container_class, $string;
982 }
983 }
984  
985 map {
986 0 append_xml_attribute( $render->{error_container_attributes},
987 0 'class', $_ )
988 } uniq @error_container_class;
989 }
990  
991 51 return;
992 }
993  
994 6 ▶sub render_label {
Subroutine render_label: called CC=1 SCAR=0.0
Pod undocumented
995 6 my ($self) = @_;
996  
997 6 my $render = $self->render_data;
998  
999 6 return $self->_string_label($render);
1000 }
1001  
1002 6 ▶sub render_field {
Subroutine render_field: called CC=1 SCAR=0.0
Pod undocumented
1003 6 my ($self) = @_;
1004  
1005 6 my $render = $self->render_data;
1006  
1007 6 return $self->_string_field($render);
1008 }
1009  
1010 0 ▶sub _string_field_start {
Subroutine _string_field_start: not called CC=8 SCAR=42.8
1011 0 my ( $self, $render ) = @_;
1012  
1013 # field wrapper template - start
1014  
1015 0 my $html = '';
1016  
1017 0 ▶ if ( defined $render->{container_tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"container_tag"}) 0 0 0
1018 $html .= sprintf '<%s%s>',
1019 $render->{container_tag},
1020 0 process_attrs( $render->{container_attributes} );
1021 }
1022  
1023 0 ▶ if ( defined $render->{label} && $render->{label_tag} eq 'legend' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"label"} and $render->{"label_tag"} eq "legend") 0 0 0
Condition0%0/3
defined $render->{"label"} and $render->{"label_tag"} eq "legend"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $render->{"label"} and $render->{"label_tag"} eq "legend"
defined $render->{"label"} $render->{"label_tag"} eq "legend"
Truth table0%0/3
A and B
A= defined $render->{"label"}B= $render->{"label_tag"} eq "legend"
ABresult
0X0
100
111
1024 0 $html .= sprintf "\n%s", $self->_string_label($render);
1025 }
1026  
1027 0 $html .= $self->_string_errors($render);
1028  
1029 0 ▶ if ( defined $render->{label}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"label"} and $render->{"label_tag"} ne "legend" and not $render->{"reverse_single"}) 0 0 0
Condition0%0/6
defined $render->{"label"} and $render->{"label_tag"} ne "legend" and not $render->{"reverse_single"}
!ll&&!rl&&r
000
defined $render->{"label"} and $render->{"label_tag"} ne "legend"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $render->{"label"} and $render->{"label_tag"} ne "legend" and not $render->{"reverse_single"}
defined $render->{"label"} $render->{"label_tag"} ne "legend" not $render->{"reverse_single"}
Truth table0%0/4
A and B and not(C)
A= defined $render->{"label"}B= $render->{"label_tag"} ne "legend"C= not $render->{"reverse_single"}
ABCresult
0XX0
10X0
1100
1111
1030 && $render->{label_tag} ne 'legend'
1031 && !$render->{reverse_single} )
1032 {
1033 0 $html .= sprintf "\n%s", $self->_string_label($render);
1034 }
1035  
1036 0 ▶ if ( defined $render->{container_tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"container_tag"}) 0 0 0
1037 0 $html .= "\n";
1038 }
1039  
1040 0 return $html;
1041 }
1042  
1043 95 ▶sub _string_label {
Subroutine _string_label: called CC=1 SCAR=0.0
1044 95 my ( $self, $render ) = @_;
1045  
1046 # label template
1047  
1048 my $html = sprintf "<%s%s>%s</%s>",
1049 $render->{label_tag},
1050 process_attrs( $render->{label_attributes} ),
1051 $render->{label},
1052 $render->{label_tag},
1053 95 ;
1054  
1055 95 return $html;
1056 }
1057  
1058 717 ▶sub _string_errors {
Subroutine _string_errors: called CC=5 SCAR=16.6
1059 717 my ( $self, $render ) = @_;
1060  
1061 717 ▶ return '' if !$render->{errors};
Branch: 1 branch
BranchTrueFalseTotal
unless $render->{"errors"} 670 47 717
1062  
1063 47 my $html = '';
1064  
1065 47 ▶ if ( $render->{error_container_tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($render->{"error_container_tag"}) 0 47 47
1066 $html .= sprintf qq{<%s%s>\n},
1067 $render->{error_container_tag},
1068 0 process_attrs( $render->{error_container_attributes} ),
1069 ;
1070 }
1071  
1072 47 my @error_html;
1073 47 for my $error ( @{ $render->{errors} } ) {
1074 push @error_html, sprintf qq{<%s%s>%s</%s>},
1075 $render->{error_tag},
1076 process_attrs( $error->{attributes} ),
1077 $error->{message},
1078 $render->{error_tag},
1079 50 ;
1080 }
1081 47 $html .= join "\n", @error_html;
1082  
1083 47 ▶ if ( $render->{error_container_tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($render->{"error_container_tag"}) 0 47 47
1084 0 $html .= sprintf qq{\n</%s>}, $render->{error_container_tag};
1085 }
1086  
1087 47 return $html;
1088 }
1089  
1090 0 ▶sub _string_field_end {
Subroutine _string_field_end: not called CC=7 SCAR=40.3
1091 0 my ( $self, $render ) = @_;
1092  
1093 # field wrapper template - end
1094  
1095 0 my $html = '';
1096  
1097 0 ▶ if ( defined $render->{label}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"label"} and $render->{"label_tag"} ne "legend" and $render->{"reverse_single"}) 0 0 0
Condition0%0/6
defined $render->{"label"} and $render->{"label_tag"} ne "legend" and $render->{"reverse_single"}
!ll&&!rl&&r
000
defined $render->{"label"} and $render->{"label_tag"} ne "legend"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $render->{"label"} and $render->{"label_tag"} ne "legend" and $render->{"reverse_single"}
defined $render->{"label"} $render->{"label_tag"} ne "legend" $render->{"reverse_single"}
Truth table0%0/4
A and B and C
A= defined $render->{"label"}B= $render->{"label_tag"} ne "legend"C= $render->{"reverse_single"}
ABCresult
0XX0
10X0
1100
1111
1098 && $render->{label_tag} ne 'legend'
1099 && $render->{reverse_single} )
1100 {
1101 0 $html .= sprintf "\n%s", $self->_string_label($render);
1102 }
1103  
1104 0 ▶ if ( defined $render->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"comment"}) 0 0 0
1105 $html .= sprintf "\n<span%s>\n%s\n</span>",
1106 process_attrs( $render->{comment_attributes} ),
1107 $render->{comment},
1108 0 ;
1109 }
1110  
1111 0 ▶ if ( defined $render->{container_tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"container_tag"}) 0 0 0
1112 0 $html .= sprintf "\n</%s>", $render->{container_tag},;
1113 }
1114  
1115 0 ▶ if ( defined $render->{javascript} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"javascript"}) 0 0 0
1116 $html .= sprintf qq{\n<script type="text/javascript">\n%s\n</script>},
1117 $render->{javascript},
1118 0 ;
1119 }
1120  
1121 0 return $html;
1122 }
1123  
1124 541 ▶around clone => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1125 541 my $orig = shift;
1126 541 my $self = shift;
1127  
1128 541 my $clone = $self->$orig(@_);
1129  
1130 541 for my $list ( qw(
1131 _filters _constraints _inflators _validators _transformers
1132 _deflators _errors _plugins )
1133 )
1134 {
1135 4328 $clone->$list( [ map { $_->clone } @{ $self->$list } ] );
1136  
1137 4328 map { $_->parent($clone) } @{ $clone->$list };
1138 }
1139  
1140 541 $clone->comment_attributes( Clone::clone( $self->comment_attributes ) );
1141 541 $clone->container_attributes( Clone::clone( $self->container_attributes ) );
1142 541 $clone->label_attributes( Clone::clone( $self->label_attributes ) );
1143  
1144 541 return $clone;
1145 415 };
1146  
1147 415 1;
1148  
1149 __END__
« lib/HTML/FormFu/Role/Element/Group.pm ↑ Summary lib/HTML/FormFu/Element/Block.pm »