File Coverage

blib/lib/HTML/FormHandler/Field/Multiple.pm
Criterion Covered Total %
statement 17 17 100.0
branch 4 4 100.0
condition 2 3 66.6
subroutine 3 3 100.0
pod 0 1 0.0
total 26 28 92.8


line stmt bran cond sub pod time code
1             package HTML::FormHandler::Field::Multiple;
2             # ABSTRACT: multiple select list
3             $HTML::FormHandler::Field::Multiple::VERSION = '0.40068';
4 18     18   15632 use Moose;
  18         43  
  18         158  
5             extends 'HTML::FormHandler::Field::Select';
6              
7              
8             has '+multiple' => ( default => 1 );
9             has '+size' => ( default => 5 );
10             has '+sort_options_method' => ( default => sub { \&default_sort_options } );
11              
12             sub default_sort_options {
13 44     44 0 138 my ( $self, $options ) = @_;
14              
15 44 100 66     377 return $options unless scalar @$options && defined $self->value;
16 40         179 my $value = $self->deflate($self->value);
17 40 100       204 return $options unless scalar @$value;
18             # This places the currently selected options at the top of the list
19             # Makes the drop down lists a bit nicer
20 6         19 my %selected = map { $_ => 1 } @$value;
  7         39  
21 6         20 my @out = grep { $selected{ $_->{value} } } @$options;
  17         51  
22 6         24 push @out, grep { !$selected{ $_->{value} } } @$options;
  17         46  
23 6         28 return \@out;
24             }
25              
26             __PACKAGE__->meta->make_immutable;
27 18     18   122550 use namespace::autoclean;
  18         49  
  18         191  
28             1;
29              
30             __END__
31              
32             =pod
33              
34             =encoding UTF-8
35              
36             =head1 NAME
37              
38             HTML::FormHandler::Field::Multiple - multiple select list
39              
40             =head1 VERSION
41              
42             version 0.40068
43              
44             =head1 DESCRIPTION
45              
46             This is a convenience field that inherits from the Select field and
47             pre-sets some attributes. It sets the 'multiple' flag,
48             sets the 'size' attribute to 5, and sets the 'sort_options_method' to
49             move the currently selected options to the top of the options list.
50              
51             =head1 AUTHOR
52              
53             FormHandler Contributors - see HTML::FormHandler
54              
55             =head1 COPYRIGHT AND LICENSE
56              
57             This software is copyright (c) 2017 by Gerda Shank.
58              
59             This is free software; you can redistribute it and/or modify it under
60             the same terms as the Perl 5 programming language system itself.
61              
62             =cut