File Coverage

blib/lib/Data/MuForm/Field/Multiple.pm
Criterion Covered Total %
statement 3 15 20.0
branch 0 4 0.0
condition 0 3 0.0
subroutine 1 3 33.3
pod 0 2 0.0
total 4 27 14.8


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