lib/HTML/FormFu.pm

filter: Statementstmt 92.8% 557 / 600 Branchbran 72.0% 193 / 268 Conditioncond 73.5% 39 / 53 MC/DCmcdc 52.9% 18 / 34 Subroutinesub 93.4% 71 / 76 Podpod 81.8% 18 / 22 totaltotal 85.0% 896 / 1053 SCAR 56.6
CC
186
Cov
86%
process
24.3
_transform_input
21.8
_validate_input
15.1
CRAP 287.9
« lib/HTML/FormFu/Role/FormAndBlockMethods.pm ↑ Summary lib/HTML/FormFu/Util.pm »
1 403 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu;
4 403 $HTML::FormFu::VERSION = '2.06';
5 # ABSTRACT: HTML Form Creation, Rendering and Validation Framework
6  
7 403 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 403 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 403 with 'HTML::FormFu::Role::Render',
11 'HTML::FormFu::Role::CreateChildren',
12 'HTML::FormFu::Role::GetProcessors',
13 'HTML::FormFu::Role::ContainsElements',
14 'HTML::FormFu::Role::ContainsElementsSharedWithField',
15 'HTML::FormFu::Role::FormAndBlockMethods',
16 'HTML::FormFu::Role::FormAndElementMethods',
17 'HTML::FormFu::Role::FormBlockAndFieldMethods',
18 'HTML::FormFu::Role::NestedHashUtils',
19 'HTML::FormFu::Role::Populate',
20 'HTML::FormFu::Role::CustomRoles';
21  
22 403 use HTML::FormFu::Attribute qw(
23 mk_attrs
24 mk_attr_accessors
25 mk_output_accessors
26 mk_inherited_accessors
27 mk_inherited_merging_accessors
28 403 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 403 ▶use HTML::FormFu::Constants qw( $EMPTY_STR );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 403 ▶use HTML::FormFu::Constraint;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 403 ▶use HTML::FormFu::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 403 ▶use HTML::FormFu::FakeQuery;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 403 ▶use HTML::FormFu::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 403 ▶use HTML::FormFu::Inflator;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 403 ▶use HTML::FormFu::Localize;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 403 use HTML::FormFu::ObjectUtil qw(
37 form
38 load_config_file load_config_filestem
39 clone stash
40 parent
41 _load_file
42 403 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
43 403 use HTML::FormFu::Util qw(
44 DEBUG
45 DEBUG_PROCESS
46 DEBUG_CONSTRAINTS
47 debug
48 require_class _get_elements
49 xml_escape split_name
50 _parse_args process_attrs
51 _filter_components
52 403 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 403 ▶use Clone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
55 403 ▶use List::Util 1.45 qw( first any none uniq );
Subroutine BEGIN: called CC=1 SCAR=0.0
56 403 ▶use Scalar::Util qw( blessed weaken reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
57 403 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 use overload (
60 'eq' => '_string_equals',
61 '==' => '_object_equals',
62 164 ▶ '""' => sub { return shift->render },
Subroutine __ANON__: called CC=1 SCAR=0.0
63 1 ▶ 'bool' => sub {1},
Subroutine __ANON__: called CC=1 SCAR=0.0
64 403 'fallback' => 1,
65 403 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 403 __PACKAGE__->mk_attr_accessors(qw( id action enctype method ));
68  
69 403 for my $name ( qw(
70 _elements
71 _output_processors
72 _valid_names
73 _plugins
74 _models
75 ) )
76 {
77 has $name => (
78 is => 'rw',
79 981 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
80 2015 lazy => 1,
81 isa => 'ArrayRef',
82 );
83 }
84  
85 has languages => (
86 is => 'rw',
87 60 ▶ default => sub { ['en'] },
Subroutine __ANON__: called CC=1 SCAR=0.0
88 403 lazy => 1,
89 isa => 'ArrayRef',
90 traits => ['Chained'],
91 );
92  
93 has input => (
94 is => 'rw',
95 26 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
96 403 lazy => 1,
97 isa => 'HashRef',
98 traits => ['Chained'],
99 );
100  
101 has _processed_params => (
102 is => 'rw',
103 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 403 lazy => 1,
105 isa => 'HashRef',
106 );
107  
108 403 has form_error_message_class => (
109 is => 'rw',
110 default => 'form_error_message',
111 lazy => 1,
112 );
113  
114 403 our @MULTIFORM_SHARED = ( qw(
115 javascript
116 javascript_src
117 indicator
118 filename
119 query_type
120 force_error_message
121 localize_class
122 tt_module
123 nested_name
124 nested_subscript
125 default_model
126 tmp_upload_dir
127 params_ignore_underscore
128 ) );
129  
130 403 for (@MULTIFORM_SHARED) {
131 5239 has $_ => (
132 is => 'rw',
133 traits => ['Chained'],
134 );
135 }
136  
137 403 has submitted => ( is => 'rw', traits => ['Chained'] );
138 403 has query => ( is => 'rw', traits => ['Chained'] );
139  
140 403 has _auto_fieldset => ( is => 'rw' );
141  
142 403 __PACKAGE__->mk_output_accessors(qw( form_error_message ));
143  
144 403 *elements = \&element;
145 403 *constraints = \&constraint;
146 403 *filters = \&filter;
147 403 *deflators = \&deflator;
148 403 *inflators = \&inflator;
149 403 *validators = \&validator;
150 403 *transformers = \&transformer;
151 403 *output_processors = \&output_processor;
152 403 *loc = \&localize;
153 403 *plugins = \&plugin;
154 403 *add_plugins = \&add_plugin;
155  
156 403 our $build_defaults = {
157 action => '',
158 method => 'post',
159 filename => 'form',
160 render_method => 'string',
161 tt_args => {},
162 tt_module => 'Template',
163 query_type => 'CGI',
164 default_model => 'DBIC',
165 localize_class => 'HTML::FormFu::I18N',
166 auto_error_message => 'form_%s_%t',
167 error_tag => 'span',
168 };
169  
170 sub BUILD {
171 419 ▶ my ( $self, $args ) = @_;
Subroutine BUILD: called CC=1 SCAR=0.0
172  
173 419 $self->populate($build_defaults);
174  
175 419 return;
176 }
177  
178 sub auto_fieldset {
179 1003 ▶ my ( $self, $element_ref ) = @_;
Subroutine auto_fieldset: called CC=3 SCAR=11.0
Pod documented
180  
181 # if there's no arg, just return whether there's an auto_fieldset already
182 1003 ▶ return $self->_auto_fieldset if !$element_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $element_ref 916 87 1003
183  
184 # if the argument isn't a reference, assume it's just a "1" meaning true,
185 # and use an empty hashref
186 87 ▶ if ( !ref $element_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $element_ref) 46 41 87
187 46 $element_ref = {};
188 }
189  
190 87 $element_ref->{type} = 'Fieldset';
191  
192 87 $self->element($element_ref);
193  
194 87 $self->_auto_fieldset(1);
195  
196 87 return $self;
197 }
198  
199 sub default_values {
200 7 ▶ my ( $self, $default_ref ) = @_;
Subroutine default_values: called CC=4 SCAR=13.9
Pod documented
201  
202 7 for my $field ( @{ $self->get_fields } ) {
203 18 my $name = $field->nested_name;
204 18 ▶ next if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 18 18
205 18 ▶ next if !exists $default_ref->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $default_ref->{$name} 8 10 18
206  
207 10 $field->default( $default_ref->{$name} );
208 }
209  
210 7 return $self;
211 }
212  
213 sub model {
214 21 ▶ my ( $self, $model_name ) = @_;
Subroutine model: called CC=5 SCAR=16.2
Pod documented
215  
216 21 ▶ $model_name ||= $self->default_model;
Condition66%2/3
$model_name ||= $self->default_model
l!l&&r!l&&!r
3180
MC/DC0%0/2
$model_name ||= $self->default_model
$model_name $self->default_model
Truth table66%2/3
A ||= B
A= $model_nameB= $self->default_model
ABresult
1X1
011
000
217  
218 # search models already loaded
219 21 for my $model ( @{ $self->_models } ) {
220 14 ▶ return $model
Branch: 1 branch
BranchTrueFalseTotal
if $model->type =~ /\Q$model_name\E$/ 14 0 14
221 if $model->type =~ /\Q$model_name\E$/;
222 }
223  
224 # class not found, try require-ing it
225 7 ▶ my $class
Branch: 1 branch
BranchTrueFalseTotal
$model_name =~ s/^\+// ? : 1 6 7
226 = $model_name =~ s/^\+//
227 ? $model_name
228 : "HTML::FormFu::Model::$model_name";
229  
230 7 require_class($class);
231  
232 7 my $model = $class->new(
233 { type => $model_name,
234 parent => $self,
235 } );
236  
237 7 push @{ $self->_models }, $model;
238  
239 7 return $model;
240 }
241  
242 sub process {
243 455 ▶ my ( $self, $query ) = @_;
Subroutine process: called CC=24 SCAR=31.9
Pod documented
244  
245 455 $self->input( {} );
246 455 $self->_processed_params( {} );
247 455 $self->_valid_names( [] );
248  
249 455 $self->clear_errors;
250  
251 455 ▶ $query ||= $self->query;
Condition100%3/3
$query ||= $self->query
l!l&&r!l&&!r
408146
MC/DC100%2/2
$query ||= $self->query
$query $self->query
Truth table100%3/3
A ||= B
A= $queryB= $self->query
ABresult
1X1
011
000
252  
253 455 ▶ if ( defined $query && !blessed($query) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $query and not builtin::blessed($query)) 400 55 455
Condition100%3/3
defined $query and not builtin::blessed($query)
!ll&&!rl&&r
469400
MC/DC100%2/2
defined $query and not builtin::blessed($query)
defined $query not builtin::blessed($query)
Truth table100%3/3
A and not(B)
A= defined $queryB= not builtin::blessed($query)
ABresult
0X0
100
111
254 400 $query = HTML::FormFu::FakeQuery->new( $self, $query );
255 }
256  
257 # save it for further calls to process()
258 455 ▶ if ($query) {
Branch: 1 branch
BranchTrueFalseTotal
if ($query) 409 46 455
259 409 ▶ DEBUG && debug( QUERY => $query );
Branch: 1 branch
BranchTrueFalseTotal
DEBUG() and debug("QUERY", $query) 0 409 409
260  
261 409 $self->query($query);
262 }
263  
264 # run all elements pre_process() methods
265 455 for my $elem ( @{ $self->get_elements } ) {
266 922 $elem->pre_process;
267 }
268  
269 # run all plugins pre_process() methods
270 455 for my $plugin ( @{ $self->get_plugins } ) {
271 0 $plugin->pre_process;
272 }
273  
274 # run all elements process() methods
275 455 for my $elem ( @{ $self->get_elements } ) {
276 922 $elem->process;
277 }
278  
279 # run all plugins process() methods
280 455 for my $plugin ( @{ $self->get_plugins } ) {
281 0 $plugin->process;
282 }
283  
284 455 my $submitted;
285  
286 455 ▶ if ( defined $query ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $query) 409 46 455
287 409 eval { my @params = $query->param };
288 409 ▶ croak "Invalid query object: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 409 409
289  
290 409 $submitted = $self->_submitted($query);
291 }
292  
293 455 ▶ DEBUG_PROCESS && debug( SUBMITTED => $submitted );
Branch: 1 branch
BranchTrueFalseTotal
&DEBUG_PROCESS() and debug("SUBMITTED", $submitted) 0 455 455
294  
295 455 $self->submitted($submitted);
296  
297 455 ▶ if ($submitted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($submitted) 405 50 455
298 405 my %input;
299 405 my @params = $query->param;
300  
301 405 for my $field ( @{ $self->get_fields } ) {
302 1207 my $name = $field->nested_name;
303  
304 1207 ▶ next if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 4 1203 1207
305 1203 ▶ next if none { $name eq $_ } @params;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { $name eq $_; } , @params) 197 1006 1203
306  
307 ## CGI wants you to use $query->multi_param($foo).
308 ## doing so breaks CGI::Simple. So shoosh it up for now.
309 1006 local $CGI::LIST_CONTEXT_WARN = 0;
310  
311 1006 ▶ if ( $field->nested ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->nested) { } 255 751 1006
312  
313 # call in list context so we know if there's more than 1 value
314 255 my @values = $query->param($name);
315  
316 255 ▶ my $value
Branch: 1 branch
BranchTrueFalseTotal
@values > 1 ? : 13 242 255
317 = @values > 1
318 ? \@values
319 : $values[0];
320  
321 255 $self->set_nested_hash_value( \%input, $name, $value );
322 }
323 else {
324 751 my @values = $query->param($name);
325  
326 751 ▶ $input{$name}
Branch: 1 branch
BranchTrueFalseTotal
@values > 1 ? : 64 687 751
327 = @values > 1
328 ? \@values
329 : $values[0];
330 }
331 }
332  
333 405 ▶ DEBUG && debug( INPUT => \%input );
Branch: 1 branch
BranchTrueFalseTotal
DEBUG() and debug("INPUT", \%input) 0 405 405
334  
335 # run all field process_input methods
336 405 for my $field ( @{ $self->get_fields } ) {
337 1207 $field->process_input( \%input );
338 }
339  
340 405 $self->input( \%input );
341  
342 405 $self->_process_input;
343 }
344  
345 # run all plugins post_process methods
346 455 for my $elem ( @{ $self->get_elements } ) {
347 922 $elem->post_process;
348 }
349  
350 455 for my $plugin ( @{ $self->get_plugins } ) {
351 0 $plugin->post_process;
352 }
353  
354 455 return;
355 }
356  
357 sub _submitted {
358 409 ▶ my ( $self, $query ) = @_;
Subroutine _submitted: called CC=6 SCAR=17.9
359  
360 409 my $indicator = $self->indicator;
361 409 my $code;
362  
363 409 ▶ if ( defined($indicator) && ref $indicator ne 'CODE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $indicator and ref $indicator ne 'CODE') { } 7 402 409
elsif (not defined $indicator) { } 389 13 402
Condition100%3/3
defined $indicator and ref $indicator ne "CODE"
!ll&&!rl&&r
389137
MC/DC100%2/2
defined $indicator and ref $indicator ne "CODE"
defined $indicator ref $indicator ne "CODE"
Truth table100%3/3
A and B
A= defined $indicatorB= ref $indicator ne "CODE"
ABresult
0X0
100
111
364 7 ▶ DEBUG_PROCESS && debug( INDICATOR => $indicator );
Branch: 1 branch
BranchTrueFalseTotal
&DEBUG_PROCESS() and debug("INDICATOR", $indicator) 0 7 7
365  
366 7 ▶ $code = sub { return defined $query->param($indicator) };
Subroutine __ANON__: called CC=1 SCAR=0.0
367 }
368 elsif ( !defined $indicator ) {
369 my @names = uniq
370 1141 grep {defined}
371 389 map { $_->nested_name } @{ $self->get_fields };
372  
373 389 ▶ DEBUG_PROCESS && debug( 'no indicator, checking fields...' => \@names );
Branch: 1 branch
BranchTrueFalseTotal
&DEBUG_PROCESS() and debug("no indicator, checking fields...", \@names) 0 389 389
374  
375 $code = sub {
376 389 ▶ grep { defined $query->param($_) } @names;
Subroutine __ANON__: called CC=1 SCAR=0.0
377 389 };
378 }
379 else {
380 13 $code = $indicator;
381 }
382  
383 409 return $code->( $self, $query );
384 }
385  
386 sub _process_input {
387 405 ▶ my ($self) = @_;
Subroutine _process_input: called CC=4 SCAR=13.9
388  
389 405 $self->_build_params;
390  
391 405 $self->_process_file_uploads;
392  
393 405 $self->_filter_input;
394 405 $self->_constrain_input;
395 405 ▶ $self->_inflate_input if !@{ $self->get_errors };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->get_errors;} 279 126 405
396 405 ▶ $self->_validate_input if !@{ $self->get_errors };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->get_errors;} 276 129 405
397 405 ▶ $self->_transform_input if !@{ $self->get_errors };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->get_errors;} 275 130 405
398  
399 405 $self->_build_valid_names;
400  
401 405 return;
402 }
403  
404 sub _build_params {
405 405 ▶ my ($self) = @_;
Subroutine _build_params: called CC=10 SCAR=23.0
406  
407 405 my $input = $self->input;
408 405 my %params;
409  
410 405 for my $field ( @{ $self->get_fields } ) {
411 1207 my $name = $field->nested_name;
412  
413 1207 ▶ next if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 4 1203 1207
414 1203 ▶ next if exists $params{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{$name} 19 1184 1203
415  
416 next
417 1184 ▶ if !$self->nested_hash_key_exists( $self->input, $name )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->nested_hash_key_exists($self->input, $name) or $field->default_empty_value 131 1053 1184
Condition100%3/3
$self->nested_hash_key_exists($self->input, $name) or $field->default_empty_value
l!l&&r!l&&!r
10476131
MC/DC100%2/2
$self->nested_hash_key_exists($self->input, $name) or $field->default_empty_value
$self->nested_hash_key_exists($self->input, $name) $field->default_empty_value
Truth table100%3/3
A or B
A= $self->nested_hash_key_exists($self->input, $name)B= $field->default_empty_value
ABresult
1X1
011
000
418 && !$field->default_empty_value;
419  
420 1053 my $input = $self->get_nested_hash_value( $self->input, $name );
421  
422 1053 ▶ if ( ref $input eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $input eq 'ARRAY') { } 62 991 1053
elsif (not defined $input and $field->default_empty_value) { } 6 1943 1949
423  
424 # can't clone upload filehandles
425 # so create new arrayref of values
426 62 $input = [@$input];
427 }
428 ▶ elsif ( !defined $input && $field->default_empty_value ) {
Condition100%3/3
not defined $input and $field->default_empty_value
!ll&&!rl&&r
958276
MC/DC100%2/2
not defined $input and $field->default_empty_value
not defined $input $field->default_empty_value
Truth table100%3/3
not(A) and B
A= not defined $inputB= $field->default_empty_value
ABresult
0X0
100
111
429 6 $input = '';
430 }
431  
432 1053 $self->set_nested_hash_value( \%params, $name, $input, $name );
433 }
434  
435 405 $self->_processed_params( \%params );
436  
437 405 ▶ DEBUG_PROCESS && debug( 'PROCESSED PARAMS' => \%params );
Branch: 1 branch
BranchTrueFalseTotal
&DEBUG_PROCESS() and debug("PROCESSED PARAMS", \%params) 0 405 405
438  
439 405 return;
440 }
441  
442 sub _process_file_uploads {
443 405 ▶ my ($self) = @_;
Subroutine _process_file_uploads: called CC=5 SCAR=16.1
444  
445 my @names = uniq
446 25 grep {defined}
447 25 map { $_->nested_name }
448 405 grep { $_->isa('HTML::FormFu::Element::File') } @{ $self->get_fields };
449  
450 405 ▶ if (@names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names) 13 392 405
451 13 my $query_class = $self->query_type;
452 13 ▶ if ( $query_class !~ /^\+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($query_class =~ /^\+/) 13 0 13
453 13 $query_class = "HTML::FormFu::QueryType::$query_class";
454 }
455 13 require_class($query_class);
456  
457 13 my $params = $self->_processed_params;
458 13 my $input = $self->input;
459  
460 13 for my $name (@names) {
461 24 ▶ next if !$self->nested_hash_key_exists( $input, $name );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->nested_hash_key_exists($input, $name) 3 21 24
462  
463 21 my $values = $query_class->parse_uploads( $self, $name );
464  
465 21 $self->set_nested_hash_value( $params, $name, $values );
466 }
467 }
468  
469 405 return;
470 }
471  
472 sub _filter_input {
473 405 ▶ my ($self) = @_;
Subroutine _filter_input: called CC=4 SCAR=13.9
474  
475 405 my $params = $self->_processed_params;
476  
477 405 for my $filter ( @{ $self->get_filters } ) {
478 62 my $name = $filter->nested_name;
479  
480 62 ▶ next if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 62 62
481 62 ▶ next if !$self->nested_hash_key_exists( $params, $name );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->nested_hash_key_exists($params, $name) 3 59 62
482  
483 59 $filter->process( $self, $params );
484 }
485  
486 405 return;
487 }
488  
489 sub _constrain_input {
490 405 ▶ my ($self) = @_;
Subroutine _constrain_input: called CC=11 SCAR=25.9
491  
492 405 my $params = $self->_processed_params;
493  
494 405 for my $constraint ( @{ $self->get_constraints } ) {
495  
496 534 ▶ DEBUG_CONSTRAINTS && debug(
Branch: 1 branch
BranchTrueFalseTotal
DEBUG_CONSTRAINTS() and debug("FIELD NAME", $constraint->field->nested_name, "CONSTRAINT TYPE", $constraint->type) 0 534 534
497 'FIELD NAME' => $constraint->field->nested_name,
498 'CONSTRAINT TYPE' => $constraint->type,
499 );
500  
501 534 $constraint->pre_process;
502  
503 534 my @errors = eval { $constraint->process($params) };
504  
505 534 ▶ DEBUG_CONSTRAINTS && debug( ERRORS => \@errors );
Branch: 1 branch
BranchTrueFalseTotal
DEBUG_CONSTRAINTS() and debug("ERRORS", \@errors) 0 534 534
506 534 ▶ DEBUG_CONSTRAINTS && debug( '$@' => $@ );
Branch: 1 branch
BranchTrueFalseTotal
DEBUG_CONSTRAINTS() and debug("\$\@", $@) 0 534 534
507  
508 534 ▶ if ( blessed $@ && $@->isa('HTML::FormFu::Exception::Constraint') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($@) and $@->isa('HTML::FormFu::Exception::Constraint')) { } 0 534 534
elsif ($@) { } 0 534 534
Condition33%1/3
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Constraint")
!ll&&!rl&&r
53400
MC/DC0%0/2
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Constraint")
builtin::blessed($@) $@->isa("HTML::FormFu::Exception::Constraint")
Truth table33%1/3
A and B
A= builtin::blessed($@)B= $@->isa("HTML::FormFu::Exception::Constraint")
ABresult
0X0
100
111
509 0 push @errors, $@;
510 }
511 elsif ($@) {
512 0 push @errors, HTML::FormFu::Exception::Constraint->new;
513 }
514  
515 534 for my $error (@errors) {
516 194 ▶ if ( !$error->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($error->parent) 126 68 194
517 126 $error->parent( $constraint->parent );
518 }
519 194 ▶ if ( !$error->constraint ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($error->constraint) 194 0 194
520 194 $error->constraint($constraint);
521 }
522  
523 194 $error->parent->add_error($error);
524 }
525 }
526  
527 405 return;
528 }
529  
530 sub _inflate_input {
531 279 ▶ my ($self) = @_;
Subroutine _inflate_input: called CC=11 SCAR=26.0
532  
533 279 my $params = $self->_processed_params;
534  
535 279 for my $inflator ( @{ $self->get_inflators } ) {
536 27 my $name = $inflator->nested_name;
537  
538 27 ▶ next if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 27 27
539 27 ▶ next if !$self->nested_hash_key_exists( $params, $name );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->nested_hash_key_exists($params, $name) 1 26 27
540 26 ▶ next if any {defined} @{ $inflator->parent->get_errors };
Subroutine __ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { defined $_; } , @{$inflator->parent->get_errors;}) 0 26 26
541  
542 26 my $value = $self->get_nested_hash_value( $params, $name );
543  
544 26 my @errors;
545  
546 26 ( $value, @errors ) = eval { $inflator->process($value) };
547  
548 26 ▶ if ( blessed $@ && $@->isa('HTML::FormFu::Exception::Inflator') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($@) and $@->isa('HTML::FormFu::Exception::Inflator')) { } 0 26 26
elsif ($@) { } 0 26 26
Condition33%1/3
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Inflator")
!ll&&!rl&&r
2600
MC/DC0%0/2
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Inflator")
builtin::blessed($@) $@->isa("HTML::FormFu::Exception::Inflator")
Truth table33%1/3
A and B
A= builtin::blessed($@)B= $@->isa("HTML::FormFu::Exception::Inflator")
ABresult
0X0
100
111
549 0 push @errors, $@;
550 }
551 elsif ($@) {
552 0 push @errors, HTML::FormFu::Exception::Inflator->new;
553 }
554  
555 26 for my $error (@errors) {
556 3 ▶ $error->parent( $inflator->parent ) if !$error->parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $error->parent 3 0 3
557 3 ▶ $error->inflator($inflator) if !$error->inflator;
Branch: 1 branch
BranchTrueFalseTotal
unless $error->inflator 3 0 3
558  
559 3 $error->parent->add_error($error);
560 }
561  
562 26 $self->set_nested_hash_value( $params, $name, $value );
563 }
564  
565 279 return;
566 }
567  
568 sub _validate_input {
569 276 ▶ my ($self) = @_;
Subroutine _validate_input: called CC=11 SCAR=27.2
570  
571 276 my $params = $self->_processed_params;
572  
573 276 for my $validator ( @{ $self->get_validators } ) {
574 8 my $name = $validator->nested_name;
575  
576 8 ▶ next if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 8 8
577 8 ▶ next if !$self->nested_hash_key_exists( $params, $name );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->nested_hash_key_exists($params, $name) 0 8 8
578 8 ▶ next if any {defined} @{ $validator->parent->get_errors };
Subroutine __ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { defined $_; } , @{$validator->parent->get_errors;}) 0 8 8
579  
580 8 my @errors = eval { $validator->process($params) };
581  
582 8 ▶ if ( blessed $@ && $@->isa('HTML::FormFu::Exception::Validator') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($@) and $@->isa('HTML::FormFu::Exception::Validator')) { } 0 8 8
elsif ($@) { } 0 8 8
Condition33%1/3
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Validator")
!ll&&!rl&&r
800
MC/DC0%0/2
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Validator")
builtin::blessed($@) $@->isa("HTML::FormFu::Exception::Validator")
Truth table33%1/3
A and B
A= builtin::blessed($@)B= $@->isa("HTML::FormFu::Exception::Validator")
ABresult
0X0
100
111
583 0 push @errors, $@;
584 }
585 elsif ($@) {
586 0 push @errors, HTML::FormFu::Exception::Validator->new;
587 }
588  
589 8 for my $error (@errors) {
590 1 ▶ $error->parent( $validator->parent ) if !$error->parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $error->parent 1 0 1
591 1 ▶ $error->validator($validator) if !$error->validator;
Branch: 1 branch
BranchTrueFalseTotal
unless $error->validator 1 0 1
592  
593 1 $error->parent->add_error($error);
594 }
595 }
596  
597 276 return;
598 }
599  
600 sub _transform_input {
601 275 ▶ my ($self) = @_;
Subroutine _transform_input: called CC=11 SCAR=30.8
602  
603 275 my $params = $self->_processed_params;
604  
605 275 for my $transformer ( @{ $self->get_transformers } ) {
606 5 my $name = $transformer->nested_name;
607  
608 5 ▶ next if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 5 5
609 5 ▶ next if !$self->nested_hash_key_exists( $params, $name );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->nested_hash_key_exists($params, $name) 0 5 5
610 5 ▶ next if any {defined} @{ $transformer->parent->get_errors };
Subroutine __ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { defined $_; } , @{$transformer->parent->get_errors;}) 0 5 5
611  
612 5 my $value = $self->get_nested_hash_value( $params, $name );
613  
614 5 my (@errors) = eval { $transformer->process( $value, $params ) };
615  
616 5 ▶ if ( blessed $@ && $@->isa('HTML::FormFu::Exception::Transformer') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($@) and $@->isa('HTML::FormFu::Exception::Transformer')) { } 0 5 5
elsif ($@) { } 0 5 5
Condition33%1/3
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Transformer")
!ll&&!rl&&r
500
MC/DC0%0/2
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Transformer")
builtin::blessed($@) $@->isa("HTML::FormFu::Exception::Transformer")
Truth table33%1/3
A and B
A= builtin::blessed($@)B= $@->isa("HTML::FormFu::Exception::Transformer")
ABresult
0X0
100
111
617 0 push @errors, $@;
618 }
619 elsif ($@) {
620 0 push @errors, HTML::FormFu::Exception::Transformer->new;
621 }
622  
623 5 for my $error (@errors) {
624 0 ▶ $error->parent( $transformer->parent ) if !$error->parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $error->parent 0 0 0
625 0 ▶ $error->transformer($transformer) if !$error->transformer;
Branch: 1 branch
BranchTrueFalseTotal
unless $error->transformer 0 0 0
626  
627 0 $error->parent->add_error($error);
628 }
629 }
630  
631 275 return;
632 }
633  
634 sub _build_valid_names {
635 405 ▶ my ($self) = @_;
Subroutine _build_valid_names: called CC=11 SCAR=24.0
636  
637 405 my $params = $self->_processed_params;
638 405 my $skip_private = $self->params_ignore_underscore;
639 405 my @errors = $self->has_errors;
640 405 my @names;
641 my %non_param;
642  
643 405 for my $field ( @{ $self->get_fields } ) {
644 1207 my $name = $field->nested_name;
645  
646 1207 ▶ next if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 4 1203 1207
647 1203 ▶ next if $skip_private && $field->name =~ /^_/;
Branch: 1 branch
BranchTrueFalseTotal
if $skip_private and $field->name =~ /^_/ 1 1202 1203
Condition100%3/3
$skip_private and $field->name =~ /^_/
!ll&&!rl&&r
120021
MC/DC100%2/2
$skip_private and $field->name =~ /^_/
$skip_private $field->name =~ /^_/
Truth table100%3/3
A and B
A= $skip_privateB= $field->name =~ /^_/
ABresult
0X0
100
111
648  
649 1202 ▶ if ( $field->non_param ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($field->non_param) { } 6 1196 1202
elsif ($self->nested_hash_key_exists($params, $name)) { } 1045 151 1196
650 6 $non_param{$name} = 1;
651 }
652 elsif ( $self->nested_hash_key_exists( $params, $name ) ) {
653 1045 push @names, $name;
654 }
655 }
656  
657 push @names, uniq
658 906 grep { ref $params->{$_} ne 'HASH' }
659 907 ▶ grep { !( $skip_private && /^_/ ) }
Condition100%3/3
$skip_private && /^_/
!ll&&!rl&&r
90421
MC/DC100%2/2
$skip_private && /^_/
$skip_private /^_/
Truth table100%3/3
A && B
A= $skip_privateB= /^_/
ABresult
0X0
100
111
660 405 grep { !exists $non_param{$_} }
661 keys %$params;
662  
663 405 my %valid;
664  
665 CHECK:
666 405 for my $name (@names) {
667 1878 for my $error (@errors) {
668 782 ▶ next CHECK if $name eq $error;
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $error 258 524 782
669 }
670 1620 $valid{$name}++;
671 }
672 405 my @valid = keys %valid;
673  
674 405 $self->_valid_names( \@valid );
675  
676 405 return;
677 }
678  
679 sub _hash_keys {
680 4 ▶ my ( $hash, $subscript ) = @_;
Subroutine _hash_keys: called CC=6 SCAR=17.9
681 4 my @names;
682  
683 4 for my $key ( keys %$hash ) {
684 10 ▶ if ( ref $hash->{$key} eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $hash->{$key} eq 'HASH') { } 2 8 10
elsif (ref $hash->{$key} eq 'ARRAY') { } 2 6 8
685 push @names,
686 4 ▶ map { $subscript ? "${key}[${_}]" : "$key.$_" }
Branch: 1 branch
BranchTrueFalseTotal
$subscript ? : 2 2 4
687 2 _hash_keys( $hash->{$key}, $subscript );
688 }
689 elsif ( ref $hash->{$key} eq 'ARRAY' ) {
690 push @names,
691 4 ▶ map { $subscript ? "${key}[${_}]" : "$key.$_" }
Branch: 1 branch
BranchTrueFalseTotal
$subscript ? : 2 2 4
692 2 _array_indices( $hash->{$key}, $subscript );
693 }
694 else {
695 6 push @names, $key;
696 }
697 }
698  
699 4 return @names;
700 }
701  
702 sub _array_indices {
703 2 ▶ my ( $array, $subscript ) = @_;
Subroutine _array_indices: called CC=6 SCAR=24.2
704  
705 2 my @names;
706  
707 2 for my $i ( 0 .. $#{$array} ) {
708 4 ▶ if ( ref $array->[$i] eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $array->[$i] eq 'HASH') { } 0 4 4
elsif (ref $array->[$i] eq 'ARRAY') { } 0 4 4
709 push @names,
710 0 ▶ map { $subscript ? "${i}[${_}]" : "$i.$_" }
Branch: 1 branch
BranchTrueFalseTotal
$subscript ? : 0 0 0
711 _hash_keys( $array->[$i], $subscript );
712 }
713 elsif ( ref $array->[$i] eq 'ARRAY' ) {
714 push @names,
715 0 ▶ map { $subscript ? "${i}[${_}]" : "$i.$_" }
Branch: 1 branch
BranchTrueFalseTotal
$subscript ? : 0 0 0
716 _array_indices( $array->[$i], $subscript );
717 }
718 else {
719 4 push @names, $i;
720 }
721 }
722  
723 2 return @names;
724 }
725  
726 sub submitted_and_valid {
727 112 ▶ my ($self) = @_;
Subroutine submitted_and_valid: called CC=2 SCAR=6.9
Pod documented
728  
729 112 ▶ return $self->submitted && !$self->has_errors;
Condition100%3/3
$self->submitted && !$self->has_errors
!ll&&!rl&&r
12982
MC/DC100%2/2
$self->submitted && !$self->has_errors
$self->submitted !$self->has_errors
Truth table100%3/3
A && not(B)
A= $self->submittedB= !$self->has_errors
ABresult
0X0
100
111
730 }
731  
732 sub params {
733 77 ▶ my ($self) = @_;
Subroutine params: called CC=4 SCAR=13.9
Pod documented
734  
735 77 ▶ return {} if !$self->submitted;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->submitted 0 77 77
736  
737 77 my @names = $self->valid;
738 77 my %params;
739  
740 77 for my $name (@names) {
741 188 my @values = $self->param($name);
742  
743 188 ▶ if ( @values > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values > 1) { } 13 175 188
744 13 $self->set_nested_hash_value( \%params, $name, \@values );
745 }
746 else {
747 175 $self->set_nested_hash_value( \%params, $name, $values[0] );
748 }
749 }
750  
751 77 return \%params;
752 }
753  
754 sub param {
755 336 ▶ my ( $self, $name ) = @_;
Subroutine param: called CC=8 SCAR=20.8
Pod documented
756  
757 336 ▶ croak 'param method is readonly' if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 336 336
758  
759 336 ▶ return if !$self->submitted;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->submitted 0 336 336
760  
761 336 ▶ if ( @_ == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) 331 5 336
762 331 ▶ return if !$self->valid($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->valid($name) 19 312 331
763  
764 312 my $value
765 = $self->get_nested_hash_value( $self->_processed_params, $name );
766  
767 312 ▶ return if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 8 304 312
768  
769 304 ▶ if ( ref $value eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 20 284 304
770 20 ▶ return wantarray ? @$value : $value->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 18 2 20
771 }
772 else {
773 284 return $value;
774 }
775 }
776  
777 # return a list of valid names, if no $name arg
778 5 return $self->valid;
779 }
780  
781 sub param_value {
782 38 ▶ my ( $self, $name ) = @_;
Subroutine param_value: called CC=4 SCAR=13.9
Pod documented
783  
784 38 ▶ croak 'name parameter required' if @_ != 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 38 38
785  
786 return undef ## no critic (ProhibitExplicitReturnUndef);
787 38 ▶ if !$self->valid($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->valid($name) 1 37 38
788  
789 # this is guaranteed to always return a single value
790  
791 37 my $value = $self->get_nested_hash_value( $self->_processed_params, $name );
792  
793 37 ▶ return ref $value eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 3 34 37
794 ? $value->[0]
795 : $value;
796 }
797  
798 sub param_array {
799 7 ▶ my ( $self, $name ) = @_;
Subroutine param_array: called CC=5 SCAR=16.2
Pod documented
800  
801 7 ▶ croak 'name parameter required' if @_ != 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 7 7
802  
803 # guaranteed to always return an arrayref
804  
805 7 ▶ return [] if !$self->valid($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->valid($name) 1 6 7
806  
807 6 my $value = $self->get_nested_hash_value( $self->_processed_params, $name );
808  
809 6 ▶ return [] if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 6 6
810  
811 6 ▶ return ref $value eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 5 1 6
812 ? $value
813 : [$value];
814 }
815  
816 sub param_list {
817 3 ▶ my ( $self, $name ) = @_;
Subroutine param_list: called CC=5 SCAR=16.2
Pod documented
818  
819 3 ▶ croak 'name parameter required' if @_ != 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 3 3
820  
821 # guaranteed to always return an arrayref
822  
823 3 ▶ return if !$self->valid($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->valid($name) 1 2 3
824  
825 2 my $value = $self->get_nested_hash_value( $self->_processed_params, $name );
826  
827 2 ▶ return if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 2 2
828  
829 2 ▶ return ref $value eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 1 1 2
830 ? @$value
831 : $value;
832 }
833  
834 sub valid {
835 991 ▶ my $self = shift;
Subroutine valid: called CC=8 SCAR=21.0
Pod documented
836  
837 991 ▶ return if !$self->submitted;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->submitted 0 991 991
838  
839 991 my @valid = @{ $self->_valid_names };
840  
841 991 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 815 176 991
842 815 my $name = shift;
843  
844 815 ▶ return 1 if any { $name eq $_ } @valid;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $name eq $_; } , @valid) 709 106 815
845  
846 # not found - see if it's the name of a nested block
847 106 my $parent;
848  
849 106 ▶ if ( defined $self->nested_name && $self->nested_name eq $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->nested_name and $self->nested_name eq $name) { } 0 106 106
Condition33%1/3
defined $self->nested_name and $self->nested_name eq $name
!ll&&!rl&&r
10600
MC/DC0%0/2
defined $self->nested_name and $self->nested_name eq $name
defined $self->nested_name $self->nested_name eq $name
Truth table33%1/3
A and B
A= defined $self->nested_nameB= $self->nested_name eq $name
ABresult
0X0
100
111
850 0 $parent = $self;
851 }
852 else {
853 ($parent)
854 102 ▶ = first { $_->isa('HTML::FormFu::Element::Block') }
Subroutine __ANON__: called CC=1 SCAR=0.0
855 106 @{ $self->get_all_elements( { nested_name => $name, } ) };
856 }
857  
858 106 ▶ if ( defined $parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent) 5 101 106
859 3 ▶ my $fail = any {defined}
Subroutine __ANON__: called CC=1 SCAR=0.0
860 5 map { @{ $_->get_errors } } @{ $parent->get_fields };
861  
862 5 ▶ return 1 if !$fail;
Branch: 1 branch
BranchTrueFalseTotal
unless $fail 2 3 5
863 }
864  
865 104 return;
866 }
867  
868 # return a list of valid names, if no $name arg
869 176 return @valid;
870 }
871  
872 sub has_errors {
873 892 ▶ my $self = shift;
Subroutine has_errors: called CC=4 SCAR=13.9
Pod documented
874  
875 892 ▶ return if !$self->submitted;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->submitted 144 748 892
876  
877 367 my @names = map { $_->nested_name }
878 2451 grep { @{ $_->get_errors } }
879 748 grep { defined $_->nested_name } @{ $self->get_fields };
880  
881 748 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 143 605 748
882 143 my $name = shift;
883 143 ▶ return 1 if any {/\Q$name/} @names;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { /\Q$name\E/; } , @names) 54 89 143
884 89 return;
885 }
886  
887 # return list of names with errors, if no $name arg
888 605 return @names;
889 }
890  
891 sub add_valid {
892 4 ▶ my ( $self, $key, $value ) = @_;
Subroutine add_valid: called CC=3 SCAR=11.1
Pod documented
893  
894 4 ▶ croak 'add_valid requires arguments ($key, $value)' if @_ != 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 3 0 4 4
895  
896 4 $self->set_nested_hash_value( $self->input, $key, $value );
897  
898 4 $self->set_nested_hash_value( $self->_processed_params, $key, $value );
899  
900 4 ▶ if ( none { $_ eq $key } @{ $self->_valid_names } ) {
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
if (&none(sub { $_ eq $key; } , @{$self->_valid_names;})) 4 0 4
901 4 push @{ $self->_valid_names }, $key;
902 }
903  
904 4 return $value;
905 }
906  
907 sub _single_plugin {
908 1 ▶ my ( $self, $arg_ref ) = @_;
Subroutine _single_plugin: called CC=7 SCAR=21.6
909  
910 1 ▶ if ( !ref $arg_ref ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg_ref) { } 0 1 1
elsif (ref $arg_ref eq 'HASH') { } 1 0 1
911 0 $arg_ref = { type => $arg_ref };
912 }
913 elsif ( ref $arg_ref eq 'HASH' ) {
914  
915 # shallow clone
916 1 $arg_ref = {%$arg_ref};
917 }
918 else {
919 0 croak 'invalid args';
920 }
921  
922 1 my $type = delete $arg_ref->{type};
923 1 my @return;
924  
925 1 ▶ my @names = map { ref $_ ? @$_ : $_ }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 1 1
926 1 grep {defined} ( delete $arg_ref->{name}, delete $arg_ref->{names} );
927  
928 1 ▶ if (@names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names) { } 1 0 1
929  
930 # add plugins to appropriate fields
931 1 for my $x (@names) {
932 1 for my $field ( @{ $self->get_fields( { nested_name => $x } ) } ) {
933 1 my $new = $field->_require_plugin( $type, $arg_ref );
934 1 push @{ $field->_plugins }, $new;
935 1 push @return, $new;
936 }
937 }
938 }
939 else {
940  
941 # add plugin directly to form
942 0 my $new = $self->_require_plugin( $type, $arg_ref );
943  
944 0 push @{ $self->_plugins }, $new;
945 0 push @return, $new;
946 }
947  
948 1 return @return;
949 }
950  
951 around render => sub {
952 168 ▶ my $orig = shift;
Subroutine __ANON__: called CC=3 SCAR=11.3
953 168 my $self = shift;
954  
955 168 my $plugins = $self->get_plugins;
956  
957 168 for my $plugin (@$plugins) {
958 0 $plugin->render;
959 }
960  
961 168 my $output = $self->$orig;
962  
963 168 for my $plugin (@$plugins) {
964 0 $plugin->post_render( \$output );
965 }
966  
967 168 return $output;
968 403 };
969  
970 sub render_data {
971 11 ▶ my ( $self, $args ) = @_;
Subroutine render_data: called CC=2 SCAR=7.0
Pod documented
972  
973 my $render = $self->render_data_non_recursive(
974 11 ▶ { elements => [ map { $_->render_data } @{ $self->_elements } ],
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 0 11 11
975 $args ? %$args : (),
976 } );
977  
978 11 return $render;
979 }
980  
981 sub render_data_non_recursive {
982 183 ▶ my ( $self, $args ) = @_;
Subroutine render_data_non_recursive: called CC=5 SCAR=16.1
Pod documented
983  
984 183 ▶ my %render = (
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 11 172 183
985 filename => $self->filename,
986 javascript => $self->javascript,
987 javascript_src => $self->javascript_src,
988 attributes => xml_escape( $self->attributes ),
989 stash => $self->stash,
990 $args ? %$args : (),
991 );
992  
993 183 $render{form} = \%render;
994 183 weaken( $render{form} );
995  
996 183 $render{object} = $self;
997  
998 183 ▶ if ($self->force_error_message
Branch: 1 branch
BranchTrueFalseTotal
if ($self->force_error_message or $self->has_errors and defined $self->form_error_message) 3 180 183
Condition100%6/6
$self->force_error_message or $self->has_errors and defined $self->form_error_message
l!l&&r!l&&!r
14178
$self->has_errors and defined $self->form_error_message
!ll&&!rl&&r
166142
MC/DC66%2/3
$self->force_error_message or $self->has_errors and defined $self->form_error_message
$self->force_error_message $self->has_errors defined $self->form_error_message
Truth table75%3/4
A or B and C
A= $self->force_error_messageB= $self->has_errorsC= defined $self->form_error_message
ABCresult
1XX1
0111
00X0
0100
999 || ( $self->has_errors
1000 && defined $self->form_error_message ) )
1001 {
1002 3 $render{form_error_message} = xml_escape( $self->form_error_message );
1003 3 $render{form_error_message_class} = $self->form_error_message_class;
1004 }
1005  
1006 183 return \%render;
1007 }
1008  
1009 sub string {
1010 166 ▶ my ( $self, $args_ref ) = @_;
Subroutine string: called CC=4 SCAR=13.9
Pod undocumented
1011  
1012 166 ▶ $args_ref ||= {};
Condition50%1/2
$args_ref ||= {}
l!l
0166
MC/DC0%0/1
$args_ref ||= {}
$args_ref
Truth table50%1/2
A
A= $args_ref
Aresult
11
00
1013  
1014 166 my $html = $self->_string_form_start($args_ref);
1015  
1016 # form template
1017  
1018 166 $html .= "\n";
1019  
1020 166 for my $element ( @{ $self->get_elements } ) {
1021  
1022 # call render, so that child elements can use a different renderer
1023 226 my $element_html = $element->render;
1024  
1025 # skip Blank fields
1026 226 ▶ if ( length $element_html ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $element_html) 225 1 226
1027 225 $html .= $element_html . "\n";
1028 }
1029 }
1030  
1031 166 $html .= $self->_string_form_end($args_ref);
1032 166 $html .= "\n";
1033  
1034 166 return $html;
1035 }
1036  
1037 sub _string_form_start {
1038 172 ▶ my ( $self, $args_ref ) = @_;
Subroutine _string_form_start: called CC=7 SCAR=19.5
1039  
1040 # start_form template
1041  
1042 my $render_ref
1043 = exists $args_ref->{render_data}
1044 ? $args_ref->{render_data}
1045 172 ▶ : $self->render_data_non_recursive;
Branch: 1 branch
BranchTrueFalseTotal
exists $args_ref->{'render_data'} ? : 0 172 172
1046  
1047 172 my $html = sprintf "<form%s>", process_attrs( $render_ref->{attributes} );
1048  
1049 172 ▶ if ( defined $render_ref->{form_error_message} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render_ref->{"form_error_message"}) 3 169 172
1050 $html .= sprintf qq{\n<div class="%s">%s</div>},
1051 $render_ref->{form_error_message_class},
1052 $render_ref->{form_error_message},
1053 3 ;
1054 }
1055  
1056 172 ▶ if ( defined $render_ref->{javascript_src} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render_ref->{"javascript_src"}) 2 170 172
1057 2 my $uri = $render_ref->{javascript_src};
1058  
1059 2 ▶ my @uris = ref $uri eq 'ARRAY' ? @$uri : ($uri);
Branch: 1 branch
BranchTrueFalseTotal
ref $uri eq 'ARRAY' ? : 1 1 2
1060  
1061 2 for my $uri (@uris) {
1062 3 $html .= sprintf
1063 qq{\n<script type="text/javascript" src="%s">\n</script>},
1064 $uri,
1065 ;
1066 }
1067 }
1068  
1069 172 ▶ if ( defined $render_ref->{javascript} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render_ref->{"javascript"}) 3 169 172
1070 $html .= sprintf
1071 qq{\n<script type="text/javascript">\n%s\n</script>},
1072 $render_ref->{javascript},
1073 3 ;
1074 }
1075  
1076 172 return $html;
1077 }
1078  
1079 sub _string_form_end {
1080 172 ▶ my ($self) = @_;
Subroutine _string_form_end: called CC=1 SCAR=0.0
1081  
1082 # end_form template
1083  
1084 172 return "</form>";
1085 }
1086  
1087 sub start {
1088 6 ▶ my $self = shift;
Subroutine start: called CC=2 SCAR=7.6
Pod documented
1089  
1090 6 ▶ if ( 'tt' eq $self->render_method ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('tt' eq $self->render_method) { } 0 6 6
1091 0 return $self->tt(
1092 { filename => 'start_form',
1093 render_data => $self->render_data_non_recursive,
1094 } );
1095 }
1096 else {
1097 6 return $self->_string_form_start(@_);
1098 }
1099 }
1100  
1101 sub end {
1102 6 ▶ my $self = shift;
Subroutine end: called CC=2 SCAR=7.6
Pod documented
1103  
1104 6 ▶ if ( 'tt' eq $self->render_method ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('tt' eq $self->render_method) { } 0 6 6
1105 0 return $self->tt(
1106 { filename => 'end_form',
1107 render_data => $self->render_data_non_recursive,
1108 } );
1109 }
1110 else {
1111 6 return $self->_string_form_end(@_);
1112 }
1113 }
1114  
1115 sub hidden_fields {
1116 1 ▶ my ($self) = @_;
Subroutine hidden_fields: called CC=1 SCAR=0.0
Pod documented
1117  
1118 return join $EMPTY_STR,
1119 1 map { $_->render } @{ $self->get_fields( { type => 'Hidden' } ) };
1120 }
1121  
1122 sub output_processor {
1123 3 ▶ my ( $self, $arg ) = @_;
Subroutine output_processor: called CC=3 SCAR=12.3
Pod undocumented
1124 3 my @return;
1125  
1126 3 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 3 3
1127 0 push @return, map { $self->_single_output_processor($_) } @$arg;
1128 }
1129 else {
1130 3 push @return, $self->_single_output_processor($arg);
1131 }
1132  
1133 3 ▶ return @return == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@return == 1 ? : 3 0 3
1134 }
1135  
1136 sub _single_output_processor {
1137 3 ▶ my ( $self, $arg ) = @_;
Subroutine _single_output_processor: called CC=3 SCAR=11.1
1138  
1139 3 ▶ if ( !ref $arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 2 1 3
elsif (ref $arg eq 'HASH') { } 1 0 1
1140 2 $arg = { type => $arg };
1141 }
1142 elsif ( ref $arg eq 'HASH' ) {
1143 1 $arg = Clone::clone($arg);
1144 }
1145 else {
1146 0 croak 'invalid args';
1147 }
1148  
1149 3 my $type = delete $arg->{type};
1150  
1151 3 my $new = $self->_require_output_processor( $type, $arg );
1152  
1153 3 push @{ $self->_output_processors }, $new;
1154  
1155 3 return $new;
1156 }
1157  
1158 sub _require_output_processor {
1159 3 ▶ my ( $self, $type, $opt ) = @_;
Subroutine _require_output_processor: called CC=6 SCAR=19.5
1160  
1161 3 ▶ croak 'required arguments: $self, $type, \%options' if @_ != 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 3 0 3 3
1162  
1163 3 ▶ croak "options argument must be hash-ref"
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($opt) ne "HASH" 0 3 3
1164 if reftype($opt) ne 'HASH';
1165  
1166 3 my $class = $type;
1167 3 ▶ if ( not $class =~ s/^\+// ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ s/^\+//) 3 0 3
1168 3 $class = "HTML::FormFu::OutputProcessor::$class";
1169 }
1170  
1171 3 $type =~ s/^\+//;
1172  
1173 3 require_class($class);
1174  
1175 3 my $object = $class->new(
1176 { type => $type,
1177 parent => $self,
1178 } );
1179  
1180 # handle default_args
1181 3 my $parent = $self->parent;
1182  
1183 3 ▶ if ( $parent && exists $parent->default_args->{output_processor}{$type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent and exists $parent->default_args->{"output_processor"}{$type}) 0 3 3
Condition33%1/3
$parent and exists $parent->default_args->{"output_processor"}{$type}
!ll&&!rl&&r
300
MC/DC0%0/2
$parent and exists $parent->default_args->{"output_processor"}{$type}
$parent exists $parent->default_args->{"output_processor"}{$type}
Truth table33%1/3
A and B
A= $parentB= exists $parent->default_args->{"output_processor"}{$type}
ABresult
0X0
100
111
1184 %$opt
1185 0 = ( %{ $parent->default_args->{output_processer}{$type} }, %$opt );
1186 }
1187  
1188 3 $object->populate($opt);
1189  
1190 3 return $object;
1191 }
1192  
1193 sub get_output_processors {
1194 1119 ▶ my $self = shift;
Subroutine get_output_processors: called CC=2 SCAR=7.5
Pod undocumented
1195 1119 my %args = _parse_args(@_);
1196  
1197 1119 my @x = @{ $self->_output_processors };
1198  
1199 1119 ▶ if ( exists $args{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"type"}) 0 1119 1119
1200 0 @x = grep { $_->type eq $args{type} } @x;
1201 }
1202  
1203 1119 return \@x;
1204 }
1205  
1206 sub get_output_processor {
1207 0 ▶ my $self = shift;
Subroutine get_output_processor: not called CC=2 SCAR=17.9
Pod undocumented
1208  
1209 0 my $x = $self->get_output_processors(@_);
1210  
1211 0 ▶ return @$x ? $x->[0] : ();
Branch: 1 branch
BranchTrueFalseTotal
@$x ? : 0 0 0
1212 }
1213  
1214 403 __PACKAGE__->meta->make_immutable;
1215  
1216 403 1;
1217  
1218 __END__
1219  
1220 =pod
1221  
1222 =encoding UTF-8
1223  
1224 =head1 NAME
1225  
1226 HTML::FormFu - HTML Form Creation, Rendering and Validation Framework
1227  
1228 =head1 VERSION
1229  
1230 version 2.06
1231  
1232 =head1 SYNOPSIS
1233  
1234 Note: These examples make use of L<HTML::FormFu::Model::DBIC>. As of
1235 C<HTML::FormFu> v02.005, the L<HTML::FormFu::Model::DBIC> module is
1236 not bundled with C<HTML::FormFu> and is available in a stand-alone
1237 distribution.
1238  
1239 use HTML::FormFu;
1240  
1241 my $form = HTML::FormFu->new;
1242  
1243 $form->load_config_file('form.yml');
1244  
1245 $form->process( $cgi_query );
1246  
1247 if ( $form->submitted_and_valid ) {
1248 # do something with $form->params
1249 }
1250 else {
1251 # display the form
1252 $template->param( form => $form );
1253 }
1254  
1255 If you're using L<Catalyst>, a more suitable example might be:
1256  
1257 package MyApp::Controller::User;
1258 use Moose;
1259 extends 'Catalyst::Controller::HTML::FormFu';
1260  
1261 sub user : Chained CaptureArgs(1) {
1262 my ( $self, $c, $id ) = @_;
1263  
1264 my $rs = $c->model('Schema')->resultset('User');
1265  
1266 $c->stash->{user} = $rs->find( $id );
1267  
1268 return;
1269 }
1270  
1271 sub edit : Chained('user') Args(0) FormConfig {
1272 my ( $self, $c ) = @_;
1273  
1274 my $form = $c->stash->{form};
1275 my $user = $c->stash->{user};
1276  
1277 if ( $form->submitted_and_valid ) {
1278  
1279 $form->model->update( $user );
1280  
1281 $c->res->redirect( $c->uri_for( "/user/$id" ) );
1282 return;
1283 }
1284  
1285 $form->model->default_values( $user )
1286 if ! $form->submitted;
1287  
1288 }
1289  
1290 Note: Because L</process> is automatically called for you by the Catalyst
1291 controller; if you make any modifications to the form within your action
1292 method, such as adding or changing elements, adding constraints, etc;
1293 you must call L</process> again yourself before using L</submitted_and_valid>,
1294 any of the methods listed under L</"SUBMITTED FORM VALUES AND ERRORS"> or
1295 L</"MODIFYING A SUBMITTED FORM">, or rendering the form.
1296  
1297 Here's an example of a config file to create a basic login form (all examples
1298 here are L<YAML>, but you can use any format supported by L<Config::Any>),
1299 you can also create forms directly in your perl code, rather than using an
1300 external config file.
1301  
1302 ---
1303 action: /login
1304 indicator: submit
1305 auto_fieldset: 1
1306  
1307 elements:
1308 - type: Text
1309 name: user
1310 constraints:
1311 - Required
1312  
1313 - type: Password
1314 name: pass
1315 constraints:
1316 - Required
1317  
1318 - type: Submit
1319 name: submit
1320  
1321 constraints:
1322 - SingleValue
1323  
1324 =head1 DESCRIPTION
1325  
1326 L<HTML::FormFu> is a HTML form framework which aims to be as easy as
1327 possible to use for basic web forms, but with the power and flexibility to
1328 do anything else you might want to do (as long as it involves forms).
1329  
1330 You can configure almost any part of formfu's behaviour and output. By
1331 default formfu renders "XHTML 1.0 Strict" compliant markup, with as little
1332 extra markup as possible, but with sufficient CSS class names to allow for a
1333 wide-range of output styles to be generated by changing only the CSS.
1334  
1335 All methods listed below (except L</new>) can either be called as a normal
1336 method on your C<$form> object, or as an option in your config file. Examples
1337 will mainly be shown in L<YAML> config syntax.
1338  
1339 This documentation follows the convention that method arguments surrounded
1340 by square brackets C<[]> are I<optional>, and all other arguments are
1341 required.
1342  
1343 =head1 BUILDING A FORM
1344  
1345 =head2 new
1346  
1347 Arguments: [\%options]
1348  
1349 Return Value: $form
1350  
1351 Create a new L<HTML::FormFu|HTML::FormFu> object.
1352  
1353 Any method which can be called on the L<HTML::FormFu|HTML::FormFu> object may
1354 instead be passed as an argument to L</new>.
1355  
1356 my $form = HTML::FormFu->new({
1357 action => '/search',
1358 method => 'GET',
1359 auto_fieldset => 1,
1360 });
1361  
1362 =head2 load_config_file
1363  
1364 Arguments: $filename
1365  
1366 Arguments: \@filenames
1367  
1368 Return Value: $form
1369  
1370 Accepts a filename or list of file names, whose filetypes should be of any
1371 format recognized by L<Config::Any>.
1372  
1373 The content of each config file is passed to L</populate>, and so are added
1374 to the form.
1375  
1376 L</load_config_file> may be called in a config file itself, so as to allow
1377 common settings to be kept in a single config file which may be loaded
1378 by any form.
1379  
1380 ---
1381 load_config_file:
1382 - file1
1383 - file2
1384  
1385 YAML multiple documents within a single file. The document start marker is
1386 a line containing 3 dashes. Multiple documents will be applied in order,
1387 just as if multiple filenames had been given.
1388  
1389 In the following example, multiple documents are taken advantage of to
1390 load another config file after the elements are added. (If this were
1391 a single document, the C<load_config_file> would be called before
1392 C<elements>, regardless of its position in the file).
1393  
1394 ---
1395 elements:
1396 - name: one
1397 - name: two
1398  
1399 ---
1400 load_config_file: ext.yml
1401  
1402 Relative paths are resolved from the L</config_file_path> directory if
1403 it is set, otherwise from the current working directory.
1404  
1405 See L</BEST PRACTICES> for advice on organising config files.
1406  
1407 =head2 config_callback
1408  
1409 Arguments: \%options
1410  
1411 If defined, the arguments are used to create a L<Data::Visitor::Callback>
1412 object during L</load_config_file> which may be used to pre-process the
1413 config before it is sent to L</populate>.
1414  
1415 For example, the code below adds a callback to a form that will dynamically
1416 alter any config value ending in ".yml" to end in ".yaml" when you call
1417 L</load_config_file>:
1418  
1419 $form->config_callback({
1420 plain_value => sub {
1421 my( $visitor, $data ) = @_;
1422 s/\.yml/.yaml/;
1423 }
1424 });
1425  
1426 Default Value: not defined
1427  
1428 This method is a special 'inherited accessor', which means it can be set on
1429 the form, a block element or a single element. When the value is read, if
1430 no value is defined it automatically traverses the element's hierarchy of
1431 parents, through any block elements and up to the form, searching for a
1432 defined value.
1433  
1434 =head2 populate
1435  
1436 Arguments: \%options
1437  
1438 Return Value: $form
1439  
1440 Each option key/value passed may be any L<HTML::FormFu|HTML::FormFu>
1441 method-name and arguments.
1442  
1443 Provides a simple way to set multiple values, or add multiple elements to
1444 a form with a single method-call.
1445  
1446 Attempts to call the method-names in a semi-intelligent order (see
1447 the source of populate() in C<HTML::FormFu::ObjectUtil> for details).
1448  
1449 =head2 default_values
1450  
1451 Arguments: \%defaults
1452  
1453 Return Value: $form
1454  
1455 Set multiple field's default values from a single hash-ref.
1456  
1457 The hash-ref's keys correspond to a form field's name, and the value is
1458 passed to the field's L<default method|HTML::FormFu::_Field/default>.
1459  
1460 This should be called after all fields have been added to the form, and
1461 before L</process> is called (otherwise, call L</process> again before
1462 rendering the form).
1463  
1464 =head2 config_file_path
1465  
1466 Arguments: $directory_name
1467  
1468 L</config_file_path> defines where configuration files will be
1469 searched for, if an absolute path is not given to
1470 L</load_config_file>.
1471  
1472 Default Value: not defined
1473  
1474 This method is a special 'inherited accessor', which means it can be set on
1475 the form, a block element or a single element. When the value is read, if
1476 no value is defined it automatically traverses the element's hierarchy of
1477 parents, through any block elements and up to the form, searching for a
1478 defined value.
1479  
1480 Is an L<inheriting accessor|/INHERITING ACCESSORS>.
1481  
1482 =head2 indicator
1483  
1484 Arguments: $field_name
1485  
1486 Arguments: \&coderef
1487  
1488 If L</indicator> is set to a fieldname, L</submitted> will return true if
1489 a value for that fieldname was submitted.
1490  
1491 If L</indicator> is set to a code-ref, it will be called as a subroutine
1492 with the two arguments C<$form> and C<$query>, and its return value will be
1493 used as the return value for L</submitted>.
1494  
1495 If L</indicator> is not set, L</submitted> will return true if a value for
1496 any known fieldname was submitted.
1497  
1498 =head2 auto_fieldset
1499  
1500 Arguments: 1
1501  
1502 Arguments: \%options
1503  
1504 Return Value: $fieldset
1505  
1506 This setting is suitable for most basic forms, and means you can generally
1507 ignore adding fieldsets yourself.
1508  
1509 Calling C<< $form->auto_fieldset(1) >> immediately adds a fieldset element to
1510 the form. Thereafter, C<< $form->elements() >> will add all elements (except
1511 fieldsets) to that fieldset, rather than directly to the form.
1512  
1513 To be specific, the elements are added to the I<last> fieldset on the form,
1514 so if you add another fieldset, any further elements will be added to that
1515 fieldset.
1516  
1517 Also, you may pass a hashref to auto_fieldset(), and this will be used
1518 to set defaults for the first fieldset created.
1519  
1520 A few examples and their output, to demonstrate:
1521  
1522 2 elements with no fieldset.
1523  
1524 ---
1525 elements:
1526 - type: Text
1527 name: foo
1528 - type: Text
1529 name: bar
1530  
1531 <form action="" method="post">
1532 <div class="text">
1533 <input name="foo" type="text" />
1534 </div>
1535 <div class="text">
1536 <input name="bar" type="text" />
1537 </div>
1538 </form>
1539  
1540 2 elements with an L</auto_fieldset>.
1541  
1542 ---
1543 auto_fieldset: 1
1544 elements:
1545 - type: Text
1546 name: foo
1547 - type: Text
1548 name: bar
1549  
1550 <form action="" method="post">
1551 <fieldset>
1552 <div class="text">
1553 <input name="foo" type="text" />
1554 </div>
1555 <div class="text">
1556 <input name="bar" type="text" />
1557 </div>
1558 </fieldset>
1559 </form>
1560  
1561 The 3rd element is within a new fieldset
1562  
1563 ---
1564 auto_fieldset: { id: fs }
1565 elements:
1566 - type: Text
1567 name: foo
1568 - type: Text
1569 name: bar
1570 - type: Fieldset
1571 - type: Text
1572 name: baz
1573  
1574 <form action="" method="post">
1575 <fieldset id="fs">
1576 <div class="text">
1577 <input name="foo" type="text" />
1578 </div>
1579 <div class="text">
1580 <input name="bar" type="text" />
1581 </div>
1582 </fieldset>
1583 <fieldset>
1584 <div class="text">
1585 <input name="baz" type="text" />
1586 </div>
1587 </fieldset>
1588 </form>
1589  
1590 Because of this behaviour, if you want nested fieldsets you will have to add
1591 each nested fieldset directly to its intended parent.
1592  
1593 my $parent = $form->get_element({ type => 'Fieldset' });
1594  
1595 $parent->element('fieldset');
1596  
1597 =head2 form_error_message
1598  
1599 Arguments: $string
1600  
1601 Normally, input errors cause an error message to be displayed alongside the
1602 appropriate form field. If you'd also like a general error message to be
1603 displayed at the top of the form, you can set the message with
1604 L</form_error_message>.
1605  
1606 To set the CSS class for the message, see L</form_error_message_class>.
1607  
1608 To change the markup used to display the message, edit the
1609 C<form_error_message> template file. See L</render_method>.
1610  
1611 Is an L<output accessor|HTML::FormFu/OUTPUT ACCESSORS>.
1612  
1613 =head2 force_error_message
1614  
1615 If true, forces the L</form_error_message> to be displayed even if there are
1616 no field errors.
1617  
1618 =head2 default_args
1619  
1620 Arguments: \%defaults
1621  
1622 Set defaults which will be added to every element, constraint, etc. of the
1623 given type which is subsequently added to the form.
1624  
1625 For example, to make every C<Text> element automatically have a size of
1626 C<10>, and make every C<Strftime> deflator automatically get its strftime
1627 set to C<%d/%m/%Y>:
1628  
1629 default_args:
1630 elements:
1631 Text:
1632 size: 10
1633 deflators:
1634 Strftime:
1635 strftime: '%d/%m/%Y'
1636  
1637 An example to make all DateTime elements automatically get an appropriate
1638 Strftime deflator and a DateTime inflator:
1639  
1640 default_args:
1641 elements:
1642 DateTime:
1643 deflators:
1644 type: Strftime
1645 strftime: '%d-%m-%Y'
1646 inflators:
1647 type: DateTime
1648 parser:
1649 strptime: '%d-%m-%Y'
1650  
1651 =head3 Pseudo types
1652  
1653 As a special case, you can also use the C<elements> keys C<Block>, C<Field>
1654 and C<Input> to match any element which inherits from
1655 L<HTML::FormFu::Element::Block> or which C<does>
1656 L<HTML::FormFu::Role::Element::Field> or
1657 L<HTML::FormFu::Role::Element::Input>.
1658  
1659 =head3 Alternatives
1660  
1661 Each C<elements> key can contain an C<any> list using the C<|> divider: e.g.
1662  
1663 # apply the given class to any Element of type Password or Button
1664 default_args:
1665 elements:
1666 'Password|Button':
1667 attrs:
1668 class: novalidate
1669  
1670 =head3 Match ancestor
1671  
1672 Each C<elements> key list can contain a type starting with C<+> to only
1673 match elements with an ancestor of the given type: e.g.
1674  
1675 # only apple the given class to an Input field within a Multi block
1676 default_args:
1677 elements:
1678 'Input|+Multi':
1679 attrs:
1680 class: novalidate
1681  
1682 =head3 Don't match ancestor
1683  
1684 Each C<elements> key list can contain a type starting with C<-> to only
1685 match elements who do not have an ancestor of the given type: e.g.
1686  
1687 # apply the given class only to Input fields that are not in a Multi block
1688 default_args:
1689 elements:
1690 'Input|-Multi':
1691 attrs:
1692 clasS: validate
1693  
1694 =head3 Order
1695  
1696 The arguments are applied in least- to most-specific order:
1697 C<Block>, C<Field>, C<Input>, C<$type>. Within each of these, arguments are
1698 applied in order of shortest-first to longest-last.
1699  
1700 The C<type> key must match the value returned by C<type>, e.g.
1701 L<HTML::FormFu::Element/type>. If, for example, you have a custom element
1702 outside of the C<HTML::FormFu::Element::*> namespace, which you load via
1703 C<< $form->element({ type => '+My::Custom::Element' }) >>, the key given to
1704 L</default_args> should B<not> include the leading C<+>, as that is
1705 stripped-out of the returned C<type()> value. Example:
1706  
1707 # don't include the leading '+' here
1708 default_args:
1709 elements:
1710 'My::Custom::Element':
1711 attrs:
1712 class: whatever
1713  
1714 # do include the leading '+' here
1715 elements:
1716 - type: +My::Custom::Element
1717  
1718 =head3 Clashes
1719  
1720 L</default_args> generates a single hashref to pass to L</populate>, merging
1721 arguments for each type in turn - meaning L</populate> is only called once
1722 in total - not once for each type.
1723 Because scalar values are B<not> merged - this means later values will
1724 override earlier values: e.g.
1725  
1726 # Normally, calling $field->add_attrs({ class => 'input' })
1727 # then calling $field->add_attrs({ class => 'not-in-multi' })
1728 # would result in both values being retained:
1729 # class="input not-in-multi"
1730 #
1731 # However, default_args() creates a single data-structure to pass once
1732 # to populate(), so any scalar values will overwrite earlier ones
1733 # before they reach populate().
1734 #
1735 # The below example would result in the longest-matching key
1736 # overwriting any others:
1737 # class="not-in-multi"
1738 #
1739 default_args:
1740 elements:
1741 Input:
1742 add_attrs:
1743 class: input
1744 'Input:-Multi':
1745 add_attrs:
1746 class: not-in-multi
1747  
1748 =head3 Strictness
1749  
1750 Note: Unlike the proper methods which have aliases, for example L</elements>
1751 which is an alias for L</element> - the keys given to C<default_args> must
1752 be of the plural form, e.g.:
1753  
1754 default_args:
1755 elements: {}
1756 deflators: {}
1757 filters: {}
1758 constraints: {}
1759 inflators: {}
1760 validators: {}
1761 transformers: {}
1762 output_processors: {}
1763  
1764 =head2 javascript
1765  
1766 If set, the contents will be rendered within a C<script> tag, inside the top
1767 of the form.
1768  
1769 =head2 javascript_src
1770  
1771 Arguments: $url
1772  
1773 Arguments: \@urls
1774  
1775 Adds a C<script> tag for each URL, immediately before any L</javascript>
1776 section.
1777  
1778 =head2 stash
1779  
1780 Arguments: [\%private_stash]
1781  
1782 Return Value: \%stash
1783  
1784 Provides a hash-ref in which you can store any data you might want to
1785 associate with the form.
1786  
1787 ---
1788 stash:
1789 foo: value
1790 bar: value
1791  
1792 =head2 elements
1793  
1794 =head2 element
1795  
1796 Arguments: $type
1797  
1798 Arguments: \%options
1799  
1800 Return Value: $element
1801  
1802 Arguments: \@arrayref_of_types_or_options
1803  
1804 Return Value: @elements
1805  
1806 Adds a new element to the form. See
1807 L<HTML::FormFu::Element/"CORE FORM FIELDS"> and
1808 L<HTML::FormFu::Element/"OTHER CORE ELEMENTS">
1809 for a list of core elements.
1810  
1811 If you want to load an element from a namespace other than
1812 C<HTML::FormFu::Element::>, you can use a fully qualified package-name by
1813 prefixing it with C<+>.
1814  
1815 ---
1816 elements:
1817 - type: +MyApp::CustomElement
1818 name: foo
1819  
1820 If a C<type> is not provided in the C<\%options>, the default C<Text> will
1821 be used.
1822  
1823 L</element> is an alias for L</elements>.
1824  
1825 =head2 deflators
1826  
1827 =head2 deflator
1828  
1829 Arguments: $type
1830  
1831 Arguments: \%options
1832  
1833 Return Value: $deflator
1834  
1835 Arguments: \@arrayref_of_types_or_options
1836  
1837 Return Value: @deflators
1838  
1839 A L<deflator|HTML::FormFu::Deflator> may be associated with any form field,
1840 and allows you to provide
1841 L<< $field->default|HTML::FormFu::Role::Element::Field/default >> with a value
1842 which may be an object.
1843  
1844 If an object doesn't stringify to a suitable value for display, the
1845 L<deflator|HTML::FormFu::Deflator> can ensure that the form field
1846 receives a suitable string value instead.
1847  
1848 See L<HTML::FormFu::Deflator/"CORE DEFLATORS"> for a list of core deflators.
1849  
1850 If a C<name> attribute isn't provided, a new deflator is created for and
1851 added to every field on the form.
1852  
1853 If you want to load a deflator in a namespace other than
1854 C<HTML::FormFu::Deflator::>, you can use a fully qualified package-name by
1855 prefixing it with C<+>.
1856  
1857 L</deflator> is an alias for L</deflators>.
1858  
1859 =head2 insert_before
1860  
1861 Arguments: $new_element, $existing_element
1862  
1863 Return Value: $new_element
1864  
1865 The 1st argument must be the element you want added, the 2nd argument
1866 must be the existing element that the new element should be placed before.
1867  
1868 my $new = $form->element(\%specs);
1869  
1870 my $position = $form->get_element({ type => $type, name => $name });
1871  
1872 $form->insert_before( $new, $position );
1873  
1874 In the first line of the above example, the C<$new> element is initially
1875 added to the end of the form. However, the C<insert_before> method
1876 reparents the C<$new> element, so it will no longer be on the end of the
1877 form. Because of this, if you try to copy an element from one form to
1878 another, it will 'steal' the element, instead of copying it. In this case,
1879 you must use C<clone>:
1880  
1881 my $new = $form1->get_element({ type => $type1, name => $name1 })
1882 ->clone;
1883  
1884 my $position = $form2->get_element({ type => $type2, name => $name2 });
1885  
1886 $form2->insert_before( $new, $position );
1887  
1888 =head2 insert_after
1889  
1890 Arguments: $new_element, $existing_element
1891  
1892 Return Value: $new_element
1893  
1894 The 1st argument must be the element you want added, the 2nd argument
1895 must be the existing element that the new element should be placed after.
1896  
1897 my $new = $form->element(\%specs);
1898  
1899 my $position = $form->get_element({ type => $type, name => $name });
1900  
1901 $form->insert_after( $new, $position );
1902  
1903 In the first line of the above example, the C<$new> element is initially
1904 added to the end of the form. However, the C<insert_after> method
1905 reparents the C<$new> element, so it will no longer be on the end of the
1906 form. Because of this, if you try to copy an element from one form to
1907 another, it will 'steal' the element, instead of copying it. In this case,
1908 you must use C<clone>:
1909  
1910 my $new = $form1->get_element({ type => $type1, name => $name1 })
1911 ->clone;
1912  
1913 my $position = $form2->get_element({ type => $type2, name => $name2 });
1914  
1915 $form2->insert_after( $new, $position );
1916  
1917 =head2 remove_element
1918  
1919 Arguments: $element
1920  
1921 Return Value: $element
1922  
1923 Removes the C<$element> from the form or block's array of children.
1924  
1925 $form->remove_element( $element );
1926  
1927 The orphaned element cannot be usefully used for anything until it is
1928 re-attached to a form or block with L</insert_before> or L</insert_after>.
1929  
1930 =head1 FORM LOGIC AND VALIDATION
1931  
1932 L<HTML::FormFu|HTML::FormFu> provides several stages for what is
1933 traditionally described as I<validation>. These are:
1934  
1935 =over
1936  
1937 =item L<HTML::FormFu::Filter|HTML::FormFu::Filter>
1938  
1939 =item L<HTML::FormFu::Constraint|HTML::FormFu::Constraint>
1940  
1941 =item L<HTML::FormFu::Inflator|HTML::FormFu::Inflator>
1942  
1943 =item L<HTML::FormFu::Validator|HTML::FormFu::Validator>
1944  
1945 =item L<HTML::FormFu::Transformer|HTML::FormFu::Transformer>
1946  
1947 =back
1948  
1949 The first stage, the filters, allow for cleanup of user-input, such as
1950 encoding, or removing leading/trailing whitespace, or removing non-digit
1951 characters from a creditcard number.
1952  
1953 All of the following stages allow for more complex processing, and each of
1954 them have a mechanism to allow exceptions to be thrown, to represent input
1955 errors. In each stage, all form fields must be processed without error for
1956 the next stage to proceed. If there were any errors, the form should be
1957 re-displayed to the user, to allow them to input correct values.
1958  
1959 Constraints are intended for low-level validation of values, such as
1960 "is this an integer?", "is this value within bounds?" or
1961 "is this a valid email address?".
1962  
1963 Inflators are intended to allow a value to be turned into an appropriate
1964 object. The resulting object will be passed to subsequent Validators and
1965 Transformers, and will also be returned by L</params> and L</param>.
1966  
1967 Validators are intended for higher-level validation, such as
1968 business-logic and database constraints such as "is this username unique?".
1969 Validators are only run if all Constraints and Inflators have run
1970 without errors. It is expected that most Validators will be
1971 application-specific, and so each will be implemented as a separate class
1972 written by the HTML::FormFu user.
1973  
1974 =head2 filters
1975  
1976 =head2 filter
1977  
1978 Arguments: $type
1979  
1980 Arguments: \%options
1981  
1982 Return Value: $filter
1983  
1984 Arguments: \@arrayref_of_types_or_options
1985  
1986 Return Value: @filters
1987  
1988 If you provide a C<name> or C<names> value, the filter will be added to
1989 just that named field.
1990 If you do not provide a C<name> or C<names> value, the filter will be added
1991 to all L<fields|HTML::FormFu::Role::Element::Field> already attached to the form.
1992  
1993 See L<HTML::FormFu::Filter/"CORE FILTERS"> for a list of core filters.
1994  
1995 If you want to load a filter in a namespace other than
1996 C<HTML::FormFu::Filter::>, you can use a fully qualified package-name by
1997 prefixing it with C<+>.
1998  
1999 L</filter> is an alias for L</filters>.
2000  
2001 =head2 constraints
2002  
2003 =head2 constraint
2004  
2005 Arguments: $type
2006  
2007 Arguments: \%options
2008  
2009 Return Value: $constraint
2010  
2011 Arguments: \@arrayref_of_types_or_options
2012  
2013 Return Value: @constraints
2014  
2015 See L<HTML::FormFu::Constraint/"CORE CONSTRAINTS"> for a list of core
2016 constraints.
2017  
2018 If a C<name> attribute isn't provided, a new constraint is created for and
2019 added to every field on the form.
2020  
2021 If you want to load a constraint in a namespace other than
2022 C<HTML::FormFu::Constraint::>, you can use a fully qualified package-name by
2023 prefixing it with C<+>.
2024  
2025 L</constraint> is an alias for L</constraints>.
2026  
2027 =head2 inflators
2028  
2029 =head2 inflator
2030  
2031 Arguments: $type
2032  
2033 Arguments: \%options
2034  
2035 Return Value: $inflator
2036  
2037 Arguments: \@arrayref_of_types_or_options
2038  
2039 Return Value: @inflators
2040  
2041 See L<HTML::FormFu::Inflator/"CORE INFLATORS"> for a list of core inflators.
2042  
2043 If a C<name> attribute isn't provided, a new inflator is created for and
2044 added to every field on the form.
2045  
2046 If you want to load an inflator in a namespace other than
2047 C<HTML::FormFu::Inflator::>, you can use a fully qualified package-name by
2048 prefixing it with C<+>.
2049  
2050 L</inflator> is an alias for L</inflators>.
2051  
2052 =head2 validators
2053  
2054 =head2 validator
2055  
2056 Arguments: $type
2057  
2058 Arguments: \%options
2059  
2060 Return Value: $validator
2061  
2062 Arguments: \@arrayref_of_types_or_options
2063  
2064 Return Value: @validators
2065  
2066 See L<HTML::FormFu::Validator/"CORE VALIDATORS"> for a list of core
2067 validators.
2068  
2069 If a C<name> attribute isn't provided, a new validator is created for and
2070 added to every field on the form.
2071  
2072 If you want to load a validator in a namespace other than
2073 C<HTML::FormFu::Validator::>, you can use a fully qualified package-name by
2074 prefixing it with C<+>.
2075  
2076 L</validator> is an alias for L</validators>.
2077  
2078 =head2 transformers
2079  
2080 =head2 transformer
2081  
2082 Arguments: $type
2083  
2084 Arguments: \%options
2085  
2086 Return Value: $transformer
2087  
2088 Arguments: \@arrayref_of_types_or_options
2089  
2090 Return Value: @transformers
2091  
2092 See L<HTML::FormFu::Transformer/"CORE TRANSFORMERS"> for a list of core
2093 transformers.
2094  
2095 If a C<name> attribute isn't provided, a new transformer is created for and
2096 added to every field on the form.
2097  
2098 If you want to load a transformer in a namespace other than
2099 C<HTML::FormFu::Transformer::>, you can use a fully qualified package-name by
2100 prefixing it with C<+>.
2101  
2102 L</transformer> is an alias for L</transformers>.
2103  
2104 =head1 CHANGING DEFAULT BEHAVIOUR
2105  
2106 =head2 render_processed_value
2107  
2108 The default behaviour when re-displaying a form after a submission, is that
2109 the field contains the original unchanged user-submitted value.
2110  
2111 If L</render_processed_value> is true, the field value will be the final
2112 result after all Filters, Inflators and Transformers have been run.
2113 Deflators will also be run on the value.
2114  
2115 If you set this on a field with an Inflator, but without an equivalent
2116 Deflator, you should ensure that the Inflators stringify back to a usable
2117 value, so as not to confuse / annoy the user.
2118  
2119 Default Value: false
2120  
2121 This method is a special 'inherited accessor', which means it can be set on
2122 the form, a block element or a single element. When the value is read, if
2123 no value is defined it automatically traverses the element's hierarchy of
2124 parents, through any block elements and up to the form, searching for a
2125 defined value.
2126  
2127 Is an L<inheriting accessor|/INHERITING ACCESSORS>.
2128  
2129 =head2 force_errors
2130  
2131 Force a constraint to fail, regardless of user input.
2132  
2133 If this is called at runtime, after the form has already been processed,
2134 you must called L<HTML::FormFu/process> again before redisplaying the
2135 form to the user.
2136  
2137 Default Value: false
2138  
2139 This method is a special 'inherited accessor', which means it can be set on
2140 the form, a block element, an element or a single constraint. When the value
2141 is read, if no value is defined it automatically traverses the element's
2142 hierarchy of parents, through any block elements and up to the form,
2143 searching for a defined value.
2144  
2145 Is an L<inheriting accessor|/INHERITING ACCESSORS>.
2146  
2147 =head2 params_ignore_underscore
2148  
2149 If true, causes L</params>, L</param> and L</valid> to ignore any fields
2150 whose name starts with an underscore C<_>.
2151  
2152 The field is still processed as normal, and errors will cause
2153 L</submitted_and_valid> to return false.
2154  
2155 Default Value: false
2156  
2157 =head1 FORM ATTRIBUTES
2158  
2159 All attributes are added to the rendered form's start tag.
2160  
2161 =head2 attributes
2162  
2163 # Example
2164 ---
2165 attributes:
2166 id: form
2167 class: fancy_form
2168  
2169 Is an L<attribute accessor|HTML::FormFu/ATTRIBUTE ACCESSOR>.
2170  
2171 =head2 id
2172  
2173 Is an L<attribute short-cut|HTML::FormFu/ATTRIBUTE SHORT-CUTS>.
2174  
2175 =head2 action
2176  
2177 Default Value: ""
2178  
2179 Get or set the action associated with the form. The default is no action,
2180 which causes most browsers to submit to the current URI.
2181  
2182 Is an L<attribute short-cut|HTML::FormFu/ATTRIBUTE SHORT-CUTS>.
2183  
2184 =head2 enctype
2185  
2186 Get or set the encoding type of the form. Valid values are
2187 C<application/x-www-form-urlencoded> and C<multipart/form-data>.
2188  
2189 If the form contains a File element, the enctype is automatically set to
2190 C<multipart/form-data>.
2191  
2192 Is an L<attribute short-cut|HTML::FormFu/ATTRIBUTE SHORT-CUTS>.
2193  
2194 =head2 method
2195  
2196 Default Value: "post"
2197  
2198 Get or set the method used to submit the form. Can be set to either "post"
2199 or "get".
2200  
2201 Is an L<attribute short-cut|HTML::FormFu/ATTRIBUTE SHORT-CUTS>.
2202  
2203 =head2 title
2204  
2205 Get or set the form's title attribute.
2206  
2207 Is an L<attribute short-cut|HTML::FormFu/ATTRIBUTE SHORT-CUTS>.
2208  
2209 =head1 CSS CLASSES
2210  
2211 =head2 form_error_message_class
2212  
2213 Class attribute for the error message displayed at the top of the form.
2214  
2215 See L</"form_error_message">
2216  
2217 =head1 LOCALIZATION
2218  
2219 =head2 languages
2220  
2221 Arguments: [\@languages]
2222  
2223 A list of languages which will be passed to the localization object.
2224  
2225 Default Value: ['en']
2226  
2227 =head2 localize_class
2228  
2229 Arguments: [$class_name]
2230  
2231 Classname to be used for the default localization object.
2232  
2233 Default Value: 'HTML::FormFu::I18N'
2234  
2235 =head2 localize
2236  
2237 =head2 loc
2238  
2239 Arguments: [$key, @arguments]
2240  
2241 Compatible with the C<maketext> method in L<Locale::Maketext>.
2242  
2243 =head2 locale
2244  
2245 Arguments: $locale
2246  
2247 Currently only used by L<HTML::FormFu::Deflator::FormatNumber> and
2248 L<HTML::FormFu::Filter::FormatNumber>.
2249  
2250 This method is a special 'inherited accessor', which means it can be set on
2251 the form, a block element or a single element. When the value is read, if
2252 no value is defined it automatically traverses the element's hierarchy of
2253 parents, through any block elements and up to the form, searching for a
2254 defined value.
2255  
2256 Is an L<inheriting accessor|/INHERITING ACCESSORS>.
2257  
2258 =head1 PROCESSING A FORM
2259  
2260 =head2 query
2261  
2262 Arguments: [$query_object]
2263  
2264 Arguments: \%params
2265  
2266 Provide a L<CGI> compatible query object or a hash-ref of submitted
2267 names/values. Alternatively, the query object can be passed directly to the
2268 L</process> object.
2269  
2270 =head2 query_type
2271  
2272 Arguments: [$query_type]
2273  
2274 Set which module is being used to provide the L</query>.
2275  
2276 The L<Catalyst::Controller::HTML::FormFu> automatically sets this to
2277 C<Catalyst>.
2278  
2279 Valid values are C<CGI>, C<Catalyst> and C<CGI::Simple>.
2280  
2281 Default Value: 'CGI'
2282  
2283 =head2 process
2284  
2285 Arguments: [$query_object]
2286  
2287 Arguments: [\%params]
2288  
2289 Process the provided query object or input values. C<process> must be called
2290 before calling any of the methods listed under
2291 L</"SUBMITTED FORM VALUES AND ERRORS"> and L</"MODIFYING A SUBMITTED FORM">.
2292  
2293 C<process> must also be called at least once before printing the form or
2294 calling L</render> or L</render_data>.
2295  
2296 Note to users of L<Catalyst::Controller::HTML::FormFu>: Because L</process>
2297 is automatically called for you by the Catalyst controller; if you make any
2298 modifications to the form within your action method, such as adding or changing
2299 elements, adding constraints, etc; you must call L</process> again yourself
2300 before using L</submitted_and_valid>, any of the methods listed under
2301 L</"SUBMITTED FORM VALUES AND ERRORS"> or
2302 L</"MODIFYING A SUBMITTED FORM">, or rendering the form.
2303  
2304 =head1 SUBMITTED FORM VALUES AND ERRORS
2305  
2306 =head2 submitted
2307  
2308 Returns true if the form has been submitted. See L</indicator> for details
2309 on how this is computed.
2310  
2311 =head2 submitted_and_valid
2312  
2313 Shorthand for C<< $form->submitted && !$form->has_errors >>
2314  
2315 =head2 params
2316  
2317 Return Value: \%params
2318  
2319 Returns a hash-ref of all valid input for which there were no errors.
2320  
2321 =head2 param_value
2322  
2323 Arguments: $field_name
2324  
2325 A more reliable, recommended version of L</param>. Guaranteed to always return a
2326 single value, regardless of whether it's called in list context or not. If
2327 multiple values were submitted, this only returns the first value. If the value
2328 is invalid or the form was not submitted, it returns C<undef>. This makes it
2329 suitable for use in list context, where a single value is required.
2330  
2331 $db->update({
2332 name => $form->param_value('name'),
2333 address => $form->param_value('address),
2334 });
2335  
2336 =head2 param_array
2337  
2338 Arguments: $field_name
2339  
2340 Guaranteed to always return an array-ref of values, regardless of context and
2341 regardless of whether multiple values were submitted or not. If the value is
2342 invalid or the form was not submitted, it returns an empty array-ref.
2343  
2344 =head2 param_list
2345  
2346 Arguments: $field_name
2347  
2348 Guaranteed to always return a list of values, regardless of context. If the value is
2349 invalid or the form was not submitted, it returns an empty list.
2350  
2351 =head2 param
2352  
2353 Arguments: [$field_name]
2354  
2355 Return Value: $input_value
2356  
2357 Return Value: @valid_names
2358  
2359 No longer recommended for use, as its behaviour is hard to predict. Use
2360 L</param_value>, L</param_array> or L</param_list> instead.
2361  
2362 A (readonly) method similar to that of L<CGI's|CGI>.
2363  
2364 If a field name is given, in list-context returns any valid values submitted
2365 for that field, and in scalar-context returns only the first of any valid
2366 values submitted for that field.
2367  
2368 If no argument is given, returns a list of all valid input field names
2369 without errors.
2370  
2371 Passing more than 1 argument is a fatal error.
2372  
2373 =head2 valid
2374  
2375 Arguments: [$field_name]
2376  
2377 Return Value: @valid_names
2378  
2379 Return Value: $bool
2380  
2381 If a field name if given, returns C<true> if that field had no errors and
2382 C<false> if there were errors.
2383  
2384 If no argument is given, returns a list of all valid input field names
2385 without errors.
2386  
2387 =head2 has_errors
2388  
2389 Arguments: [$field_name]
2390  
2391 Return Value: @names
2392  
2393 Return Value: $bool
2394  
2395 If a field name if given, returns C<true> if that field had errors and
2396 C<false> if there were no errors.
2397  
2398 If no argument is given, returns a list of all input field names with errors.
2399  
2400 =head2 get_errors
2401  
2402 Arguments: [%options]
2403  
2404 Arguments: [\%options]
2405  
2406 Return Value: \@errors
2407  
2408 Returns an array-ref of exception objects from all fields in the form.
2409  
2410 Accepts both C<name>, C<type> and C<stage> arguments to narrow the returned
2411 results.
2412  
2413 $form->get_errors({
2414 name => 'foo',
2415 type => 'Regex',
2416 stage => 'constraint'
2417 });
2418  
2419 =head2 get_error
2420  
2421 Arguments: [%options]
2422  
2423 Arguments: [\%options]
2424  
2425 Return Value: $error
2426  
2427 Accepts the same arguments as L</get_errors>, but only returns the first
2428 error found.
2429  
2430 =head1 MODEL / DATABASE INTERACTION
2431  
2432 See L<HTML::FormFu::Model> for further details and available models.
2433  
2434 =head2 default_model
2435  
2436 Arguments: $model_name
2437  
2438 Default Value: 'DBIC'
2439  
2440 =head2 model
2441  
2442 Arguments: [$model_name]
2443  
2444 Return Value: $model
2445  
2446 =head2 model_config
2447  
2448 Arguments: \%config
2449  
2450 =head1 MODIFYING A SUBMITTED FORM
2451  
2452 =head2 add_valid
2453  
2454 Arguments: $name, $value
2455  
2456 Return Value: $value
2457  
2458 The provided value replaces any current value for the named field. This
2459 value will be returned in subsequent calls to L</params> and L</param> and
2460 the named field will be included in calculations for L</valid>.
2461  
2462 =head2 clear_errors
2463  
2464 Deletes all errors from a submitted form.
2465  
2466 =head1 RENDERING A FORM
2467  
2468 =head2 render
2469  
2470 Return Value: $string
2471  
2472 You must call L</process> once after building the form, and before calling
2473 L</render>.
2474  
2475 =head2 start
2476  
2477 Return Value: $string
2478  
2479 Returns the form start tag, and any output of L</form_error_message> and
2480 L</javascript>.
2481  
2482 =head2 end
2483  
2484 Return Value: $string
2485  
2486 Returns the form end tag.
2487  
2488 =head2 hidden_fields
2489  
2490 Return Value: $string
2491  
2492 Returns all hidden form fields.
2493  
2494 =head1 PLUGIN SYSTEM
2495  
2496 C<HTML::FormFu> provides a plugin-system that allows plugins to be easily
2497 added to a form or element, to change the default behaviour or output.
2498  
2499 See L<HTML::FormFu::Plugin> for details.
2500  
2501 =head1 ADVANCED CUSTOMISATION
2502  
2503 By default, formfu renders "XHTML 1.0 Strict" compliant markup, with as
2504 little extra markup as possible. Many hooks are provided to add
2505 programatically-generated CSS class names, to allow for a wide-range of
2506 output styles to be generated by changing only the CSS.
2507  
2508 Basic customisation of the markup is possible via the
2509 L<layout|HTML::FormFu::Role::Element::Field/layout> and
2510 L<multi_layout|HTML::FormFu::Role::Element::Field/multi_layout> methods.
2511 This allows you to reorder the position of various parts of each field -
2512 such as the label, comment, error messages and the input tag - as well
2513 as inserting any other arbitrary tags you may wish.
2514  
2515 If this is not sufficient, you can make completely personalise the markup
2516 by telling HTML::FormFu to use an external rendering engine, such as
2517 L<Template Toolkit|Template> or L<Template::Alloy>.
2518 See L</render_method> and L</tt_module> for details.
2519  
2520 Even if you set HTML::FormFu to use L<Template::Toolkit|Template> to render,
2521 the forms, HTML::FormFu can still be used in conjunction with whichever other
2522 templating system you prefer to use for your own page layouts, whether it's
2523 L<HTML::Template>: C<< <TMPL_VAR form> >>,
2524 L<Petal>: C<< <form tal:replace="form"></form> >>
2525 or L<Template::Magic>: C<< <!-- {form} --> >>.
2526  
2527 As of C<HTML::FormFu v1.00>, L<TT|Template> is no longer listed a required
2528 prerequisite - so you'll need to install it manually if you with to use the
2529 template files.
2530  
2531 =head2 render_method
2532  
2533 Default Value: C<string>
2534  
2535 Can be set to C<tt> to generate the form with external template files.
2536  
2537 To customise the markup, you'll need a copy of the template files, local to
2538 your application. See
2539 L<HTML::FormFu::Manual::Cookbook/"Installing the TT templates"> for further
2540 details.
2541  
2542 You can customise the markup for a single element by setting that element's
2543 L</render_method> to C<tt>, while the rest of the form uses the default
2544 C<string> render-method. Note though, that if you try setting the form or a
2545 Block's L</render_method> to C<tt>, and then set a child element's
2546 L</render_method> to C<string>, that setting will be ignored, and the child
2547 elements will still use the C<tt> render-method.
2548  
2549 ---
2550 elements:
2551 - name: foo
2552 render_method: tt
2553 filename: custom_field
2554  
2555 - name: bar
2556  
2557 # in this example, 'foo' will use a custom template,
2558 # while bar will use the default 'string' rendering method
2559  
2560 This method is a special 'inherited accessor', which means it can be set on
2561 the form, a block element or a single element. When the value is read, if
2562 no value is defined it automatically traverses the element's hierarchy of
2563 parents, through any block elements and up to the form, searching for a
2564 defined value.
2565  
2566 Is an L<inheriting accessor|/INHERITING ACCESSORS>.
2567  
2568 =head2 filename
2569  
2570 Change the template filename used for the form.
2571  
2572 Default Value: "form"
2573  
2574 =head2 tt_args
2575  
2576 Arguments: [\%constructor_arguments]
2577  
2578 Accepts a hash-ref of arguments passed to L</render_method>, which is called
2579 internally by L</render>.
2580  
2581 Within tt_args, the keys C<RELATIVE> and C<RECURSION> are overridden to always
2582 be true, as these are a basic requirement for the L<Template> engine.
2583  
2584 The system directory containing HTML::FormFu's template files is always
2585 added to the end of C<INCLUDE_PATH>, so that the core template files will be
2586 found. You only need to set this yourself if you have your own copy of the
2587 template files for customisation purposes.
2588  
2589 This method is a special 'inherited accessor', which means it can be set on
2590 the form, a block element or a single element. When the value is read, if
2591 no value is defined it automatically traverses the element's hierarchy of
2592 parents, through any block elements and up to the form, searching for a
2593 defined value.
2594  
2595 =head2 add_tt_args
2596  
2597 Arguments: [\%constructor_arguments]
2598  
2599 Ensures that the hash-ref argument is merged with any existing hash-ref
2600 value of L</tt_args>.
2601  
2602 =head2 tt_module
2603  
2604 Default Value: Template
2605  
2606 The module used when L</render_method> is set to C<tt>. Should provide an
2607 interface compatible with L<Template>.
2608  
2609 This method is a special 'inherited accessor', which means it can be set on
2610 the form, a block element or a single element. When the value is read, if
2611 no value is defined it automatically traverses the element's hierarchy of
2612 parents, through any block elements and up to the form, searching for a
2613 defined value.
2614  
2615 =head2 render_data
2616  
2617 Usually called implicitly by L</render>. Returns the data structure that
2618 would normally be passed onto the C<string> or C<tt> render-methods.
2619  
2620 As with L</render>, you must call L</process> once after building the form,
2621 and before calling L</render_data>.
2622  
2623 =head2 render_data_non_recursive
2624  
2625 Like L</render_data>, but doesn't include the data for any child-elements.
2626  
2627 =head1 INTROSPECTION
2628  
2629 =head2 get_fields
2630  
2631 Arguments: [%options]
2632  
2633 Arguments: [\%options]
2634  
2635 Return Value: \@elements
2636  
2637 Returns all fields in the form (specifically, all elements which have a true
2638 L<HTML::FormFu::Element/is_field> value).
2639  
2640 Accepts both C<name> and C<type> arguments to narrow the returned results.
2641  
2642 $form->get_fields({
2643 name => 'foo',
2644 type => 'Radio',
2645 });
2646  
2647 Accepts also an Regexp to search for results.
2648  
2649 $form->get_elements({
2650 name => qr/oo/,
2651 });
2652  
2653 =head2 get_field
2654  
2655 Arguments: [%options]
2656  
2657 Arguments: [\%options]
2658  
2659 Return Value: $element
2660  
2661 Accepts the same arguments as L</get_fields>, but only returns the first
2662 field found.
2663  
2664 =head2 get_elements
2665  
2666 Arguments: [%options]
2667  
2668 Arguments: [\%options]
2669  
2670 Return Value: \@elements
2671  
2672 Returns all top-level elements in the form (not recursive).
2673 See L</get_all_elements> for a recursive version.
2674  
2675 Accepts both C<name> and C<type> arguments to narrow the returned results.
2676  
2677 $form->get_elements({
2678 name => 'foo',
2679 type => 'Radio',
2680 });
2681  
2682 Accepts also an Regexp to search for results.
2683  
2684 $form->get_elements({
2685 name => qr/oo/,
2686 });
2687  
2688 =head2 get_element
2689  
2690 Arguments: [%options]
2691  
2692 Arguments: [\%options]
2693  
2694 Return Value: $element
2695  
2696 Accepts the same arguments as L</get_elements>, but only returns the first
2697 element found.
2698  
2699 See L</get_all_element> for a recursive version.
2700  
2701 =head2 get_all_elements
2702  
2703 Arguments: [%options]
2704  
2705 Arguments: [\%options]
2706  
2707 Return Value: \@elements
2708  
2709 Returns all elements in the form recursively.
2710  
2711 Optionally accepts both C<name> and C<type> arguments to narrow the returned
2712 results.
2713  
2714 # return all Text elements
2715  
2716 $form->get_all_elements({
2717 type => 'Text',
2718 });
2719  
2720 Accepts also an Regexp to search for results.
2721  
2722 $form->get_elements({
2723 name => qr/oo/,
2724 });
2725  
2726 See L</get_elements> for a non-recursive version.
2727  
2728 =head2 get_all_element
2729  
2730 Arguments: [%options]
2731  
2732 Arguments: [\%options]
2733  
2734 Return Value: $element
2735  
2736 Accepts the same arguments as L</get_all_elements>, but only returns the
2737 first element found.
2738  
2739 # return the first Text field found, regardless of whether it's
2740 # within a fieldset or not
2741  
2742 $form->get_all_element({
2743 type => 'Text',
2744 });
2745  
2746 Accepts also an Regexp to search for results.
2747  
2748 $form->get_elements({
2749 name => qr/oo/,
2750 });
2751  
2752 See L</get_all_elements> for a non-recursive version.
2753  
2754 =head2 get_deflators
2755  
2756 Arguments: [%options]
2757  
2758 Arguments: [\%options]
2759  
2760 Return Value: \@deflators
2761  
2762 Returns all top-level deflators from all fields.
2763  
2764 Accepts both C<name> and C<type> arguments to narrow the returned results.
2765  
2766 $form->get_deflators({
2767 name => 'foo',
2768 type => 'Strftime',
2769 });
2770  
2771 =head2 get_deflator
2772  
2773 Arguments: [%options]
2774  
2775 Arguments: [\%options]
2776  
2777 Return Value: $element
2778  
2779 Accepts the same arguments as L</get_deflators>, but only returns the first
2780 deflator found.
2781  
2782 =head2 get_filters
2783  
2784 Arguments: [%options]
2785  
2786 Arguments: [\%options]
2787  
2788 Return Value: \@filters
2789  
2790 Returns all top-level filters from all fields.
2791  
2792 Accepts both C<name> and C<type> arguments to narrow the returned results.
2793  
2794 $form->get_filters({
2795 name => 'foo',
2796 type => 'LowerCase',
2797 });
2798  
2799 =head2 get_filter
2800  
2801 Arguments: [%options]
2802  
2803 Arguments: [\%options]
2804  
2805 Return Value: $filter
2806  
2807 Accepts the same arguments as L</get_filters>, but only returns the first
2808 filter found.
2809  
2810 =head2 get_constraints
2811  
2812 Arguments: [%options]
2813  
2814 Arguments: [\%options]
2815  
2816 Return Value: \@constraints
2817  
2818 Returns all constraints from all fields.
2819  
2820 Accepts both C<name> and C<type> arguments to narrow the returned results.
2821  
2822 $form->get_constraints({
2823 name => 'foo',
2824 type => 'Equal',
2825 });
2826  
2827 =head2 get_constraint
2828  
2829 Arguments: [%options]
2830  
2831 Arguments: [\%options]
2832  
2833 Return Value: $constraint
2834  
2835 Accepts the same arguments as L</get_constraints>, but only returns the
2836 first constraint found.
2837  
2838 =head2 get_inflators
2839  
2840 Arguments: [%options]
2841  
2842 Arguments: [\%options]
2843  
2844 Return Value: \@inflators
2845  
2846 Returns all inflators from all fields.
2847  
2848 Accepts both C<name> and C<type> arguments to narrow the returned results.
2849  
2850 $form->get_inflators({
2851 name => 'foo',
2852 type => 'DateTime',
2853 });
2854  
2855 =head2 get_inflator
2856  
2857 Arguments: [%options]
2858  
2859 Arguments: [\%options]
2860  
2861 Return Value: $inflator
2862  
2863 Accepts the same arguments as L</get_inflators>, but only returns the
2864 first inflator found.
2865  
2866 =head2 get_validators
2867  
2868 Arguments: [%options]
2869  
2870 Arguments: [\%options]
2871  
2872 Return Value: \@validators
2873  
2874 Returns all validators from all fields.
2875  
2876 Accepts both C<name> and C<type> arguments to narrow the returned results.
2877  
2878 $form->get_validators({
2879 name => 'foo',
2880 type => 'Callback',
2881 });
2882  
2883 =head2 get_validator
2884  
2885 Arguments: [%options]
2886  
2887 Arguments: [\%options]
2888  
2889 Return Value: $validator
2890  
2891 Accepts the same arguments as L</get_validators>, but only returns the
2892 first validator found.
2893  
2894 =head2 get_transformers
2895  
2896 Arguments: [%options]
2897  
2898 Arguments: [\%options]
2899  
2900 Return Value: \@transformers
2901  
2902 Returns all transformers from all fields.
2903  
2904 Accepts both C<name> and C<type> arguments to narrow the returned results.
2905  
2906 $form->get_transformers({
2907 name => 'foo',
2908 type => 'Callback',
2909 });
2910  
2911 =head2 get_transformer
2912  
2913 Arguments: [%options]
2914  
2915 Arguments: [\%options]
2916  
2917 Return Value: $transformer
2918  
2919 Accepts the same arguments as L</get_transformers>, but only returns the
2920 first transformer found.
2921  
2922 =head2 clone
2923  
2924 Returns a deep clone of the <$form> object.
2925  
2926 Because of scoping issues, code references (such as in Callback constraints)
2927 are copied instead of cloned.
2928  
2929 =head1 ATTRIBUTE ACCESSORS
2930  
2931 For the basic method, e.g. C</attributes>:
2932  
2933 Arguments: [%attributes]
2934  
2935 Arguments: [\%attributes]
2936  
2937 Return Value: $form
2938  
2939 As a special case, if no arguments are passed, the attributes hash-ref is
2940 returned. This allows the following idioms.
2941  
2942 # set a value
2943 $form->attributes->{id} = 'form';
2944  
2945 # delete all attributes
2946 %{ $form->attributes } = ();
2947  
2948 All methods documented as 'attribute accessors' also have the following
2949 variants generated:
2950  
2951 C<*_xml> can be used as a setter, and ensures that its argument is not
2952 XML-escaped in the rendered form.
2953  
2954 C<*_loc> can he used as a setter, and passes the arguments through
2955 L</localize>.
2956  
2957 C<add_*> can be used to append a word to an attribute without overwriting
2958 any already-existing value.
2959  
2960 # Example
2961 $form->attributes({ class => 'fancy' });
2962 $form->add_attributes({ class => 'pants' });
2963 # class="fancy pants"
2964  
2965 C<add_*_xml>, like C<add_*>, but ensures it doesn't get XML-escaped.
2966  
2967 C<add_*_loc>, like C<add_*>, but passing the arguments through L</localize>.
2968  
2969 C<del_*> can be used to remove a word from an attribute value.
2970  
2971 # Example
2972 $form->attributes({ class => 'fancy pants' });
2973 $form->del_attributes({ class => 'pants' });
2974 # class="fancy"
2975  
2976 C<del_*_xml>, like C<del_*>, but ensures it doesn't get XML-escaped.
2977  
2978 C<del_*_loc>, like C<del_*>, but passing the arguments through L</localize>.
2979  
2980 Also, any attribute method-name which contains the word C<attributes> also
2981 has aliases created for all these variants, with the word C<attributes>
2982 replaced by C<attrs>.
2983  
2984 # For example, the attributes() method would have all these variant
2985 # methods available
2986  
2987 $form->attributes({ class => 'fancy' });
2988 $form->attributes_xml({ title => '<b>fancy</b>' });
2989 $form->attributes_loc({ title => 'fancy' });
2990 $form->add_attributes({ class => 'fancy' });
2991 $form->add_attributes_xml({ title => '<b>fancy</b>' });
2992 $form->add_attributes_loc({ title => 'fancy' });
2993 $form->del_attributes({ class => 'fancy' });
2994 $form->del_attributes_xml({ title => '<b>fancy</b>' });
2995 $form->del_attributes_loc({ title => 'fancy' });
2996  
2997 # Because the method contains the word 'attributes', it also gets the
2998 # following short-forms
2999  
3000 $form->attrs({ class => 'fancy' });
3001 $form->attrs_xml({ title => '<b>fancy</b>' });
3002 $form->attrs_loc({ title => 'fancy' });
3003 $form->add_attrs({ class => 'fancy' });
3004 $form->add_attrs_xml({ title => '<b>fancy</b>' });
3005 $form->add_attrs_loc({ title => 'fancy' });
3006 $form->del_attrs({ class => 'fancy' });
3007 $form->del_attrs_xml({ title => '<b>fancy</b>' });
3008 $form->del_attrs_loc({ title => 'fancy' });
3009  
3010 =head1 ATTRIBUTE SHORT-CUTS
3011  
3012 All methods documented as 'attribute short-cuts' are short-cuts to directly
3013 access individual attribute key/values.
3014  
3015 # Example
3016 $form->id( 'login' );
3017 $id = $form->id;
3018  
3019 # is equivalent to:
3020 $form->attributes({ id => 'login' });
3021 $id = $form->attributes->{id};
3022  
3023 All attribute short-cuts also have a C<*_xml> variant.
3024  
3025 # Example
3026 $form->id_xml( $xml );
3027  
3028 # is equivalent to:
3029 $form->attributes_xml({ id => $xml });
3030  
3031 All attribute short-cuts also have a C<*_loc> variant.
3032  
3033 # Example
3034 $form->title_loc( $key );
3035  
3036 # is equivalent to:
3037 $form->attributes_loc({ title => $key });
3038  
3039 =head1 INHERITING ACCESSORS
3040  
3041 All methods documented as 'inheriting accessors' can be set on the form,
3042 a block element or a single field element.
3043 When the value is read, if no value is defined it automatically traverses
3044 the element's hierarchy of parents, searching for a defined value.
3045  
3046 All inherited accessors also have a C<*_no_inherit> variant, which can be
3047 used as a getter to fetch any defined value, without traversing the
3048 hierarchy of parents. This variant cannot be used as a setter.
3049  
3050 E.g., the L</auto_id> has a variant named C<auto_id_no_inherit>.
3051  
3052 =head1 OUTPUT ACCESSORS
3053  
3054 All methods documented as 'output accessors' also have C<*_xml> and C<*_loc>
3055 variants.
3056  
3057 The C<*_xml> variant can be used as a setter, and ensures that its
3058 argument is not XML-escaped in the rendered form.
3059  
3060 The C<*_loc> variant can be used as a setter, and passes the arguments
3061 through L</localize>.
3062  
3063 E.g., the L<label|HTML::FormFu::Role::Element::Field/label> method has
3064 variants named C<label_xml> and C<label_loc>.
3065  
3066 =head1 BOOLEAN ATTRIBUTE ACCESSORS
3067  
3068 To support boolean attributes, whose value should either be equal to the
3069 attribute name, or empty. Any true value will switch the attribute 'on', any
3070 false value will remove the attribute.
3071  
3072 # Example
3073  
3074 $field->autofocus(1);
3075 # equivalent to:
3076 $field->attributes({ autofocus => 'autofocus' });
3077  
3078 $field->autofocus(0);;
3079 # equivalent to:
3080 delete $field->attributes->{autofocus};
3081  
3082 =head1 ATTRIBUTE SUBSTITUTIONS
3083  
3084 Some attributes support character substitutions: the following substitutions
3085 are possible:
3086  
3087 %f # $form->id
3088 %n # $field->name
3089 %t # lc( $field->type )
3090 %r # $block->repeatable_count
3091 %s # $error->stage
3092  
3093 These allow each field to have consistent attributes, while remaining unique.
3094  
3095 =head1 DEPRECATION POLICY
3096  
3097 We try our best to not make incompatible changes, but if they're required
3098 we'll make every effort possible to provide backwards compatibility for
3099 several release-cycles, issuing a warnings about the changes, before removing
3100 the legacy features.
3101  
3102 =head1 RESTORING LEGACY HTML CLASSES
3103  
3104 C<v1.00> dropped most of the default HTML class-names, with the intention
3105 that each application should define just what it needs, without needing to
3106 reset unwanted options first. We also gain the benefit of less markup being
3107 generated, speeding up both L<render|/render> and HTTP transfers.
3108  
3109 To restore the previous behaviour, set the following options.
3110  
3111 If you're using L<best practices|/"BEST PRACTICES">, you'll only need to set
3112 these once per-application in your app-wide config file.
3113  
3114 ---
3115 auto_container_class: '%t'
3116 auto_container_label_class: 'label'
3117 auto_container_comment_class: 'comment'
3118 auto_comment_class: 'comment'
3119 auto_container_error_class: 'error'
3120 auto_container_per_error_class: 'error_%s_%t'
3121 auto_error_class: 'error_message error_%s_%t'
3122  
3123 =head1 DEPRECATED METHODS
3124  
3125 See L<HTML::FormFu::Role::Element::Field/"DEPRECATED METHODS">.
3126  
3127 =head1 REMOVED METHODS
3128  
3129 See also L<HTML::FormFu::Element/"REMOVED METHODS">.
3130  
3131 =head2 element_defaults
3132  
3133 Has been removed; see L</default_args> instead.
3134  
3135 =head2 model_class
3136  
3137 Has been removed; use L</default_model> instead.
3138  
3139 =head2 defaults_from_model
3140  
3141 Has been removed; use L<HTML::FormFu::Model/default_values> instead.
3142  
3143 =head2 save_to_model
3144  
3145 Has been removed; use L<HTML::FormFu::Model/update> instead.
3146  
3147 =head1 BEST PRACTICES
3148  
3149 It is advisable to keep application-wide (or global) settings in a single
3150 config file, which should be loaded by each form.
3151  
3152 See L</load_config_file>.
3153  
3154 =head1 COOKBOOK
3155  
3156 L<HTML::FormFu::Manual::Cookbook>
3157  
3158 =head2 UNICODE
3159  
3160 L<HTML::FormFu::Manual::Unicode>
3161  
3162 =head1 EXAMPLES
3163  
3164 =head2 vertically-aligned CSS
3165  
3166 The distribution directory C<examples/vertically-aligned> contains a form with
3167 example CSS for a "vertically aligned" theme.
3168  
3169 This can be viewed by opening the file C<vertically-aligned.html> in a
3170 web-browser.
3171  
3172 If you wish to experiment with making changes, the form is defined in file
3173 C<vertically-aligned.yml>, and the HTML file can be updated with any changes
3174 by running the following command (while in the distribution root directory).
3175  
3176 perl examples/vertically-aligned/vertically-aligned.pl
3177  
3178 This uses the L<Template Toolkit|Template> file C<vertically-aligned.tt>,
3179 and the CSS is defined in files C<vertically-aligned.css> and
3180 C<vertically-aligned-ie.css>.
3181  
3182 =head1 SUPPORT
3183  
3184 Project Page:
3185  
3186 L<http://code.google.com/p/html-formfu/>
3187  
3188 Mailing list:
3189  
3190 L<http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu>
3191  
3192 Mailing list archives:
3193  
3194 L<http://lists.scsys.co.uk/pipermail/html-formfu/>
3195  
3196 IRC:
3197  
3198 C<irc.perl.org>, channel C<#formfu>
3199  
3200 The HTML::Widget archives L<http://lists.scsys.co.uk/pipermail/html-widget/>
3201 between January and May 2007 also contain discussion regarding HTML::FormFu.
3202  
3203 =head1 BUGS
3204  
3205 Please submit bugs / feature requests to
3206 L<https://github.com/FormFu/HTML-FormFu/issues> (preferred) or
3207 L<http://rt.perl.org>.
3208  
3209 =head1 PATCHES
3210  
3211 To help patches be applied quickly, please send them to the mailing list;
3212 attached, rather than inline; against subversion, rather than a cpan version
3213 (run C<< svn diff > patchfile >>); mention which svn version it's against.
3214 Mailing list messages are limited to 256KB, so gzip the patch if necessary.
3215  
3216 =head1 GITHUB REPOSITORY
3217  
3218 This module's sourcecode is maintained in a git repository at
3219 L<git://github.com/FormFu/HTML-FormFu.git>
3220  
3221 The project page is L<https://github.com/FormFu/HTML-FormFu>
3222  
3223 =head1 SEE ALSO
3224  
3225 L<HTML::FormFu::Imager>
3226  
3227 L<Catalyst::Controller::HTML::FormFu>
3228  
3229 L<HTML::FormFu::Model::DBIC>
3230  
3231 =head1 CONTRIBUTORS
3232  
3233 Brian Cassidy
3234  
3235 Ozum Eldogan
3236  
3237 Ruben Fonseca
3238  
3239 Ronald Kimball
3240  
3241 Daisuke Maki
3242  
3243 Andreas Marienborg
3244  
3245 Mario Minati
3246  
3247 Steve Nolte
3248  
3249 Moritz Onken
3250  
3251 Doug Orleans
3252  
3253 Matthias Dietrich
3254  
3255 Dean Hamstead
3256  
3257 Karen Etheridge
3258  
3259 Nigel Metheringham
3260  
3261 Based on the original source code of L<HTML::Widget>, by Sebastian Riedel,
3262 C<sri@oook.de>.
3263  
3264 =head1 AUTHOR
3265  
3266 Carl Franks <cpan@fireartist.com>
3267  
3268 =head1 COPYRIGHT AND LICENSE
3269  
3270 This software is copyright (c) 2018 by Carl Franks.
3271  
3272 This is free software; you can redistribute it and/or modify it under
3273 the same terms as the Perl 5 programming language system itself.
3274  
3275 =cut
« lib/HTML/FormFu/Role/FormAndBlockMethods.pm ↑ Summary lib/HTML/FormFu/Util.pm »