File Coverage

blib/lib/HTML/FormHandler/Field/SelectCSV.pm
Criterion Covered Total %
statement 16 18 88.8
branch 3 6 50.0
condition n/a
subroutine 5 5 100.0
pod 1 4 25.0
total 25 33 75.7


line stmt bran cond sub pod time code
1             package HTML::FormHandler::Field::SelectCSV;
2             # ABSTRACT: Multiple select field from CSV value
3             $HTML::FormHandler::Field::SelectCSV::VERSION = '0.40067';
4 1     1   702 use HTML::FormHandler::Moose;
  1         1  
  1         8  
5             extends 'HTML::FormHandler::Field::Select';
6              
7              
8             has '+inflate_default_method' => ( default => sub { \&selectcsv_inflate_default } );
9             has '+deflate_value_method' => ( default => sub { \&selectcsv_deflate_value } );
10             has '+multiple' => ( default => 1 );
11 1     1 0 32 sub build_value_when_empty { undef }
12              
13             sub selectcsv_inflate_default {
14 3     3 0 5 my ( $self, $value ) = @_;
15 3 50       8 if( defined $value ) {
16 3         15 my @values = split (/,/, $value);
17 3         13 return @values;
18             }
19 0         0 return;
20             }
21              
22             sub selectcsv_deflate_value {
23 1     1 0 2 my ( $self, $value ) = @_;
24 1 50       4 if ( defined $value ) {
25 1         10 my $str = join( ',', sort @$value );
26 1         6 return $str;
27             }
28 0         0 return;
29             }
30              
31             sub fif {
32 12     12 1 16 my $self = shift;
33 12         44 my $fif = $self->next::method;
34 12 50       32 $fif = [] if $fif eq '';
35 12         28 return $fif;
36             }
37              
38             1;
39              
40             __END__
41              
42             =pod
43              
44             =encoding UTF-8
45              
46             =head1 NAME
47              
48             HTML::FormHandler::Field::SelectCSV - Multiple select field from CSV value
49              
50             =head1 VERSION
51              
52             version 0.40067
53              
54             =head1 SYNOPSIS
55              
56             A multiple select field for comma-separated values in the database.
57             It expects database values like: '1,5,7'. The string will be inflated
58             into an arrayref for validation and form filling, and will be deflated
59             into a comma-separated string in the output value.
60              
61             This field is useful for MySQL 'set' columns.
62              
63             =head1 NAME
64              
65             HTML::FormHandler::Field::SelectCSV
66              
67             =head1 AUTHOR
68              
69             FormHandler Contributors - see HTML::FormHandler
70              
71             =head1 COPYRIGHT AND LICENSE
72              
73             This software is copyright (c) 2016 by Gerda Shank.
74              
75             This is free software; you can redistribute it and/or modify it under
76             the same terms as the Perl 5 programming language system itself.
77              
78             =cut