Plugin/Multiselect.pm

filter: Statementstmt 100% 39 / 39 Branchbran 93.7% 15 / 16 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 93.5% 73 / 78 CC 12 SCAR 13.4
CC
12
Cov
95%
validate_value
6.0
make_option
5.1
multiselect
3.0
CRAP 3.8
« Plugin.pm ↑ Summary Plugin/Image.pm »
1 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package HTML::Widget::Plugin::Multiselect;
4 # ABSTRACT: widget for multiple selections from a list
5 15 $HTML::Widget::Plugin::Multiselect::VERSION = '0.204';
6 15 ▶use parent 'HTML::Widget::Plugin::Select';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #pod =head1 SYNOPSIS
9 #pod
10 #pod $widget_factory->multiselect({
11 #pod id => 'multiopts', # if no name attr given, defaults to id value
12 #pod size => 3,
13 #pod values => [ 'value_1', 'value_3' ],
14 #pod options => [
15 #pod [ value_1 => 'Display Name 1' ],
16 #pod [ value_2 => 'Display Name 2' ],
17 #pod [ value_3 => 'Display Name 3' ],
18 #pod ],
19 #pod });
20 #pod
21 #pod =head1 DESCRIPTION
22 #pod
23 #pod This plugin provides a select-from-list widget that allows the selection of
24 #pod multiple elements.
25 #pod
26 #pod =cut
27  
28 15 ▶use HTML::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 #pod =head1 METHODS
31 #pod
32 #pod =head2 C< provided_widgets >
33 #pod
34 #pod This plugin provides the following widgets: multiselect
35 #pod
36 #pod =cut
37  
38 16 ▶sub provided_widgets { qw(multiselect) }
Subroutine provided_widgets: called CC=1 SCAR=0.0
Pod documented
39  
40 #pod =head2 C< multiselect >
41 #pod
42 #pod This method returns a multiple-selection-from-list widget. Yup.
43 #pod
44 #pod In addition to the generic L<HTML::Widget::Plugin> attributes and the
45 #pod L<HTML::Widget::Plugin::Select> attributes, the following are valid arguments:
46 #pod
47 #pod =over
48 #pod
49 #pod =item size
50 #pod
51 #pod This is the number of elements that should be visible in the widget.
52 #pod
53 #pod =back
54 #pod
55 #pod =cut
56  
57 16 ▶sub _attribute_args { qw(size) }
Subroutine _attribute_args: called CC=1 SCAR=0.0
58  
59 4 ▶sub multiselect {
Subroutine multiselect: called CC=3 SCAR=11.0
Pod documented
60 4 my ($self, $factory, $arg) = @_;
61  
62 4 ▶ $arg->{attr}{name} = $arg->{attr}{id} if not defined $arg->{attr}{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg->{"attr"}{"name"} 2 2 4
63 4 $arg->{attr}{multiple} = 'multiple';
64  
65 4 ▶ if ($arg->{values}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{"values"}) 1 3 4
66 1 $arg->{value} = delete $arg->{values};
67 }
68  
69 4 $self->build($factory, $arg);
70 }
71  
72 #pod =head2 C< make_option >
73 #pod
74 #pod This method, subclassed from the standard select widget, expects that C<$value>
75 #pod will be an array of selected values.
76 #pod
77 #pod =cut
78  
79 12 ▶sub make_option {
Subroutine make_option: called CC=5 SCAR=16.3
Pod documented
80 12 my ($self, $factory, $value, $name, $arg, $opt_arg) = @_;
81  
82 12 my $option = HTML::Element->new('option', value => $value);
83 12 $option->push_content($name);
84 12 ▶ $option->attr(disabled => 'disabled') if $opt_arg && $opt_arg->{disabled};
Branch: 1 branch
BranchTrueFalseTotal
if $opt_arg and $opt_arg->{"disabled"} 0 12 12
Condition33%1/3
$opt_arg and $opt_arg->{"disabled"}
!ll&&!rl&&r
1200
MC/DC0%0/2
$opt_arg and $opt_arg->{"disabled"}
$opt_arg $opt_arg->{"disabled"}
Truth table33%1/3
A and B
A= $opt_argB= $opt_arg->{"disabled"}
ABresult
0X0
100
111
85 $option->attr(selected => 'selected')
86 12 ▶ if $arg->{value} and grep { $_ eq $value } @{ $arg->{value} };
Branch: 1 branch
BranchTrueFalseTotal
if $arg->{"value"} and grep {$_ eq $value;} @{$$arg{"value"};} 4 8 12
Condition100%3/3
$arg->{"value"} and grep {$_ eq $value;} @{$$arg{"value"};}
!ll&&!rl&&r
444
MC/DC100%2/2
$arg->{"value"} and grep {$_ eq $value;} @{$$arg{"value"};}
$arg->{"value"} grep {$_ eq $value;} @{$$arg{"value"};}
Truth table100%3/3
A and B
A= $arg->{"value"}B= grep {$_ eq $value;} @{$$arg{"value"};}
ABresult
0X0
100
111
87  
88 12 return $option;
89 }
90  
91 #pod =head2 C< validate_value >
92 #pod
93 #pod This method checks whether the given value option is valid. It throws an
94 #pod exception if the given values are not all in the list of options.
95 #pod
96 #pod =cut
97  
98 4 ▶sub validate_value {
Subroutine validate_value: called CC=6 SCAR=17.9
Pod documented
99 4 my ($class, $values, $options) = @_;
100  
101 4 ▶ $values = [ $values ] unless ref $values;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $values 1 3 4
102 4 ▶ return unless grep { defined } @$values;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {defined $_;} @$values 1 3 4
103  
104 3 for my $value (@$values) {
105 6 ▶ my $matches = grep { $value eq $_ } map { ref $_ ? $_->[0] : $_ } @$options;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 8 16 24
106 6 ▶ Carp::croak "provided value '$value' not in given options" unless $matches;
Branch: 1 branch
BranchTrueFalseTotal
unless $matches 1 5 6
107 }
108 }
109  
110 15 1;
111  
112 __END__
« Plugin.pm ↑ Summary Plugin/Image.pm »