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

filter: Statementstmt 80.3% 404 / 503 Branchbran 57.6% 136 / 236 Conditioncond 72.5% 111 / 153 MC/DCmcdc 57.3% 47 / 82 Subroutinesub 75.8% 47 / 62 Podpod 42.1% 8 / 19 totaltotal 71.3% 753 / 1055 SCAR 67.5
CC
184
Cov
73%
_string_field_start
72.0
_render_error_class
57.0
_string_field_end
56.0
CRAP 851.7
« lib/HTML/FormFu/Attribute.pm ↑ Summary lib/HTML/FormFu/Role/FormAndBlockMethods.pm »
1 383 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Role::Element::Field;
4 383 $HTML::FormFu::Role::Element::Field::VERSION = '2.06';
5 # ABSTRACT: Role for all form-field elements
6  
7 383 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 383 ▶use MooseX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 383 with 'HTML::FormFu::Role::ContainsElementsSharedWithField',
11 'HTML::FormFu::Role::NestedHashUtils',
12 'HTML::FormFu::Role::FormBlockAndFieldMethods',
13 'HTML::FormFu::Role::Element::Layout';
14  
15 383 use HTML::FormFu::Attribute qw(
16 mk_attrs
17 mk_output_accessors
18 383 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 383 ▶use HTML::FormFu::Constants qw( $EMPTY_STR );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 383 use HTML::FormFu::Util qw(
21 _parse_args append_xml_attribute
22 xml_escape require_class
23 process_attrs _filter_components
24 383 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 383 ▶use Class::MOP::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 383 ▶use Clone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 383 ▶use List::Util 1.45 qw( uniq );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 383 ▶use Carp qw( croak carp );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 383 __PACKAGE__->mk_attrs( qw(
31 comment_attributes
32 container_attributes
33 label_attributes
34 error_attributes
35 error_container_attributes
36 ) );
37  
38 383 has _constraints => ( is => 'rw', traits => ['Chained'] );
39 383 has _filters => ( is => 'rw', traits => ['Chained'] );
40 383 has _inflators => ( is => 'rw', traits => ['Chained'] );
41 383 has _deflators => ( is => 'rw', traits => ['Chained'] );
42 383 has _validators => ( is => 'rw', traits => ['Chained'] );
43 383 has _transformers => ( is => 'rw', traits => ['Chained'] );
44 383 has _plugins => ( is => 'rw', traits => ['Chained'] );
45 383 has _errors => ( is => 'rw', traits => ['Chained'] );
46 383 has container_tag => ( is => 'rw', traits => ['Chained'] );
47 383 has field_filename => ( is => 'rw', traits => ['Chained'] );
48 383 has label_filename => ( is => 'rw', traits => ['Chained'] );
49 383 has label_tag => ( is => 'rw', traits => ['Chained'] );
50 383 has retain_default => ( is => 'rw', traits => ['Chained'] );
51 383 has force_default => ( is => 'rw', traits => ['Chained'] );
52 383 has javascript => ( is => 'rw', traits => ['Chained'] );
53 383 has non_param => ( is => 'rw', traits => ['Chained'] );
54 383 has reverse_single => ( is => 'rw', traits => ['Chained'] );
55 383 has reverse_multi => ( is => 'rw', traits => ['Chained'] );
56 383 has multi_value => ( is => 'rw', traits => ['Chained'] );
57 383 has original_name => ( is => 'rw', traits => ['Chained'] );
58 383 has original_nested_name => ( is => 'rw', traits => ['Chained'] );
59 383 has default_empty_value => ( is => 'rw', traits => ['Chained'] );
60  
61 383 __PACKAGE__->mk_output_accessors(qw( comment label value ));
62  
63 383 alias( "default", "value" );
64 383 alias( "default_xml", "value_xml" );
65 383 alias( "default_loc", "value_loc" );
66  
67 after BUILD => sub {
68 1317 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
69  
70 1317 $self->_constraints( [] );
71 1317 $self->_filters( [] );
72 1317 $self->_deflators( [] );
73 1317 $self->_inflators( [] );
74 1317 $self->_validators( [] );
75 1317 $self->_transformers( [] );
76 1317 $self->_plugins( [] );
77 1317 $self->_errors( [] );
78 1317 $self->comment_attributes( {} );
79 1317 $self->container_attributes( {} );
80 1317 $self->label_attributes( {} );
81 1317 $self->error_attributes( {} );
82 1317 $self->error_container_attributes( {} );
83 1317 $self->label_filename('label');
84 1317 $self->label_tag('label');
85 1317 $self->container_tag('div');
86 1317 $self->is_field(1);
87  
88 1317 return;
89 383 };
90  
91 sub nested {
92 1007 ▶ my ($self) = @_;
Subroutine nested: called CC=8 SCAR=20.9
Pod undocumented
93  
94 1007 ▶ croak 'cannot set nested' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 1007 1007
95  
96 1007 ▶ if ( defined $self->name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->name) 1007 0 1007
97 1007 my $parent = $self;
98  
99 1007 ▶ while ( defined( $parent = $parent->parent ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($parent = $parent->parent)) 1289 752 2041
100  
101 1289 ▶ if ( $parent->can('is_field') && $parent->is_field ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->can('is_field') and $parent->is_field) { } 97 1192 1289
Condition100%3/3
$parent->can("is_field") and $parent->is_field
!ll&&!rl&&r
75244097
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 1192 ▶ return 1 if defined $parent->nested_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent->nested_name 158 1034 1192
106 }
107 }
108 }
109  
110 752 return;
111 }
112  
113 sub nested_name {
114 17657 ▶ my ($self) = @_;
Subroutine nested_name: called CC=4 SCAR=15.8
Pod undocumented
115  
116 17657 ▶ croak 'cannot set nested_name' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 17657 17657
117  
118 17657 ▶ return if !defined $self->name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->name 58 17599 17657
119  
120 17599 my @names = $self->nested_names;
121  
122 17599 ▶ if ( $self->form->nested_subscript ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form->nested_subscript) { } 0 17599 17599
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 17599 return join ".", @names;
133 }
134 }
135  
136 sub nested_names {
137 15569 ▶ my ($self) = @_;
Subroutine nested_names: called CC=11 SCAR=24.0
Pod undocumented
138  
139 15569 ▶ croak 'cannot set nested_names' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 15569 15569
140  
141 15569 ▶ if ( defined( my $name = $self->name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $self->name)) 15569 0 15569
142 15569 my @names;
143 15569 my $parent = $self;
144  
145 # micro optimization! this method's called a lot, so access
146 # parent hashkey directly, instead of calling parent()
147 15569 ▶ while ( defined( $parent = $parent->{parent} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($parent = $parent->{"parent"})) 25718 15569 41287
148  
149 25718 ▶ if ( $parent->can('is_field') && $parent->is_field ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($parent->can('is_field') and $parent->is_field) { } 535 25183 25718
elsif ($parent->can('is_repeatable') and $parent->is_repeatable) { } 2914 22269 25183
Condition100%3/3
$parent->can("is_field") and $parent->is_field
!ll&&!rl&&r
155699614535
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
1556967002914
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 22269 ▶ push @names, $parent->nested_name
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent->nested_name 2914 19355 22269
165 if defined $parent->nested_name;
166 }
167 }
168  
169 15569 ▶ if (@names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names) 3243 12326 15569
170 3243 return reverse $name, @names;
171 }
172 }
173  
174 12326 return ( $self->name );
175 }
176  
177 sub build_original_nested_name {
178 71 ▶ my ($self) = @_;
Subroutine build_original_nested_name: called CC=4 SCAR=16.8
Pod undocumented
179  
180 71 ▶ croak 'cannot set build_original_nested_name' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 71 71
181  
182 71 ▶ return if !defined $self->name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->name 0 71 71
183  
184 71 my @names = $self->build_original_nested_names;
185  
186 71 ▶ if ( $self->form->nested_subscript ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form->nested_subscript) { } 0 71 71
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 71 return join ".", @names;
197 }
198 }
199  
200 sub build_original_nested_names {
201 71 ▶ my ($self) = @_;
Subroutine build_original_nested_names: called CC=15 SCAR=29.7
Pod undocumented
202  
203 71 ▶ croak 'cannot set build_original_nested_names' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 71 71
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 71 ▶ if ( defined( my $name = $self->name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $self->name)) 71 0 71
210 71 my @names;
211 71 my $parent = $self;
212  
213 # micro optimization! this method's called a lot, so access
214 # parent hashkey directly, instead of calling parent()
215 71 ▶ while ( defined( $parent = $parent->{parent} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($parent = $parent->{"parent"})) 187 71 258
216  
217 187 ▶ if ( $parent->can('is_field') && $parent->is_field ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($parent->can('is_field') and $parent->is_field) { } 10 177 187
elsif ($parent->can('is_repeatable') and $parent->is_repeatable) { } 73 104 177
Condition100%3/3
$parent->can("is_field") and $parent->is_field
!ll&&!rl&&r
7110610
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
713373
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 73 ▶ push @names, $parent->original_nested_name
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent->original_nested_name 71 2 73
237 if defined $parent->original_nested_name;
238 }
239 else {
240  
241 # handling 'not Field' and 'not Repeatable'
242 104 ▶ if ( $parent->can('original_nested_name')
Branch: 2 branches
BranchTrueFalseTotal
if ($parent->can('original_nested_name') and defined $parent->original_nested_name) { } 0 104 104
elsif (defined $parent->nested_name) { } 0 104 104
Condition66%2/3
$parent->can("original_nested_name") and defined $parent->original_nested_name
!ll&&!rl&&r
71330
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 71 ▶ if (@names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names) 71 0 71
254 71 return reverse $name, @names;
255 }
256 }
257  
258 0 return ( $self->name );
259 }
260  
261 sub nested_base {
262 0 ▶ my ($self) = @_;
Subroutine nested_base: not called CC=4 SCAR=30.0
Pod undocumented
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 sub get_deflators {
275 111 ▶ my $self = shift;
Subroutine get_deflators: called CC=1 SCAR=0.0
Pod documented
276 111 my %args = _parse_args(@_);
277  
278 111 my @x = @{ $self->_deflators };
279  
280 111 return _filter_components( \%args, \@x );
281 }
282  
283 sub get_filters {
284 1182 ▶ my $self = shift;
Subroutine get_filters: called CC=1 SCAR=0.0
Pod documented
285 1182 my %args = _parse_args(@_);
286  
287 1182 my @x = @{ $self->_filters };
288  
289 1182 return _filter_components( \%args, \@x );
290 }
291  
292 sub get_constraints {
293 1199 ▶ my $self = shift;
Subroutine get_constraints: called CC=1 SCAR=0.0
Pod documented
294 1199 my %args = _parse_args(@_);
295  
296 1199 my @x = @{ $self->_constraints };
297  
298 1199 return _filter_components( \%args, \@x );
299 }
300  
301 sub get_inflators {
302 980 ▶ my $self = shift;
Subroutine get_inflators: called CC=1 SCAR=0.0
Pod documented
303 980 my %args = _parse_args(@_);
304  
305 980 my @x = @{ $self->_inflators };
306  
307 980 return _filter_components( \%args, \@x );
308 }
309  
310 sub get_validators {
311 794 ▶ my $self = shift;
Subroutine get_validators: called CC=1 SCAR=0.0
Pod documented
312 794 my %args = _parse_args(@_);
313  
314 794 my @x = @{ $self->_validators };
315  
316 794 return _filter_components( \%args, \@x );
317 }
318  
319 sub get_transformers {
320 792 ▶ my $self = shift;
Subroutine get_transformers: called CC=1 SCAR=0.0
Pod documented
321 792 my %args = _parse_args(@_);
322  
323 792 my @x = @{ $self->_transformers };
324  
325 792 return _filter_components( \%args, \@x );
326 }
327  
328 sub get_errors {
329 7878 ▶ my $self = shift;
Subroutine get_errors: called CC=2 SCAR=6.9
Pod documented
330 7878 my %args = _parse_args(@_);
331  
332 7878 my @x = @{ $self->_errors };
333  
334 7878 _filter_components( \%args, \@x );
335  
336 7878 ▶ if ( !$args{forced} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"forced"}) 6242 1636 7878
337 6242 @x = grep { !$_->forced } @x;
338 }
339  
340 7878 return \@x;
341 }
342  
343 sub clear_errors {
344 1221 ▶ my ($self) = @_;
Subroutine clear_errors: called CC=1 SCAR=0.0
Pod documented
345  
346 1221 $self->_errors( [] );
347  
348 1221 return;
349 }
350  
351 after pre_process => sub {
352 1303 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
353  
354 1303 for my $plugin ( @{ $self->_plugins } ) {
355 2 $plugin->pre_process;
356 }
357  
358 1303 return;
359 383 };
360  
361 after process => sub {
362 1457 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
363  
364 1457 for my $plugin ( @{ $self->_plugins } ) {
365 2 $plugin->process;
366 }
367  
368 1457 return;
369 383 };
370  
371 after post_process => sub {
372 1457 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
373  
374 1457 for my $plugin ( @{ $self->_plugins } ) {
375 2 $plugin->post_process;
376 }
377  
378 1457 return;
379 383 };
380  
381 sub process_input {
382 1202 ▶ my ( $self, $input ) = @_;
Subroutine process_input: called CC=12 SCAR=25.0
Pod undocumented
383  
384 1202 my $submitted = $self->form->submitted;
385 1202 my $default = $self->default;
386 1202 my $original = $self->value;
387 1202 my $name = $self->nested_name;
388  
389 # set input to default value (defined before calling FormFu->process)
390 1202 ▶ if ( $submitted && $self->force_default && defined $default ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($submitted and $self->force_default and defined $default) { } 33 1169 1202
elsif ($submitted and $self->force_default and $self->can('checked') and $self->checked) { } 8 1161 1169
elsif ($submitted and $self->force_default and not defined $default and defined $original) { } 8 2287 2295
Condition83%5/6
$submitted and $self->force_default and defined $default
!ll&&!rl&&r
11343533
$submitted and $self->force_default
!ll&&!rl&&r
0113468
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
391 33 $self->set_nested_hash_value( $input, $name, $default );
392 }
393  
394 # checkbox, radio
395 ▶ elsif ($submitted
Condition88%8/9
$submitted and $self->force_default and $self->can("checked") and $self->checked
!ll&&!rl&&r
1135268
$submitted and $self->force_default and $self->can("checked")
!ll&&!rl&&r
1134134
$submitted and $self->force_default
!ll&&!rl&&r
0113435
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
396 && $self->force_default
397 && $self->can('checked')
398 && $self->checked )
399 {
400  
401 # the checked attribute is set, so force input to be the original value
402 8 $self->set_nested_hash_value( $input, $name, $original );
403 }
404  
405 # checkbox, radio
406 ▶ elsif ($submitted
Condition77%7/9
$submitted and $self->force_default and not defined $default and defined $original
!ll&&!rl&&r
1134198
$submitted and $self->force_default and not defined $default
!ll&&!rl&&r
1134027
$submitted and $self->force_default
!ll&&!rl&&r
0113427
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
407 && $self->force_default
408 && !defined $default
409 && defined $original )
410 {
411  
412 # default and value are not equal, so this element is not checked by default
413 8 $self->set_nested_hash_value( $input, $name, undef );
414 }
415  
416 1202 return;
417 }
418  
419 sub prepare_id {
420 1273 ▶ my ( $self, $render ) = @_;
Subroutine prepare_id: called CC=7 SCAR=19.5
Pod undocumented
421  
422 1273 ▶ 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 1234 1273
Condition83%5/6
not defined $render->{"attributes"}{"id"} and defined $self->auto_id and length $self->auto_id
!ll&&!rl&&r
1234039
not defined $render->{"attributes"}{"id"} and defined $self->auto_id
!ll&&!rl&&r
5122939
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
423 && defined $self->auto_id
424 && length $self->auto_id )
425 {
426 39 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 31 8 39
427 = defined $self->form->id
428 ? $self->form->id
429 : $EMPTY_STR;
430  
431 my $field_name
432 = defined $render->{nested_name}
433 ? $render->{nested_name}
434 39 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 39 0 39
435  
436 39 my %string = (
437 f => $form_name,
438 n => $field_name,
439 );
440  
441 39 my $id = $self->auto_id;
442 39 $id =~ s/%([fn])/$string{$1}/g;
443  
444 39 ▶ if ( defined( my $count = $self->repeatable_count ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $count = $self->repeatable_count)) 4 35 39
445 4 $id =~ s/%r/$count/g;
446 }
447  
448 39 $render->{attributes}{id} = $id;
449 }
450  
451 1273 return;
452 }
453  
454 sub process_value {
455 1205 ▶ my ( $self, $value ) = @_;
Subroutine process_value: called CC=12 SCAR=24.9
Pod undocumented
456  
457 1205 my $submitted = $self->form->submitted;
458 1205 my $default = $self->default;
459  
460 1205 my $new;
461  
462 1205 ▶ if ($submitted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($submitted) { } 419 786 1205
463 419 ▶ if ( defined $value ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $value) { } 354 65 419
elsif (defined $default) { } 37 28 65
464 354 $new = $value;
465 }
466 elsif ( defined $default ) {
467 37 $new = $EMPTY_STR;
468 }
469 }
470 else {
471 786 $new = $default;
472 }
473  
474 1205 ▶ 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 1193 1205
Condition77%7/9
$submitted and $self->retain_default and defined $new and $new eq $HTML::FormFu::Role::Element::Field::EMPTY_STR
!ll&&!rl&&r
1193012
$submitted and $self->retain_default and defined $new
!ll&&!rl&&r
1193012
$submitted and $self->retain_default
!ll&&!rl&&r
78640712
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
475 && $self->retain_default
476 && defined $new
477 && $new eq $EMPTY_STR )
478 {
479 12 $new = $default;
480 }
481  
482 # if the default value has been changed after FormFu->process has been
483 # called we use it and set the value to that changed default again
484 1205 ▶ if ( $submitted
Branch: 1 branch
BranchTrueFalseTotal
if ($submitted and $self->force_default and defined $default and $new ne $default) 2 1203 1205
Condition100%9/9
$submitted and $self->force_default and defined $default and $new ne $default
!ll&&!rl&&r
1184192
$submitted and $self->force_default and defined $default
!ll&&!rl&&r
1178621
$submitted and $self->force_default
!ll&&!rl&&r
78639227
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
485 && $self->force_default
486 && defined $default
487 && $new ne $default )
488 {
489 2 $new = $default;
490 }
491  
492 1205 return $new;
493 }
494  
495 around render_data_non_recursive => sub {
496 1321 ▶ my ( $orig, $self, $args ) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
497  
498 1321 ▶ my $render = $self->$orig(
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 1296 25 1321
499 { nested_name => xml_escape( $self->nested_name ),
500 comment_attributes => xml_escape( $self->comment_attributes ),
501 container_attributes => xml_escape( $self->container_attributes ),
502 label_attributes => xml_escape( $self->label_attributes ),
503 comment => xml_escape( $self->comment ),
504 label => xml_escape( $self->label ),
505 field_filename => $self->field_filename,
506 label_filename => $self->label_filename,
507 label_tag => $self->label_tag,
508 container_tag => $self->container_tag,
509 error_container_tag => $self->error_container_tag,
510 error_tag => $self->error_tag,
511 reverse_single => $self->reverse_single,
512 reverse_multi => $self->reverse_multi,
513 javascript => $self->javascript,
514 $args ? %$args : (),
515 } );
516  
517 1321 $self->_render_container_class($render);
518 1321 $self->_render_comment_class($render);
519 1321 $self->_render_label($render);
520 1321 $self->_render_value($render);
521 1321 $self->_render_constraint_class($render);
522 1321 $self->_render_inflator_class($render);
523 1321 $self->_render_validator_class($render);
524 1321 $self->_render_transformer_class($render);
525 1321 $self->_render_error_class($render);
526  
527 1321 return $render;
528 383 };
529  
530 sub _render_label {
531 1321 ▶ my ( $self, $render ) = @_;
Subroutine _render_label: called CC=19 SCAR=29.7
532  
533 1321 ▶ if ( !defined $render->{label}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $render->{"label"} and defined $self->auto_label and length $self->auto_label) 6 1315 1321
Condition83%5/6
not defined $render->{"label"} and defined $self->auto_label and length $self->auto_label
!ll&&!rl&&r
131506
not defined $render->{"label"} and defined $self->auto_label
!ll&&!rl&&r
10112146
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
534 && defined $self->auto_label
535 && length $self->auto_label )
536 {
537 my %string = (
538 f => defined $self->form->id ? $self->form->id : '',
539 6 ▶ n => defined $render->{name} ? $render->{name} : '',
Branch: 2 branches
BranchTrueFalseTotal
defined $self->form->id ? : 2 4 6
defined $render->{'name'} ? : 6 0 6
540 );
541  
542 6 my $label = $self->auto_label;
543 6 $label =~ s/%([fn])/$string{$1}/g;
544  
545 6 $render->{label} = $self->form->localize($label);
546 }
547  
548 1321 ▶ 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 1320 1321
Condition83%5/6
defined $render->{"label"} and defined $self->auto_label_class and length $self->auto_label_class
!ll&&!rl&&r
132001
defined $render->{"label"} and defined $self->auto_label_class
!ll&&!rl&&r
12141061
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
549 && defined $self->auto_label_class
550 && length $self->auto_label_class )
551 {
552 1 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 0 1 1
553 = defined $self->form->id
554 ? $self->form->id
555 : $EMPTY_STR;
556  
557 my $field_name
558 = defined $render->{nested_name}
559 ? $render->{nested_name}
560 1 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 1 0 1
561  
562 1 my $type = lc $self->type;
563 1 $type =~ s/:://g;
564  
565 1 my %string = (
566 f => $form_name,
567 n => $field_name,
568 t => $type,
569 );
570  
571 1 my $class = $self->auto_label_class;
572 1 $class =~ s/%([fnt])/$string{$1}/g;
573  
574 1 append_xml_attribute( $render->{label_attributes}, 'class', $class );
575 }
576  
577 1321 ▶ 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 1318 1321
Condition83%5/6
defined $render->{"label"} and defined $self->auto_container_label_class and length $self->auto_container_label_class
!ll&&!rl&&r
131803
defined $render->{"label"} and defined $self->auto_container_label_class
!ll&&!rl&&r
12141043
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
578 && defined $self->auto_container_label_class
579 && length $self->auto_container_label_class )
580 {
581 3 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 2 1 3
582 = defined $self->form->id
583 ? $self->form->id
584 : $EMPTY_STR;
585  
586 my $field_name
587 = defined $render->{nested_name}
588 ? $render->{nested_name}
589 3 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 3 0 3
590  
591 3 my $type = lc $self->type;
592 3 $type =~ s/:://g;
593  
594 3 my %string = (
595 f => $form_name,
596 n => $field_name,
597 t => $type,
598 );
599  
600 3 my $class = $self->auto_container_label_class;
601 3 $class =~ s/%([fnt])/$string{$1}/g;
602  
603 append_xml_attribute( $render->{container_attributes},
604 3 'class', $class );
605 }
606  
607 # label "for" attribute
608 1321 ▶ 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 1294 1321
Condition83%5/6
defined $render->{"label"} and defined $render->{"attributes"}{"id"} and not exists $render->{"label_attributes"}{"for"}
!ll&&!rl&&r
1294027
defined $render->{"label"} and defined $render->{"attributes"}{"id"}
!ll&&!rl&&r
12148027
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
609 && defined $render->{attributes}{id}
610 && !exists $render->{label_attributes}{for} )
611 {
612 27 $render->{label_attributes}{for} = $render->{attributes}{id};
613 }
614  
615 1321 return;
616 }
617  
618 sub _render_comment_class {
619 1321 ▶ my ( $self, $render ) = @_;
Subroutine _render_comment_class: called CC=11 SCAR=24.1
620  
621 1321 ▶ 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 1318 1321
Condition83%5/6
defined $render->{"comment"} and defined $self->auto_comment_class and length $self->auto_comment_class
!ll&&!rl&&r
131803
defined $render->{"comment"} and defined $self->auto_comment_class
!ll&&!rl&&r
1286323
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
622 && defined $self->auto_comment_class
623 && length $self->auto_comment_class )
624 {
625 3 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 2 1 3
626 = defined $self->form->id
627 ? $self->form->id
628 : $EMPTY_STR;
629  
630 my $field_name
631 = defined $render->{nested_name}
632 ? $render->{nested_name}
633 3 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 3 0 3
634  
635 3 my %string = (
636 f => $form_name,
637 n => $field_name,
638 );
639  
640 3 my $class = $self->auto_comment_class;
641 3 $class =~ s/%([fn])/$string{$1}/g;
642  
643 3 append_xml_attribute( $render->{comment_attributes}, 'class', $class );
644 }
645  
646 1321 ▶ 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 1318 1321
Condition83%5/6
defined $render->{"comment"} and defined $self->auto_container_comment_class and length $self->auto_container_comment_class
!ll&&!rl&&r
131803
defined $render->{"comment"} and defined $self->auto_container_comment_class
!ll&&!rl&&r
1286323
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
647 && defined $self->auto_container_comment_class
648 && length $self->auto_container_comment_class )
649 {
650 3 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 2 1 3
651 = defined $self->form->id
652 ? $self->form->id
653 : $EMPTY_STR;
654  
655 my $field_name
656 = defined $render->{nested_name}
657 ? $render->{nested_name}
658 3 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 3 0 3
659  
660 3 my %string = (
661 f => $form_name,
662 n => $field_name,
663 );
664  
665 3 my $class = $self->auto_container_comment_class;
666 3 $class =~ s/%([fn])/$string{$1}/g;
667  
668 append_xml_attribute( $render->{container_attributes},
669 3 'class', $class );
670 }
671  
672 1321 return;
673 }
674  
675 sub _render_value {
676 1321 ▶ my ( $self, $render ) = @_;
Subroutine _render_value: called CC=17 SCAR=28.4
677  
678 1321 my $form = $self->form;
679 1321 my $name = $self->nested_name;
680  
681 1321 my $input;
682  
683 1321 ▶ if ( $self->form->submitted
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form->submitted and defined $name and $self->nested_hash_key_exists($form->input, $name)) 412 909 1321
Condition100%6/6
$self->form->submitted and defined $name and $self->nested_hash_key_exists($form->input, $name)
!ll&&!rl&&r
83178412
$self->form->submitted and defined $name
!ll&&!rl&&r
8292490
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
684 && defined $name
685 && $self->nested_hash_key_exists( $form->input, $name ) )
686 {
687 412 ▶ if ( $self->render_processed_value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->render_processed_value) { } 7 405 412
688 7 $input
689 = $self->get_nested_hash_value( $form->_processed_params,
690 $name, );
691 }
692 else {
693 405 $input = $self->get_nested_hash_value( $form->input, $name, );
694 }
695 }
696  
697 1321 ▶ if ( ref $input eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input eq "ARRAY") 24 1297 1321
698 24 my $elems = $self->form->get_fields( $self->name );
699 24 for ( 0 .. @$elems - 1 ) {
700 42 ▶ if ( $self == $elems->[$_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self == $elems->[$_]) 24 18 42
701 24 $input = $input->[$_];
702 }
703 }
704 }
705  
706 1321 my $value = $self->process_value($input);
707  
708 1321 ▶ if ( !$self->form->submitted
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->form->submitted or $self->render_processed_value and defined $value) 836 485 1321
Condition100%6/6
not $self->form->submitted or $self->render_processed_value and defined $value
l!l&&r!l&&!r
8297485
$self->render_processed_value and defined $value
!ll&&!rl&&r
48417
MC/DC66%2/3
not $self->form->submitted or $self->render_processed_value and defined $value
not $self->form->submitted $self->render_processed_value defined $value
Truth table75%3/4
not(A) or B and C
A= not $self->form->submittedB= $self->render_processed_valueC= defined $value
ABCresult
1XX1
0111
00X0
0100
709 || ( $self->render_processed_value && defined $value ) )
710 {
711 836 for my $deflator ( @{ $self->_deflators } ) {
712 31 $value = $deflator->process($value);
713 }
714 }
715  
716 # handle multiple values for the same name
717 1321 ▶ if ( ref $value eq 'ARRAY' && defined $self->name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY" and defined $self->name) 12 1309 1321
Condition66%2/3
ref $value eq "ARRAY" and defined $self->name
!ll&&!rl&&r
1309012
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
718 12 my $max = $#$value;
719 12 my $fields = $self->form->get_fields( name => $self->name );
720  
721 12 for my $i ( 0 .. $max ) {
722 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
723 12 $value = $value->[$i];
724 12 last;
725 }
726 }
727 }
728  
729 1321 $render->{value} = xml_escape($value);
730  
731 1321 return;
732 }
733  
734 sub _render_container_class {
735 1321 ▶ my ( $self, $render ) = @_;
Subroutine _render_container_class: called CC=5 SCAR=16.1
736  
737 1321 ▶ if ( defined $self->auto_container_class
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->auto_container_class and length $self->auto_container_class) 3 1318 1321
Condition66%2/3
defined $self->auto_container_class and length $self->auto_container_class
!ll&&!rl&&r
131803
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
738 && length $self->auto_container_class )
739 {
740 3 ▶ my $form_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->form->id ? : 2 1 3
741 = defined $self->form->id
742 ? $self->form->id
743 : $EMPTY_STR;
744  
745 my $field_name
746 = defined $render->{nested_name}
747 ? $render->{nested_name}
748 3 ▶ : $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
defined $render->{'nested_name'} ? : 3 0 3
749  
750 3 my $type = lc $self->type;
751 3 $type =~ s/:://g;
752  
753 3 my %string = (
754 f => $form_name,
755 n => $field_name,
756 t => $type,
757 );
758  
759 3 my $class = $self->auto_container_class;
760 3 $class =~ s/%([fnt])/$string{$1}/g;
761  
762 append_xml_attribute( $render->{container_attributes},
763 3 'class', $class );
764 }
765  
766 1321 return;
767 }
768  
769 sub _render_constraint_class {
770 1321 ▶ my ( $self, $render ) = @_;
Subroutine _render_constraint_class: called CC=6 SCAR=18.1
771  
772 1321 my $auto_class = $self->auto_constraint_class;
773  
774 1321 ▶ return if !defined $auto_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $auto_class 1319 2 1321
775  
776 2 for my $c ( @{ $self->_constraints } ) {
777 my %string = (
778 f => defined $self->form->id ? $self->form->id : '',
779 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
780 t => defined $c->type ? lc( $c->type ) : '',
781 );
782  
783 2 $string{t} =~ s/::/_/g;
784 2 $string{t} =~ s/\+//;
785  
786 2 my $class = $auto_class;
787  
788 2 $class =~ s/%([fnt])/$string{$1}/g;
789  
790 append_xml_attribute( $render->{container_attributes},
791 2 'class', $class, );
792 }
793  
794 2 return;
795 }
796  
797 sub _render_inflator_class {
798 1321 ▶ my ( $self, $render ) = @_;
Subroutine _render_inflator_class: called CC=6 SCAR=32.0
799  
800 1321 my $auto_class = $self->auto_inflator_class;
801  
802 1321 ▶ return if !defined $auto_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $auto_class 1321 0 1321
803  
804 0 for my $c ( @{ $self->_inflators } ) {
805 my %string = (
806 f => defined $self->form->id ? $self->form->id : '',
807 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
808 t => defined $c->type ? lc( $c->type ) : '',
809 );
810  
811 0 $string{t} =~ s/::/_/g;
812 0 $string{t} =~ s/\+//;
813  
814 0 my $class = $auto_class;
815  
816 0 $class =~ s/%([fnt])/$string{$1}/g;
817  
818 append_xml_attribute( $render->{container_attributes},
819 0 'class', $class, );
820 }
821  
822 0 return;
823 }
824  
825 sub _render_validator_class {
826 1321 ▶ my ( $self, $render ) = @_;
Subroutine _render_validator_class: called CC=6 SCAR=32.0
827  
828 1321 my $auto_class = $self->auto_validator_class;
829  
830 1321 ▶ return if !defined $auto_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $auto_class 1321 0 1321
831  
832 0 for my $c ( @{ $self->_validators } ) {
833 my %string = (
834 f => defined $self->form->id ? $self->form->id : '',
835 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
836 t => defined $c->type ? lc( $c->type ) : '',
837 );
838  
839 0 $string{t} =~ s/::/_/g;
840 0 $string{t} =~ s/\+//;
841  
842 0 my $class = $auto_class;
843  
844 0 $class =~ s/%([fnt])/$string{$1}/g;
845  
846 append_xml_attribute( $render->{container_attributes},
847 0 'class', $class, );
848 }
849  
850 0 return;
851 }
852  
853 sub _render_transformer_class {
854 1321 ▶ my ( $self, $render ) = @_;
Subroutine _render_transformer_class: called CC=6 SCAR=32.0
855  
856 1321 my $auto_class = $self->auto_transformer_class;
857  
858 1321 ▶ return if !defined $auto_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $auto_class 1321 0 1321
859  
860 0 for my $c ( @{ $self->_transformers } ) {
861 my %string = (
862 f => defined $self->form->id ? $self->form->id : '',
863 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
864 t => defined $c->type ? lc( $c->type ) : '',
865 );
866  
867 0 $string{t} =~ s/::/_/g;
868 0 $string{t} =~ s/\+//;
869  
870 0 my $class = $auto_class;
871  
872 0 $class =~ s/%([fnt])/$string{$1}/g;
873  
874 append_xml_attribute( $render->{container_attributes},
875 0 'class', $class, );
876 }
877  
878 0 return;
879 }
880  
881 sub _render_error_class {
882 1321 ▶ my ( $self, $render ) = @_;
Subroutine _render_error_class: called CC=15 SCAR=40.4
883  
884 1321 my @errors = @{ $self->get_errors( { forced => 1 } ) };
885  
886 1321 ▶ return if !@errors;
Branch: 1 branch
BranchTrueFalseTotal
unless @errors 1274 47 1321
887  
888 47 @errors = map { $_->render_data } @errors;
889  
890 47 $render->{errors} = \@errors;
891  
892 # auto_error_field_class
893 47 my $field_class = $self->auto_error_field_class;
894  
895 47 ▶ if ( defined $field_class && length $field_class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $field_class and length $field_class) 1 46 47
Condition66%2/3
defined $field_class and length $field_class
!ll&&!rl&&r
4601
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
896 my %string = (
897 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
898 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
899 1 );
900  
901 1 $field_class =~ s/%([fn])/$string{$1}->()/ge;
902  
903 1 append_xml_attribute( $render->{attributes}, 'class', $field_class );
904 }
905  
906 47 my @container_class;
907  
908 # auto_container_error_class
909 47 my $auto_class = $self->auto_container_error_class;
910  
911 47 ▶ if ( defined $auto_class && length $auto_class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $auto_class and length $auto_class) 2 45 47
Condition66%2/3
defined $auto_class and length $auto_class
!ll&&!rl&&r
4502
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
912 my %string = (
913 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
914 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
915 2 );
916  
917 2 $auto_class =~ s/%([fn])/$string{$1}->()/ge;
918  
919 2 push @container_class, $auto_class;
920 }
921  
922 # auto_container_per_error_class
923 47 my $item_class = $self->auto_container_per_error_class;
924  
925 47 ▶ if ( defined $item_class && length $item_class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $item_class and length $item_class) 1 46 47
Condition66%2/3
defined $item_class and length $item_class
!ll&&!rl&&r
4601
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
926 1 for my $error (@errors) {
927 my %string = (
928 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
929 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
930 1 ▶ s => sub { $error->{stage} },
Subroutine __ANON__: called CC=1 SCAR=0.0
931 1 ▶ t => sub { lc $error->{type} },
Subroutine __ANON__: called CC=1 SCAR=0.0
932 1 );
933  
934 1 my $string = $item_class;
935 1 $string =~ s/%([fnst])/$string{$1}->()/ge;
936  
937 1 push @container_class, $string;
938 }
939 }
940  
941 47 map { append_xml_attribute( $render->{container_attributes}, 'class', $_ ) }
942 uniq @container_class;
943  
944 47 my @error_container_class;
945  
946 47 ▶ if ( $self->error_container_tag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error_container_tag) 0 47 47
947  
948 # auto_error_container_class
949 0 my $auto_class = $self->auto_error_container_class;
950  
951 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
952 my %string = (
953 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
954 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
955 0 );
956  
957 0 $auto_class =~ s/%([fn])/$string{$1}->()/ge;
958  
959 0 push @error_container_class, $auto_class;
960 }
961  
962 # auto_container_per_error_class
963 0 my $item_class = $self->auto_container_per_error_class;
964  
965 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
966 0 for my $error (@errors) {
967 my %string = (
968 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
969 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
970 0 ▶ s => sub { $error->{stage} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
971 0 ▶ t => sub { lc $error->{type} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
972 0 );
973  
974 0 my $string = $item_class;
975 0 $string =~ s/%([fnst])/$string{$1}->()/ge;
976  
977 0 push @error_container_class, $string;
978 }
979 }
980  
981 map {
982 0 append_xml_attribute( $render->{error_container_attributes},
983 0 'class', $_ )
984 } uniq @error_container_class;
985 }
986  
987 47 return;
988 }
989  
990 sub render_label {
991 6 ▶ my ($self) = @_;
Subroutine render_label: called CC=1 SCAR=0.0
Pod undocumented
992  
993 6 my $render = $self->render_data;
994  
995 6 return $self->_string_label($render);
996 }
997  
998 sub render_field {
999 6 ▶ my ($self) = @_;
Subroutine render_field: called CC=1 SCAR=0.0
Pod undocumented
1000  
1001 6 my $render = $self->render_data;
1002  
1003 6 return $self->_string_field($render);
1004 }
1005  
1006 sub _string_field_start {
1007 0 ▶ my ( $self, $render ) = @_;
Subroutine _string_field_start: not called CC=8 SCAR=42.8
1008  
1009 # field wrapper template - start
1010  
1011 0 my $html = '';
1012  
1013 0 ▶ if ( defined $render->{container_tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"container_tag"}) 0 0 0
1014 $html .= sprintf '<%s%s>',
1015 $render->{container_tag},
1016 0 process_attrs( $render->{container_attributes} );
1017 }
1018  
1019 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
1020 0 $html .= sprintf "\n%s", $self->_string_label($render);
1021 }
1022  
1023 0 $html .= $self->_string_errors($render);
1024  
1025 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
1026 && $render->{label_tag} ne 'legend'
1027 && !$render->{reverse_single} )
1028 {
1029 0 $html .= sprintf "\n%s", $self->_string_label($render);
1030 }
1031  
1032 0 ▶ if ( defined $render->{container_tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"container_tag"}) 0 0 0
1033 0 $html .= "\n";
1034 }
1035  
1036 0 return $html;
1037 }
1038  
1039 sub _string_label {
1040 93 ▶ my ( $self, $render ) = @_;
Subroutine _string_label: called CC=1 SCAR=0.0
1041  
1042 # label template
1043  
1044 my $html = sprintf "<%s%s>%s</%s>",
1045 $render->{label_tag},
1046 process_attrs( $render->{label_attributes} ),
1047 $render->{label},
1048 $render->{label_tag},
1049 93 ;
1050  
1051 93 return $html;
1052 }
1053  
1054 sub _string_errors {
1055 703 ▶ my ( $self, $render ) = @_;
Subroutine _string_errors: called CC=5 SCAR=16.6
1056  
1057 703 ▶ return '' if !$render->{errors};
Branch: 1 branch
BranchTrueFalseTotal
unless $render->{"errors"} 660 43 703
1058  
1059 43 my $html = '';
1060  
1061 43 ▶ if ( $render->{error_container_tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($render->{"error_container_tag"}) 0 43 43
1062 $html .= sprintf qq{<%s%s>\n},
1063 $render->{error_container_tag},
1064 0 process_attrs( $render->{error_container_attributes} ),
1065 ;
1066 }
1067  
1068 43 my @error_html;
1069 43 for my $error ( @{ $render->{errors} } ) {
1070 push @error_html, sprintf qq{<%s%s>%s</%s>},
1071 $render->{error_tag},
1072 process_attrs( $error->{attributes} ),
1073 $error->{message},
1074 $render->{error_tag},
1075 46 ;
1076 }
1077 43 $html .= join "\n", @error_html;
1078  
1079 43 ▶ if ( $render->{error_container_tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($render->{"error_container_tag"}) 0 43 43
1080 0 $html .= sprintf qq{\n</%s>}, $render->{error_container_tag};
1081 }
1082  
1083 43 return $html;
1084 }
1085  
1086 sub _string_field_end {
1087 0 ▶ my ( $self, $render ) = @_;
Subroutine _string_field_end: not called CC=7 SCAR=40.3
1088  
1089 # field wrapper template - end
1090  
1091 0 my $html = '';
1092  
1093 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
1094 && $render->{label_tag} ne 'legend'
1095 && $render->{reverse_single} )
1096 {
1097 0 $html .= sprintf "\n%s", $self->_string_label($render);
1098 }
1099  
1100 0 ▶ if ( defined $render->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"comment"}) 0 0 0
1101 $html .= sprintf "\n<span%s>\n%s\n</span>",
1102 process_attrs( $render->{comment_attributes} ),
1103 $render->{comment},
1104 0 ;
1105 }
1106  
1107 0 ▶ if ( defined $render->{container_tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"container_tag"}) 0 0 0
1108 0 $html .= sprintf "\n</%s>", $render->{container_tag},;
1109 }
1110  
1111 0 ▶ if ( defined $render->{javascript} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"javascript"}) 0 0 0
1112 $html .= sprintf qq{\n<script type="text/javascript">\n%s\n</script>},
1113 $render->{javascript},
1114 0 ;
1115 }
1116  
1117 0 return $html;
1118 }
1119  
1120 around clone => sub {
1121 180 ▶ my $orig = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
1122 180 my $self = shift;
1123  
1124 180 my $clone = $self->$orig(@_);
1125  
1126 180 for my $list ( qw(
1127 _filters _constraints _inflators _validators _transformers
1128 _deflators _errors _plugins )
1129 )
1130 {
1131 1440 $clone->$list( [ map { $_->clone } @{ $self->$list } ] );
1132  
1133 1440 map { $_->parent($clone) } @{ $clone->$list };
1134 }
1135  
1136 180 $clone->comment_attributes( Clone::clone( $self->comment_attributes ) );
1137 180 $clone->container_attributes( Clone::clone( $self->container_attributes ) );
1138 180 $clone->label_attributes( Clone::clone( $self->label_attributes ) );
1139  
1140 180 return $clone;
1141 383 };
1142  
1143 383 1;
1144  
1145 __END__
1146  
1147 =pod
1148  
1149 =encoding UTF-8
1150  
1151 =head1 NAME
1152  
1153 HTML::FormFu::Role::Element::Field - Role for all form-field elements
1154  
1155 =head1 VERSION
1156  
1157 version 2.06
1158  
1159 =head1 DESCRIPTION
1160  
1161 Base-class for all form-field elements.
1162  
1163 =head1 METHODS
1164  
1165 =head2 default
1166  
1167 Set the form-field's default value.
1168  
1169 Is an L<output accessor|HTML::FormFu/OUTPUT ACCESSORS>.
1170  
1171 =head2 value
1172  
1173 For most fields, L</value> is an alias for L</default>.
1174  
1175 For the L<HTML::FormFu::Element::Checkbox> and
1176 L<HTML::FormFu::Element::Radio> elements, L</value> sets what the value of
1177 the field will be if it is checked or selected. If the L</default> is the
1178 same as the L</value>, then the field will be checked or selected when
1179 rendered.
1180  
1181 For the L<HTML::FormFu::Element::Radiogroup> and
1182 L<HTML::FormFu::Element::Select> elements, the L</value> is ignored:
1183 L<values|HTML::FormFu::Role::Element::Group/values> or
1184 L<options|HTML::FormFu::Role::Element::Group/options> provides the equivalent
1185 function.
1186  
1187 Is an L<output accessor|HTML::FormFu/OUTPUT ACCESSORS>.
1188  
1189 =head2 non_param
1190  
1191 Arguments: bool
1192  
1193 Default Value: false
1194  
1195 If true, values for this field are never returned by L<HTML::FormFu/params>,
1196 L<HTML::FormFu/param> and L<HTML::FormFu/valid>.
1197  
1198 This is useful for Submit buttons, when you only use its value as an
1199 L<indicator|HTML::FormFu/indicator>
1200  
1201 =head2 placeholder
1202  
1203 Sets the HTML5 attribute C<placeholder> to the specified value.
1204  
1205 Is an L<output accessor|HTML::FormFu/OUTPUT ACCESSORS>.
1206  
1207 =head2 javascript
1208  
1209 Arguments: [$javascript]
1210  
1211 If set, the contents will be rendered within a C<script> tag, within the
1212 field's container.
1213  
1214 =head2 retain_default
1215  
1216 If L</retain_default> is true and the form was submitted, but the field
1217 didn't have a value submitted, then when the form is redisplayed to the user
1218 the field will have its value set to its default value, rather than the
1219 usual behaviour of having an empty value.
1220  
1221 Default Value: C<false>
1222  
1223 =head2 force_default
1224  
1225 If L</force_default> is true and the form was submitted, and the field
1226 has a default/value set, then when the form is redisplayed to the user
1227 the field will have its value set to its default value.
1228  
1229 If the default value is being changed after FormFu->process is being called
1230 the later default value is respected for rendering, *but* nevertheless the
1231 input value doesn't respect that, it will remain the first value.
1232  
1233 Default Value: C<false>
1234  
1235 =head2 default_empty_value
1236  
1237 Designed for use by Checkbox fields. Normally if a checkbox is not checked,
1238 no value is submitted for that field. If C<default_empty_value> is true,
1239 the Checkbox field is given an empty value during
1240 L<process|HTML::FormFu/process>. Please note that, with this setting,
1241 the checkbox gets an EMPTY value (as opposed to no value at all without
1242 enabling it), NOT the default value assigned to the element (if any).
1243  
1244 Default Value: C<false>
1245  
1246 =head2 repeatable_count
1247  
1248 Only available for fields attached to a
1249 L<Repeatable|HTML::FormFu::Element::Repeatable> element, after
1250 L<< $repeatable->repeat($count) | HTML::FormFu::Element::Repeatable/repeat >>
1251 has been called.
1252  
1253 The value is inherited from
1254 L<HTML::FormFu::Element::Repeatable/repeatable_count>.
1255  
1256 =head2 clone
1257  
1258 See L<HTML::FormFu/clone> for details.
1259  
1260 =head2 deflators
1261  
1262 See L<HTML::FormFu/deflators> for details.
1263  
1264 =head2 deflator
1265  
1266 See L<HTML::FormFu/deflator> for details.
1267  
1268 =head2 auto_datalist_id
1269  
1270 Arguments: [$string]
1271  
1272 If any L<Input|HTML::FormFu::Role::Element::Input> element had a datalist,
1273 but does not have L<HTML::FormFu::Role::Element::Input/datalist_id> set,
1274 L</auto_datalist_id> is used to generate the datalist id.
1275  
1276 The following character substitution will be performed: C<%f> will be
1277 replaced by L<< $form->id|/id >>, C<%n> will be replaced by
1278 L<< $field->name|HTML::FormFu::Element/name >>, C<%r> will be replaced by
1279 L<< $block->repeatable_count|HTML::FormFu::Element::Repeatable/repeatable_count >>.
1280  
1281 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1282  
1283 =head1 FORM LOGIC AND VALIDATION
1284  
1285 =head2 filters
1286  
1287 See L<HTML::FormFu/filters> for details.
1288  
1289 =head2 filter
1290  
1291 See L<HTML::FormFu/filter> for details.
1292  
1293 =head2 constraints
1294  
1295 See L<HTML::FormFu/constraints> for details.
1296  
1297 =head2 constraint
1298  
1299 See L<HTML::FormFu/constraint> for details.
1300  
1301 =head2 inflators
1302  
1303 See L<HTML::FormFu/inflators> for details.
1304  
1305 =head2 inflator
1306  
1307 See L<HTML::FormFu/inflator> for details.
1308  
1309 =head2 validators
1310  
1311 See L<HTML::FormFu/validators> for details.
1312  
1313 =head2 validator
1314  
1315 See L<HTML::FormFu/validator> for details.
1316  
1317 =head2 transformers
1318  
1319 See L<HTML::FormFu/transformers> for details.
1320  
1321 =head2 transformer
1322  
1323 See L<HTML::FormFu/transformer> for details.
1324  
1325 =head1 CUSTOMIZING GENERATED MARKUP
1326  
1327 Each field is, by default, wrapped in a container.
1328 Each container may also contain a label, a comment, and after an invalid
1329 submission may contain 1 or more error messages.
1330  
1331 Example of generated form:
1332  
1333 1 <form action="" method="post">
1334 2 <div class="has-errors"> # container
1335 3 <ul class="errors"> # error container
1336 4 <li> # error message
1337 5 This field must contain an email address
1338 6 </li>
1339 7 </li>
1340 8 <label>Foo</label> # label
1341 9 <input name="foo" type="text" value="example.com" />
1342 10 <span class="comment"> # comment
1343 11 This is Foo
1344 12 </span>
1345 13 </div>
1346 14 </form>
1347  
1348 # Line 2 starts the 'container' - by default a DIV.
1349 # Line 2 starts an error container, which may contain 1 or more error
1350 messages - in this case, a unordered list (UL).
1351 # Line 4 starts a single error message - in this case, a list item (LI).
1352 # Line 8 shows a 'label'.
1353 # Line 9 shows the field's 'input' tag.
1354 # Lines 10 starts a 'comment'.
1355  
1356 To re-order the various parts of each form (label, input, errors, etc) and
1357 arbitrary extra tags, see the L<layout|/layout> method.
1358  
1359 =head2 CONTAINER
1360  
1361 =head3 container_tag
1362  
1363 Default value: 'div'
1364  
1365 The container wrapping each entire field, any label, comment, and errors.
1366  
1367 =head3 container_attributes
1368  
1369 Attributes added to the container tag.
1370  
1371 Is an L<attribute accessor|HTML::FormFu/ATTRIBUTE ACCESSOR>.
1372  
1373 =head3 auto_container_class
1374  
1375 Default Value: '%t'
1376  
1377 If set, then the container of each field will be given a class-name based on
1378 the given pattern.
1379  
1380 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>.
1381  
1382 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1383  
1384 =head3 auto_container_label_class
1385  
1386 Default Value: 'label'
1387  
1388 If set, and if the field has a L<label|/label>, the container will be given a
1389 class-name based on the given pattern.
1390  
1391 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>.
1392  
1393 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1394  
1395 =head3 auto_container_comment_class
1396  
1397 Default Value: '%t'
1398  
1399 If set, and if the field has a
1400 L<comment|HTML::FormFu::Role::Element::Field/comment>, the container will be
1401 given a class-name based on the given pattern.
1402  
1403 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>.
1404  
1405 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1406  
1407 =head3 auto_container_error_class
1408  
1409 Default Value: 'error'
1410  
1411 If set, then the container of each field with an error will be given a
1412 class-name based on the given pattern.
1413  
1414 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>.
1415  
1416 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1417  
1418 =head3 auto_container_per_error_class
1419  
1420 Default Value: 'error_%s_%t'
1421  
1422 If set, then the container of each field with an error will be given a
1423 class-name based on the given pattern.
1424  
1425 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>, C<%s>.
1426  
1427 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1428  
1429 =head2 FORM FIELD
1430  
1431 =head3 auto_id
1432  
1433 If set, then the field will be given an L<id|HTML::FormFu::Element/id>
1434 attribute, if it doesn't have one already.
1435  
1436 E.g., setting C<< $form->auto_id('%n') >> will make each field have an ID
1437 the same as the field's name. This makes our form config simpler, and ensures
1438 we don't need to manually update IDs if any field names are changed.
1439  
1440 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%r>.
1441  
1442 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1443  
1444 =head2 LABEL
1445  
1446 =head3 label
1447  
1448 Set a label to communicate the purpose of the form-field to the user.
1449  
1450 Is an L<output accessor|HTML::FormFu/OUTPUT ACCESSORS>.
1451  
1452 =head3 auto_label
1453  
1454 If L<label|/label> isn't already set, the value of L</auto_label> is passed through
1455 L<localize|HTML::FormFu/localize> to generate a label.
1456  
1457 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>.
1458  
1459 The generated string will be passed to L</localize> to create the label.
1460  
1461 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1462  
1463 =head3 label_tag
1464  
1465 Default value: 'label'
1466 (except L<Checkboxgroup|HTML::FormFu::Element::Checkboxgroup>)
1467  
1468 Default value: 'legend'
1469 (only L<Checkboxgroup|HTML::FormFu::Element::Checkboxgroup>)
1470  
1471 Set which tag is used to wrap a L<label|/label>.
1472  
1473 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1474  
1475 =head3 label_attributes
1476  
1477 Attributes added to the label container.
1478  
1479 Is an L<attribute accessor|HTML::FormFu/ATTRIBUTE ACCESSOR>.
1480  
1481 =head2 COMMENT
1482  
1483 =head3 comment
1484  
1485 Set a comment to be displayed along with the form-field.
1486  
1487 Is an L<output accessor|HTML::FormFu/OUTPUT ACCESSORS>.
1488  
1489 =head3 comment_attributes
1490  
1491 Attributes added to the comment container.
1492  
1493 Is an L<attribute accessor|HTML::FormFu/ATTRIBUTE ACCESSOR>.
1494  
1495 =head3 auto_comment_class
1496  
1497 Default Value: '%t'
1498  
1499 If set, and if the field has a
1500 L<comment|HTML::FormFu::Role::Element::Field/comment>, the comment tag will
1501 be given a class-name based on the given pattern.
1502  
1503 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>.
1504  
1505 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1506  
1507 =head2 ERROR CONTAINER
1508  
1509 =head3 error_container_tag
1510  
1511 If set, and if the field has any errors, a container of this type is
1512 wrapped around all of the field error messages.
1513  
1514 # Example - this would wrap each individual error in a 'li' tag,
1515 # with a single 'ul' tag wrapped around all the errors.
1516  
1517 element:
1518 name: foo
1519 error_container_tag: ul
1520 error_tag: li
1521  
1522 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1523  
1524 =head3 auto_error_container_class
1525  
1526 Add a class-name to the error container.
1527  
1528 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>.
1529  
1530 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1531  
1532 =head3 auto_error_container_per_error_class
1533  
1534 Add a class-name to the error container for each error on that field.
1535  
1536 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>, C<%s>.
1537  
1538 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1539  
1540 =head2 ERROR MESSAGES
1541  
1542 =head3 error_tag
1543  
1544 Default value: 'span'
1545  
1546 Sets the tag used to wrap each individual error message.
1547  
1548 Defaults to C<span>.
1549  
1550 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1551  
1552 =head3 auto_error_message
1553  
1554 Default Value: 'form_%s_%t'
1555  
1556 If set, then each error will be given an auto-generated
1557 L<message|HTML::FormFu::Exception::Input/message>, if it doesn't have one
1558 already.
1559  
1560 The generated string will be passed to L</localize> to create the message.
1561  
1562 For example, a L<Required constraint|HTML::FormFu::Constraint::Required>
1563 will return the string C<form_constraint_required>. Under the default
1564 localization behaviour, the appropriate message for
1565 C<form_constraint_required> will be used from the default I18N package.
1566  
1567 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>, C<%s>.
1568  
1569 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1570  
1571 =head3 error_attributes
1572  
1573 Set attributes on the tag of each error message.
1574  
1575 Is an L<attribute accessor|HTML::FormFu/ATTRIBUTE ACCESSOR>.
1576  
1577 =head3 auto_error_field_class
1578  
1579 Upon error, add a class name firectly to the field tag (e.g. C<input>, C<select> tag).
1580  
1581 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>.
1582  
1583 =head3 auto_error_class
1584  
1585 Default Value: 'error_%s_%t'
1586  
1587 Add a class-name to the tag of each error message.
1588  
1589 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>, C<%s>.
1590  
1591 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1592  
1593 =head2 PROCESSOR CLASSES
1594  
1595 =head3 auto_constraint_class
1596  
1597 Add a class-name to the container tag, for each constraint added to the field.
1598  
1599 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>.
1600  
1601 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1602  
1603 =head3 auto_inflator_class
1604  
1605 Add a class-name to the container tag, for each inflator added to the field.
1606  
1607 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>.
1608  
1609 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1610  
1611 =head3 auto_validator_class
1612  
1613 Add a class-name to the container tag, for each validator added to the field.
1614  
1615 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>.
1616  
1617 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1618  
1619 =head3 auto_transformer_class
1620  
1621 Add a class-name to the container tag, for each transformer added to the field.
1622  
1623 Supports L<substitutions|HTML::FormFu/ATTRIBUTE SUBSTITUTIONS>: C<%f>, C<%n>, C<%t>.
1624  
1625 Is an L<inheriting accessor|HTML::FormFu/INHERITING ACCESSORS>.
1626  
1627 =head2 REORDERING FIELD COMPONENTS
1628  
1629 =head2 layout
1630  
1631 Specify the order that each sub-part of the element should appear in the
1632 rendered markup.
1633  
1634 # Default Value
1635 $element->layout( [
1636 'errors',
1637 'label',
1638 'field',
1639 'comment',
1640 'javascript',
1641 ] );
1642  
1643 Example: Move the form field (the input tag or equivalent) inside the label
1644 tag, after the label text.
1645 Remove the comment - this will now never be rendered.
1646  
1647 # YAML config
1648 layout:
1649 - errors
1650 - label:
1651 - label_text
1652 - field
1653 - javascript
1654  
1655 # prettified example of rendered markup
1656 <div>
1657 <span>This field is required.</span>
1658 <label>
1659 Foo
1660 <input name="foo" type="text" />
1661 </label>
1662 </div>
1663  
1664 Example: Don't wrap the label text inside it's usual tag.
1665 Insert the form field (the input tag or equivalent) inside an arbitrary
1666 extra tag.
1667  
1668 # YAML config
1669 layout:
1670 - errors
1671 - label_text
1672 -
1673 div:
1674 attributes:
1675 class: xxx
1676 content: field
1677 - comment
1678 - javascript
1679  
1680 # prettified example of rendered markup
1681 <div>
1682 <span>This field is required.</span>
1683 Foo
1684 <div class="xxx">
1685 <input name="foo" type="text" />
1686 </div>
1687 </div>
1688  
1689 The following elements override the default L<layout> value:
1690  
1691 =over
1692  
1693 =item L<HTML::FormFu::Element::Checkboxgroup|HTML::FormFu::Element::Checkboxgroup>
1694  
1695 =item L<HTML::FormFu::Element::Hidden|HTML::FormFu::Element::Hidden>
1696  
1697 =back
1698  
1699 =head3 Specification
1700  
1701 The L<layout|/layout> method accepts an array-ref, hash-ref, or string
1702 argument.
1703  
1704 The processing is recursive, so each item in an array-ref may be any value
1705 accepted by the L<layout|/layout> method.
1706  
1707 A hash-ref must contain a single key and value pair.
1708 If the hash key is the string C<label>, it creates a C<label> tag, using any
1709 previously defined L<LABEL|/LABEL> customizations.
1710 This allows the label tag to contains other elements, such as the form field.
1711  
1712 All other hash key values are asssumed to be an arbitrary block tag name.
1713 The value must be a hash-ref, and may contain one or both C<attributes> or
1714 C<content> keys.
1715  
1716 Any C<attributes> value must be a hash-ref, whose key/values are added to
1717 the block tag. No processing or expansion is done to the C<attributes>
1718 hash-ref at all.
1719  
1720 The C<content> value may be anything accepted by the L<layout|/layout>
1721 method.
1722  
1723 The following strings are accepted:
1724  
1725 =over
1726  
1727 =item errors
1728  
1729 Renders the element error messages.
1730  
1731 See L<ERROR CONTAINER|/"ERROR CONTAINER"> and
1732 L<ERROR MESSAGES|/"ERROR MESSAGES"> to customize the tags and attributes.
1733  
1734 =item label
1735  
1736 Renders the element L<label|/label>.
1737  
1738 See L<LABEL|/LABEL> to customize the tag and attributes.
1739  
1740 =item label_text
1741  
1742 Renders the element L<label|/label> text, without the usual
1743 L<label_tag|/label_tag>.
1744  
1745 =item field
1746  
1747 Renders the form field control (an input tag, button, or other control).
1748  
1749 =item comment
1750  
1751 Renders the element L<comment|/comment>.
1752  
1753 See L<COMMENT|/COMMENT> to customize the tag and attributes.
1754  
1755 =item javascript
1756  
1757 Renders a C<script> tag containing any L<javascript|/javascript>.
1758  
1759 =back
1760  
1761 =head2 multi_layout
1762  
1763 Specify the order that each sub-part of each element within a
1764 L<HTML::FormFu::Element::Multi|HTML::FormFu::Element::Multi> should
1765 appear in the rendered markup.
1766  
1767 # Default Value
1768 $element->multi_layout( [
1769 'label',
1770 'field',
1771 ] );
1772  
1773 Example: Swap the label/field order. This is equivalent to the
1774 now-deprecated L<reverse_multi|/reverse_multi> method.
1775  
1776 # YAML config
1777 multi_layout:
1778 - field
1779 - label
1780  
1781 The following elements override the default C<multi_layout> value:
1782  
1783 =over
1784  
1785 =item L<HTML::FormFu::Element::Checkbox|HTML::FormFu::Element::Checkbox>
1786  
1787 =back
1788  
1789 =head1 RENDERING
1790  
1791 =head2 field_filename
1792  
1793 The template filename to be used for just the form field - not including the
1794 display of any container, label, errors, etc.
1795  
1796 Must be set by more specific field classes.
1797  
1798 =head2 label_filename
1799  
1800 The template filename to be used to render the label.
1801  
1802 Defaults to C<label>.
1803  
1804 =head1 ERROR HANDLING
1805  
1806 =head2 get_errors
1807  
1808 See L<HTML::FormFu/get_errors> for details.
1809  
1810 =head2 add_error
1811  
1812 =head2 clear_errors
1813  
1814 See L<HTML::FormFu/clear_errors> for details.
1815  
1816 =head1 INTROSPECTION
1817  
1818 =head2 get_deflators
1819  
1820 See L<HTML::FormFu/get_deflators> for details.
1821  
1822 =head2 get_deflator
1823  
1824 See L<HTML::FormFu/get_deflator> for details.
1825  
1826 =head2 get_filters
1827  
1828 See L<HTML::FormFu/get_filters> for details.
1829  
1830 =head2 get_filter
1831  
1832 See L<HTML::FormFu/get_filter> for details.
1833  
1834 =head2 get_constraints
1835  
1836 See L<HTML::FormFu/get_constraints> for details.
1837  
1838 =head2 get_constraint
1839  
1840 See L<HTML::FormFu/get_constraint> for details.
1841  
1842 =head2 get_inflators
1843  
1844 See L<HTML::FormFu/get_inflators> for details.
1845  
1846 =head2 get_inflator
1847  
1848 See L<HTML::FormFu/get_inflator> for details.
1849  
1850 =head2 get_validators
1851  
1852 See L<HTML::FormFu/get_validators> for details.
1853  
1854 =head2 get_validator
1855  
1856 See L<HTML::FormFu/get_validator> for details.
1857  
1858 =head2 get_transformers
1859  
1860 See L<HTML::FormFu/get_transformers> for details.
1861  
1862 =head2 get_transformer
1863  
1864 See L<HTML::FormFu/get_transformer> for details.
1865  
1866 =head2 get_errors
1867  
1868 See L<HTML::FormFu/get_errors> for details.
1869  
1870 =head2 clear_errors
1871  
1872 See L<HTML::FormFu/clear_errors> for details.
1873  
1874 =head1 DEPRECATED METHODS
1875  
1876 =over
1877  
1878 =item reverse_single
1879  
1880 See L<layout|/layout> instead.
1881  
1882 =item reverse_multi
1883  
1884 See L<multi_layout|/multi_layout> instead.
1885  
1886 =item errors_filename
1887  
1888 See L<layout_errors_filename|/layout_errors_filename> instead.
1889  
1890 =back
1891  
1892 =head1 SEE ALSO
1893  
1894 Base-class for L<HTML::FormFu::Role::Element::Group>,
1895 L<HTML::FormFu::Role::Element::Input>,
1896 L<HTML::FormFu::Element::Multi>,
1897 L<HTML::FormFu::Element::ContentButton>,
1898 L<HTML::FormFu::Element::Textarea>.
1899  
1900 Is a sub-class of, and inherits methods from L<HTML::FormFu::Element>
1901  
1902 L<HTML::FormFu>
1903  
1904 =head1 AUTHOR
1905  
1906 Carl Franks, C<cfranks@cpan.org>
1907  
1908 =head1 LICENSE
1909  
1910 This library is free software, you can redistribute it and/or modify it under
1911 the same terms as Perl itself.
1912  
1913 =head1 AUTHOR
1914  
1915 Carl Franks <cpan@fireartist.com>
1916  
1917 =head1 COPYRIGHT AND LICENSE
1918  
1919 This software is copyright (c) 2018 by Carl Franks.
1920  
1921 This is free software; you can redistribute it and/or modify it under
1922 the same terms as the Perl 5 programming language system itself.
1923  
1924 =cut
« lib/HTML/FormFu/Attribute.pm ↑ Summary lib/HTML/FormFu/Role/FormAndBlockMethods.pm »