FormHandler/Field/TextCSV.pm

filter: Statementstmt 83.3% 25 / 30 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 3 totaltotal 63.3% 38 / 60 CC 8 SCAR 11.9
CC
8
Cov
70%
textcsv_deflate
4.9
_inner_validate_field
3.6
textcsv_inflate
3.6
CRAP 3.3
« FormHandler/Widget/Field/Button.pm ↑ Summary FormHandler/TraitFor/I18N.pm »
1 package HTML::FormHandler::Field::TextCSV;
2 # ABSTRACT: CSV Text field from multiple
3 1 $HTML::FormHandler::Field::TextCSV::VERSION = '0.410000';
4 1 ▶use HTML::FormHandler::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 extends 'HTML::FormHandler::Field::Text';
6  
7  
8 2 ▶has '+deflate_method' => ( default => sub { \&textcsv_deflate } );
Subroutine __ANON__: called CC=1 SCAR=0.0
9 2 ▶has '+inflate_method' => ( default => sub { \&textcsv_inflate } );
Subroutine __ANON__: called CC=1 SCAR=0.0
10 1 has 'multiple' => ( isa => 'Bool', is => 'rw', default => '0' );
11 0 ▶sub build_value_when_empty { [] }
Subroutine build_value_when_empty: not called CC=1 SCAR=6.9
Pod undocumented
12 sub _inner_validate_field {
13 1 ▶ my $self = shift;
Subroutine _inner_validate_field: called CC=3 SCAR=12.7
14 1 my $value = $self->value;
15 1 ▶ return unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 1 1
16 1 ▶ if ( ref $value ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value ne "ARRAY") 0 1 1
17 0 $value = [$value];
18 0 $self->_set_value($value);
19 }
20 }
21  
22 sub textcsv_deflate {
23 6 ▶ my ( $self, $value ) = @_;
Subroutine textcsv_deflate: called CC=4 SCAR=15.9
Pod undocumented
24 6 ▶ if( defined $value && length $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and length $value) 6 0 6
Condition33%1/3
defined $value and length $value
!ll&&!rl&&r
006
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
25 6 ▶ my $value = ref $value eq 'ARRAY' ? $value : [$value];
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 6 0 6
26 6 my $new_value = join(',', @$value);
27 6 return $new_value;
28 }
29 0 return $value;
30 }
31  
32 sub textcsv_inflate {
33 1 ▶ my ( $self, $value ) = @_;
Subroutine textcsv_inflate: called CC=3 SCAR=12.7
Pod undocumented
34 1 ▶ if ( defined $value && length $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and length $value) 1 0 1
Condition33%1/3
defined $value and length $value
!ll&&!rl&&r
001
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
35 1 my @values = split(/,/, $value);
36 1 return \@values;
37 }
38 0 return $value;
39 }
40  
41 1 __PACKAGE__->meta->make_immutable;
42 1 1;
43  
44 __END__
45  
46 =pod
47  
48 =encoding UTF-8
49  
50 =head1 NAME
51  
52 HTML::FormHandler::Field::TextCSV - CSV Text field from multiple
53  
54 =head1 VERSION
55  
56 version 0.410000
57  
58 =head1 SYNOPSIS
59  
60 A text field that takes multiple values from a database and converts
61 them to comma-separated values. This is intended for javascript fields
62 that require that, such as 'select2'.
63  
64 =head1 NAME
65  
66 HTML::FormHandler::Field::TextCSV
67  
68 =head1 AUTHOR
69  
70 FormHandler Contributors - see HTML::FormHandler
71  
72 =head1 COPYRIGHT AND LICENSE
73  
74 This software is copyright (c) 2017 by Gerda Shank.
75  
76 This is free software; you can redistribute it and/or modify it under
77 the same terms as the Perl 5 programming language system itself.
78  
79 =cut
« FormHandler/Widget/Field/Button.pm ↑ Summary FormHandler/TraitFor/I18N.pm »