lib/HTML/FormFu/Filter/CompoundSprintf.pm

filter: Statementstmt 100% 28 / 28 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 84.0% 37 / 44 SCAR 13.9
CC
4
Cov
89%
filter
4.4
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« lib/HTML/FormFu/Constraint/AutoSet.pm ↑ Summary lib/HTML/FormFu/Constraint/File.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Filter::CompoundSprintf;
4 3 $HTML::FormFu::Filter::CompoundSprintf::VERSION = '2.06';
5 # ABSTRACT: CompoundSprintf filter
6  
7 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 extends 'HTML::FormFu::Filter';
10  
11 3 with 'HTML::FormFu::Role::Filter::Compound';
12  
13 3 ▶use HTML::FormFu::Constants qw( $EMPTY_STR );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 has sprintf => ( is => 'rw', traits => ['Chained'] );
17  
18 sub filter {
19 2 ▶ my ( $self, $value ) = @_;
Subroutine filter: called CC=4 SCAR=14.8
Pod undocumented
20  
21 2 ▶ return if !defined $value || $value eq $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or $value eq $HTML::FormFu::Filter::CompoundSprintf::EMPTY_STR 0 2 2
Condition33%1/3
not defined $value or $value eq $HTML::FormFu::Filter::CompoundSprintf::EMPTY_STR
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $value or $value eq $HTML::FormFu::Filter::CompoundSprintf::EMPTY_STR
not defined $value $value eq $HTML::FormFu::Filter::CompoundSprintf::EMPTY_STR
Truth table33%1/3
not(A) or B
A= not defined $valueB= $value eq $HTML::FormFu::Filter::CompoundSprintf::EMPTY_STR
ABresult
1X1
011
000
22  
23 2 my $sprintf = $self->sprintf;
24  
25 2 ▶ croak 'sprintf pattern required' if !defined $sprintf;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sprintf 0 2 2
26  
27 2 my @values = $self->_get_values($value);
28  
29 2 $value = CORE::sprintf( $sprintf, @values );
30  
31 2 return $value;
32 }
33  
34 3 __PACKAGE__->meta->make_immutable;
35  
36 3 1;
37  
38 __END__
39  
40 =pod
41  
42 =encoding UTF-8
43  
44 =head1 NAME
45  
46 HTML::FormFu::Filter::CompoundSprintf - CompoundSprintf filter
47  
48 =head1 VERSION
49  
50 version 2.06
51  
52 =head1 SYNOPSIS
53  
54 ---
55 element:
56 - type: Multi
57 name: date
58  
59 elements:
60 - name: day
61 - name: month
62 - name: year
63  
64 filter:
65 - type: CompoundSprintf
66 sprintf: '%02d-%02d-%04d'
67  
68 # get the compound-value
69  
70 my $date = $form->param_value('date');
71  
72 =head1 DESCRIPTION
73  
74 For use with a L<HTML::FormFu::Element::Multi> group of fields.
75  
76 Uses a sprintf pattern to join the input from several fields into a single
77 value.
78  
79 =head1 METHODS
80  
81 =head2 sprintf
82  
83 Arguments: $string
84  
85 C<sprintf> pattern used to join the individually submitted parts.
86 The pattern is passed to the perl-core C<sprintf> function.
87  
88 =head2 field_order
89  
90 Inherited. See L<HTML::FormFu::Filter::_Compound/field_order> for details.
91  
92 ---
93 element:
94 - type: Multi
95 name: date
96  
97 elements:
98 - name: month
99 - name: day
100 - name year
101  
102 filter:
103 - type: CompoundSprintf
104 field_order:
105 - day
106 - month
107 - year
108  
109 =head1 AUTHOR
110  
111 Carl Franks, C<cfranks@cpan.org>
112  
113 =head1 LICENSE
114  
115 This library is free software, you can redistribute it and/or modify it under
116 the same terms as Perl itself.
117  
118 =head1 AUTHOR
119  
120 Carl Franks <cpan@fireartist.com>
121  
122 =head1 COPYRIGHT AND LICENSE
123  
124 This software is copyright (c) 2018 by Carl Franks.
125  
126 This is free software; you can redistribute it and/or modify it under
127 the same terms as the Perl 5 programming language system itself.
128  
129 =cut
« lib/HTML/FormFu/Constraint/AutoSet.pm ↑ Summary lib/HTML/FormFu/Constraint/File.pm »