lib/HTML/FormFu/Filter/ForceListValue.pm

filter: Statementstmt 100% 14 / 14 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 0.0% 0 / 1 totaltotal 95.0% 19 / 20 SCAR 6.9
CC
2
Cov
100%
process
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« lib/HTML/FormFu/Role/HasParent.pm ↑ Summary lib/HTML/FormFu/Constraint/Required.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Filter::ForceListValue;
4 2 $HTML::FormFu::Filter::ForceListValue::VERSION = '2.06';
5 # ABSTRACT: convert a single value into a 1-item-list
6  
7 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 extends 'HTML::FormFu::Filter';
9  
10 sub process {
11 3 ▶ my ( $self, $result, $params ) = @_;
Subroutine process: called CC=2 SCAR=6.9
Pod undocumented
12  
13 3 my $name = $self->nested_name;
14 3 my $value = $self->get_nested_hash_value( $params, $name );
15  
16 3 ▶ return if 'ARRAY' eq ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if "ARRAY" eq ref $value 1 2 3
17  
18 2 $self->set_nested_hash_value( $params, $name, [$value] );
19 }
20  
21 2 1;
22  
23 __END__
24  
25 =pod
26  
27 =encoding UTF-8
28  
29 =head1 NAME
30  
31 HTML::FormFu::Filter::ForceListValue - convert a single value into a 1-item-list
32  
33 =head1 VERSION
34  
35 version 2.06
36  
37 =head1 SYNOPSIS
38  
39 element:
40 - type: Repeatable
41 increment_field_names: 0
42 elements:
43 - name: foo
44 render_processed_value: 1
45 filter:
46 - ForceListValue
47  
48 =head1 DESCRIPTION
49  
50 Causes a single submitted value to be changed to a list containing 1 item.
51  
52 Solves an uncommon problem with a
53 L<Repeatable block|HTML::FormFu::Element::Repeatable> with
54 L<increment_field_names|HTML::FormFu::Element::Repeatable/increment_field_names>
55 disabled, when manually increasing the
56 L<repeat|HTML::FormFu::Element::Repeatable/repeat> count after the form was
57 submitted with only a single value for each of the Repeatable's fields.
58  
59 If these circumstances, when rendered, every repeated field would have the
60 initially-submitted value as its default.
61  
62 Using this filter, and setting
63 L<render_processed_value|HTML::FormFu/render_processed_value> to C<true> will
64 ensure that only the first repetition of each field will have the submitted
65 value as its default; all subsequent repetitions will have no default value.
66  
67 =head1 AUTHOR
68  
69 Carl Franks
70  
71 =head1 LICENSE
72  
73 This library is free software, you can redistribute it and/or modify it under
74 the same terms as Perl itself.
75  
76 =head1 AUTHOR
77  
78 Carl Franks <cpan@fireartist.com>
79  
80 =head1 COPYRIGHT AND LICENSE
81  
82 This software is copyright (c) 2018 by Carl Franks.
83  
84 This is free software; you can redistribute it and/or modify it under
85 the same terms as the Perl 5 programming language system itself.
86  
87 =cut
« lib/HTML/FormFu/Role/HasParent.pm ↑ Summary lib/HTML/FormFu/Constraint/Required.pm »