MuForm/Field/Multiple.pm

filter: Statementstmt 36.8% 7 / 19 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 1 / 3 Podpod 0.0% 0 / 2 totaltotal 24.2% 8 / 33 SCAR 23.3
CC
4
Cov
27%
default_sort_options
20.0
build_base_methods
2.0
BEGIN
1.0
CRAP 10.2
« MuForm/Field/Integer.pm ↑ Summary MuForm/Model/Object.pm »
1 package Data::MuForm::Field::Multiple;
2 # ABSTRACT: multiple select list
3 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 extends 'Data::MuForm::Field::Select';
5 5 our $VERSION = '0.01';
6  
7  
8 5 has '+multiple' => ( default => 1 );
9 #has '+size' => ( default => 5 ); rendering info
10 # TODO: deal with setting methods in base field classes
11 0 ▶sub build_base_methods { { sort_options => \&default_sort_options } }
Subroutine build_base_methods: not called CC=1 SCAR=6.9
Pod undocumented
12  
13 sub default_sort_options {
14 0 ▶ my ( $self, $options ) = @_;
Subroutine default_sort_options: not called CC=4 SCAR=30.0
Pod undocumented
15  
16 0 ▶ return $options unless scalar @$options && defined $self->value;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$options and defined $self->value 0 0 0
Condition0%0/3
scalar @$options and defined $self->value
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$options and defined $self->value
scalar @$options defined $self->value
Truth table0%0/3
A and B
A= scalar @$optionsB= defined $self->value
ABresult
0X0
100
111
17 0 my $value = $self->deflate($self->value);
18 0 ▶ return $options unless scalar @$value;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$value 0 0 0
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;
22 0 my @out = grep { $selected{ $_->{value} } } @$options;
23 0 push @out, grep { !$selected{ $_->{value} } } @$options;
24 0 return \@out;
25 }
26  
27 5 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.04
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
« MuForm/Field/Integer.pm ↑ Summary MuForm/Model/Object.pm »