lib/HTML/FormFu/Filter/CopyValue.pm

filter: Statementstmt 100% 21 / 21 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 78.3% 29 / 37 SCAR 16.3
CC
5
Cov
83%
filter
5.9
BEGIN
1.0
BEGIN
1.0
CRAP 5.1
« lib/HTML/FormFu/Processor.pm ↑ Summary lib/HTML/FormFu/Filter/HTMLScrubber.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Filter::CopyValue;
4 2 $HTML::FormFu::Filter::CopyValue::VERSION = '2.06';
5 # ABSTRACT: copy the value from another field
6  
7 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 extends 'HTML::FormFu::Filter';
10  
11 2 with 'HTML::FormFu::Role::NestedHashUtils';
12  
13 2 has field => ( is => 'rw', traits => ['Chained'] );
14  
15 sub filter {
16 1 ▶ my ( $self, $value ) = @_;
Subroutine filter: called CC=5 SCAR=17.8
Pod undocumented
17  
18 1 ▶ return $value
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and length $value 0 1 1
Condition33%1/3
defined $value and length $value
!ll&&!rl&&r
100
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
19 if ( defined $value && length $value );
20  
21 1 ▶ my $field_name = $self->field
Branch: 1 branch
BranchTrueFalseTotal
my $field_name = $self->field or die "Parameter 'field' is not defined." 0 1 1
22 or die "Parameter 'field' is not defined.";
23  
24 1 ▶ my $parent = $self->parent
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->parent or die "Can't determine my parent." 0 1 1
25 or die "Can't determine my parent.";
26  
27 1 my $field_value
28 = $self->get_nested_hash_value( $parent->form->input, $field_name, );
29  
30 1 return $field_value;
31 }
32  
33 2 __PACKAGE__->meta->make_immutable;
34  
35 2 1;
36  
37 __END__
38  
39 =pod
40  
41 =encoding UTF-8
42  
43 =head1 NAME
44  
45 HTML::FormFu::Filter::CopyValue - copy the value from another field
46  
47 =head1 VERSION
48  
49 version 2.06
50  
51 =head1 SYNOPSIS
52  
53 elements:
54 - type: Text
55 name: username
56 - type: Text
57 name: nickname
58 filters:
59 - type: CopyValue
60 field: username
61  
62 =head1 DESCRIPTION
63  
64 Filter copying the value of another field if the original value of this field
65 is empty.
66  
67 =head1 CAVEATS
68  
69 If the original field contains an invalid value (a value that will be
70 constrained through a constraint) that invalid value will be copied to this
71 field (the field with the CopyValue filter). So, the user has to change two
72 fields, or you can remove the invalid value in a custom constraint.
73  
74 =head1 AUTHOR
75  
76 Mario Minati, C<mario.minati@googlemail.com>
77  
78 =head1 LICENSE
79  
80 This library is free software, you can redistribute it and/or modify it under
81 the same terms as Perl itself.
82  
83 =head1 AUTHOR
84  
85 Carl Franks <cpan@fireartist.com>
86  
87 =head1 COPYRIGHT AND LICENSE
88  
89 This software is copyright (c) 2018 by Carl Franks.
90  
91 This is free software; you can redistribute it and/or modify it under
92 the same terms as the Perl 5 programming language system itself.
93  
94 =cut
« lib/HTML/FormFu/Processor.pm ↑ Summary lib/HTML/FormFu/Filter/HTMLScrubber.pm »