Instrumented/Form/Checkbox.pm

filter: Statementstmt 13.0% 13 / 100 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 36.3% 4 / 11 Podpod 100% 7 / 7 totaltotal 12.7% 24 / 189 CC 35 SCAR 45.2
CC
35
Cov
8%
expand_content
156.0
args
132.0
set_default
56.0
CRAP 91.7
« Instrumented/Context.pm ↑ Summary Instrumented/Form/Select.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package
5 XHTML::Instrumented::Form::Checkbox;
6  
7 2 ▶use base 'XHTML::Instrumented::Form::Select';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Params::Validate qw (validate);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub new
12 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
13 0 my $class = shift;
14 0 my %p = validate(@_, {
15 name => 1,
16 type => 1,
17 value => 0,
18 required => 0,
19 default => 0,
20 values => 0,
21 data => 0,
22 });
23  
24 0 my $data = $p{data};
25 0 delete $p{data};
26  
27 0 my $self = bless({ %p }, $class);
28  
29 0 ▶ $self->set_select_data(@{$data}) if $data;
Branch: 1 branch
BranchTrueFalseTotal
if $data 0 0 0
30  
31 0 $self;
32 }
33  
34 sub args
35 0 ▶{
Subroutine args: not called CC=11 SCAR=48.8
Pod documented
36 0 my $self = shift;
37 0 my %hash = @_;
38  
39 0 ▶ if ($self->{type} eq 'select') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'type'} eq 'select') { } 0 0 0
40 } else {
41 0 ▶ if (my $count = $self->{id_count}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $count = $self->{'id_count'}) { } 0 0 0
42 0 ▶ if (my $value = $self->{control}->{args}->{value}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $value = $self->{'control'}{'args'}{'value'}) { } 0 0 0
elsif ($self->{'values'}) { } 0 0 0
43  
44 0 $hash{value} = $value;
45 } elsif ($self->{values}) {
46 0 die 'bob';
47 } else {
48 0 $hash{value} = $count;
49 }
50 } else {
51 0 ▶ if (my $value = $hash{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = $hash{'value'}) { } 0 0 0
52 0 ▶ if ($self->{values}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"values"}) 0 0 0
53 0 ▶ if (grep /$value/, @{$self->{values}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /$value/, @{$$self{"values"};}) 0 0 0
54 0 $hash{checked} = 'checked';
55 }
56 }
57 0 ▶ if ($self->{default}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"default"}) 0 0 0
58 0 ▶ if (grep /$value/, @{$self->{default}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /$value/, @{$$self{"default"};}) 0 0 0
59 0 $hash{checked} = 'checked';
60 }
61 }
62 } else {
63 0 ▶ if (grep /on/, @{$self->{default}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /on/, @{$$self{"default"};}) 0 0 0
64 0 $hash{checked} = 'checked';
65 }
66 }
67 }
68 }
69 0 $self->SUPER::args(%hash);
70 }
71  
72 sub expand_content
73 0 ▶{
Subroutine expand_content: not called CC=12 SCAR=50.5
Pod documented
74 0 my $self = shift;
75  
76 0 ▶ my $value = $self->{value} || $self->{default};
Condition0%0/3
$self->{'value'} || $self->{'default'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'value'} || $self->{'default'}
$self->{'value'} $self->{'default'}
Truth table0%0/3
A || B
A= $self->{'value'}B= $self->{'default'}
ABresult
1X1
011
000
77 0 require XHTML::Instrumented::Entry;
78  
79 0 for my $option (@{$self->{data}}) {
80 0 ▶ if ($self->{value} && $option->{value}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"value"} and $option->{"value"} and $self->{"value"} eq $option->{"value"}) 0 0 0
Condition0%0/6
$self->{"value"} and $option->{"value"} and $self->{"value"} eq $option->{"value"}
!ll&&!rl&&r
000
$self->{"value"} and $option->{"value"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"value"} and $option->{"value"} and $self->{"value"} eq $option->{"value"}
$self->{"value"} $option->{"value"} $self->{"value"} eq $option->{"value"}
Truth table0%0/4
A and B and C
A= $self->{"value"}B= $option->{"value"}C= $self->{"value"} eq $option->{"value"}
ABCresult
0XX0
10X0
1100
1111
81 && $self->{value} eq $option->{value}) {
82 0 $option->{selected} = 1;
83 }
84 }
85  
86 0 my %values = map({ ($_ => 1); } @{$value});
87  
88 0 my @ret = ();
89 0 ▶ if ($self->{tag} eq 'select') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tag"} eq "select") 0 0 0
90 0 ▶ if (@{$self->{data}||[]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'data'} or [];}) { } 0 0 0
Condition0%0/2
$self->{'data'} || []
l!l
00
MC/DC0%0/1
$self->{'data'} || []
$self->{'data'}
Truth table0%0/2
A
A= $self->{'data'}
Aresult
11
00
91 @ret = map({ XHTML::Instrumented::Entry->new(
92 tag => 'option',
93 flags => {},
94 args => { $_->as_args },
95 0 data => [ $_->{text} ],
96 ),
97 0 } @{$self->{data}}
98 );
99 } else {
100 0 for my $entry (@_) {
101 0 ▶ if (ref($entry)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $entry) 0 0 0
102 0 my $entry_value = $entry->{args}{value};
103  
104 0 ▶ if ($values{$entry_value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($values{$entry_value}) 0 0 0
105 0 $entry->{args}{selected} = 'selected';
106 }
107 0 push(@ret, $entry);
108 }
109 }
110 }
111 }
112  
113 0 @ret;
114 }
115  
116 sub is_multi
117 0 ▶{
Subroutine is_multi: not called CC=1 SCAR=6.9
Pod documented
118 0 1;
119 }
120  
121 sub checked
122 0 ▶{
Subroutine checked: not called CC=1 SCAR=6.9
Pod documented
123 0 my $self = shift;
124 0 die qq(fixme check boxes don't work.);
125 0 0;
126 }
127  
128 sub set_default
129 0 ▶{
Subroutine set_default: not called CC=7 SCAR=40.3
Pod documented
130 0 my $self = shift;
131 0 my $value = shift;
132 0 ▶ die if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
133  
134 0 ▶ if (my $type = ref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = ref $value) { } 0 0 0
135 0 ▶ die unless $type eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "ARRAY" 0 0 0
136 0 $self->{default} = $value;
137 } else {
138 0 $self->{default} = [ $value ];
139 }
140  
141 0 my %values = map({ ($_ => 1); } @{$self->{default}});
142  
143 0 ▶ for my $element (@{$self->{data} || []}) {
Condition0%0/2
$self->{'data'} || []
l!l
00
MC/DC0%0/1
$self->{'data'} || []
$self->{'data'}
Truth table0%0/2
A
A= $self->{'data'}
Aresult
11
00
144 0 delete $element->{selected};
145 0 ▶ if ($values{$element->value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($values{$element->value}) 0 0 0
146 0 $element->{selected} = 1;
147 }
148 }
149 }
150  
151 sub set_value
152 0 ▶{
Subroutine set_value: not called CC=7 SCAR=40.3
Pod documented
153 0 my $self = shift;
154 0 my $value = shift;
155 0 ▶ die if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
156  
157 0 ▶ if (my $type = ref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = ref $value) { } 0 0 0
158 0 ▶ die unless $type eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "ARRAY" 0 0 0
159 0 $self->{value} = $value;
160 } else {
161 0 $self->{value} = [ $value ];
162 }
163  
164 0 my %values = map({ ($_ => 1); } @{$self->{value}});
165  
166 0 ▶ for my $element (@{$self->{data} || []}) {
Condition0%0/2
$self->{'data'} || []
l!l
00
MC/DC0%0/1
$self->{'data'} || []
$self->{'data'}
Truth table0%0/2
A
A= $self->{'data'}
Aresult
11
00
167 0 delete $element->{selected};
168 0 ▶ if ($values{$element->value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($values{$element->value}) 0 0 0
169 0 $element->{selected} = 1;
170 }
171 }
172 }
173  
174 2 1;
175 __END__
« Instrumented/Context.pm ↑ Summary Instrumented/Form/Select.pm »