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.40067';
4 18     18   13074 use Moose;
  18         25  
  18         132  
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 71 my ( $self, $options ) = @_;
14              
15 44 100 66     299 return $options unless scalar @$options && defined $self->value;
16 40         136 my $value = $self->deflate($self->value);
17 40 100       161 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         13 my %selected = map { $_ => 1 } @$value;
  7         31  
21 6         11 my @out = grep { $selected{ $_->{value} } } @$options;
  17         29  
22 6         11 push @out, grep { !$selected{ $_->{value} } } @$options;
  17         25  
23 6         20 return \@out;
24             }
25              
26             __PACKAGE__->meta->make_immutable;
27 18     18   83966 use namespace::autoclean;
  18         35  
  18         160  
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.40067
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) 2016 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