Instrumented/Context.pm

filter: Statementstmt 16.1% 16 / 99 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 41.6% 5 / 12 Podpod 100% 7 / 7 totaltotal 13.2% 28 / 211 CC 37 SCAR 46.4
CC
37
Cov
9%
get_id
206.9
get_form
132.0
copy
30.0
CRAP 103.2
« Instrumented/Entry.pm ↑ Summary Instrumented/Form/Checkbox.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package
5 XHTML::Instrumented::Context;
6  
7 4 ▶use Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new
10 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
11 0 my $class = shift;
12  
13 0 my %p = Params::Validate::validate( @_, {
14 args => 0,
15 data => 0,
16 flags => 0,
17 special => 0,
18 loop => 0,
19 start => 0,
20 hash => 1,
21 }
22 );
23 0 bless({ %p }, $class);
24 }
25  
26 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 sub copy
28 0 ▶{
Subroutine copy: not called CC=5 SCAR=34.0
Pod documented
29 0 my $self = shift;
30  
31 0 my %p = Params::Validate::validate( @_, {
32 merge => 0,
33 form => 0,
34 loop => 0,
35 count => 0,
36 }
37 );
38 0 ▶ if ($p{form}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"form"}) 0 0 0
39 #die 'form ', Dumper $p{form};
40 }
41 0 ▶ if ($p{merge}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"merge"}) 0 0 0
42 0 my $merge = $p{merge};
43 0 die 'merge';
44 0 delete $p{merge};
45 0 $p{hash} = { %{$self->{hash}}, %$merge };
46 }
47 0 my $loop = $self->{loop};
48  
49 0 my $copy = bless({ %$self, %p }, ref($self));
50  
51 0 ▶ if ($loop && ($loop ne $copy->{loop})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop and $loop ne $copy->{"loop"}) 0 0 0
Condition0%0/3
$loop and $loop ne $copy->{"loop"}
!ll&&!rl&&r
000
MC/DC0%0/2
$loop and $loop ne $copy->{"loop"}
$loop $loop ne $copy->{"loop"}
Truth table0%0/3
A and B
A= $loopB= $loop ne $copy->{"loop"}
ABresult
0X0
100
111
52 0 push(@{$copy->{loops}}, $loop);
53 0 $copy->{_xcount} = $loop->count + 1;
54 }
55  
56 0 $copy;
57 }
58  
59 sub get_form
60 0 ▶{
Subroutine get_form: not called CC=11 SCAR=48.8
Pod documented
61 0 my $self = shift;
62 0 my $id = shift;
63 0 my $ret;
64  
65 0 ▶ if (my $loop = $self->{loop}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $loop = $self->{"loop"}) 0 0 0
66 0 ▶ if ($loop->get_id($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop->get_id($id)) 0 0 0
67 0 $ret = $loop->get_id($id)->_control;
68 0 ▶ if (my $count = $self->{count} && $ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $count = $self->{"count"} && $ret) 0 0 0
Condition0%0/3
$self->{'count'} && $ret
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'count'} && $ret
$self->{'count'} $ret
Truth table0%0/3
A && B
A= $self->{'count'}B= $ret
ABresult
0X0
100
111
69 0 $ret->set_id_count($count);
70 }
71 }
72 }
73 0 ▶ if (!$ret) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret) 0 0 0
74 0 ▶ if (UNIVERSAL::isa($self->{hash}{$id}, 'XHTML::Instrumented::Form')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($self->{'hash'}{$id}, 'XHTML::Instrumented::Form')) { } 0 0 0
75 0 $ret = $self->{hash}{$id}->_control;
76 0 ▶ if (my $count = $self->{count} && $ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $count = $self->{"count"} && $ret) 0 0 0
Condition0%0/3
$self->{'count'} && $ret
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'count'} && $ret
$self->{'count'} $ret
Truth table0%0/3
A && B
A= $self->{'count'}B= $ret
ABresult
0X0
100
111
77 0 $ret->set_id_count($count);
78 }
79 } else {
80 0 warn $id, ' is not a form';
81 }
82 }
83 0 ▶ if ($ret && !$ret->is_form) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret and not $ret->is_form) 0 0 0
Condition0%0/3
$ret and not $ret->is_form
!ll&&!rl&&r
000
MC/DC0%0/2
$ret and not $ret->is_form
$ret not $ret->is_form
Truth table0%0/3
A and not(B)
A= $retB= not $ret->is_form
ABresult
0X0
100
111
84 0 warn $id, ' is not a form';
85 }
86  
87 0 return $ret;
88 }
89  
90 sub get_name
91 0 ▶{
Subroutine get_name: not called CC=5 SCAR=34.0
Pod documented
92 0 my $self = shift;
93 0 my $name = shift;
94 0 my $control = shift;
95 0 my $ret;
96  
97 0 ▶ if (my $form = $self->{form}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $form = $self->{'form'}) { } 0 0 0
98 0 $ret = $form->get_element($name);
99 } else {
100 # this in normal
101 }
102  
103 0 ▶ if ($ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) 0 0 0
104 0 $ret->{control} = $control;
105 0 ▶ if ($self->{loop}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"loop"}) 0 0 0
106 0 $self->set_count($ret);
107 }
108 }
109  
110 0 ▶ $ret || $control;
Branch: 1 branch
BranchTrueFalseTotal
$ret or $control 0 0 0
111 }
112  
113 sub set_count
114 0 ▶{
Subroutine set_count: not called CC=4 SCAR=30.0
Pod documented
115 0 my $self = shift;
116 0 my $ret = shift;
117  
118 0 ▶ die caller unless $self->{loop};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"loop"} 0 0 0
119 0 ▶ die caller unless $ret->isa('XHTML::Instrumented::Control');
Branch: 1 branch
BranchTrueFalseTotal
unless $ret->isa("XHTML::Instrumented::Control") 0 0 0
120  
121 0 my $cnt = $self->{loop}->count + 1;
122  
123 0 ▶ if (my $x = $self->{_xcount}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"_xcount"}) 0 0 0
124 0 $cnt = $x . '.' . $cnt;
125 }
126  
127 0 $ret->set_id_count( $cnt );
128 }
129  
130 sub get_id
131 0 ▶{
Subroutine get_id: not called CC=15 SCAR=53.3
Pod documented
132 0 my $self = shift;
133 0 my $id = shift;
134  
135 0 my $ret;
136  
137 0 ▶ if (my $loop = $self->{loop}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $loop = $self->{'loop'}) { } 0 0 0
elsif (my $form = $self->{'form'}) { } 0 0 0
138 0 $ret = $loop->get_id($id);
139  
140 0 ▶ if (ref($ret)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ret) 0 0 0
141 0 ▶ if (my $name = $ret->{args}{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $ret->{"args"}{"name"}) 0 0 0
142 0 $self->{name} = $name;
143 }
144 }
145 } elsif (my $form = $self->{form}) {
146 0 my $name = $form->{_ids_}{$id};
147 0 my $tmp = $self->{hash}{$id};
148 0 ▶ $ret = $form->get_element($name) if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 0 0
149 0 ▶ if ($ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) { } 0 0 0
150 0 ▶ if ($tmp && $tmp != $ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp and $tmp != $ret) 0 0 0
Condition0%0/3
$tmp and $tmp != $ret
!ll&&!rl&&r
000
MC/DC0%0/2
$tmp and $tmp != $ret
$tmp $tmp != $ret
Truth table0%0/3
A and B
A= $tmpB= $tmp != $ret
ABresult
0X0
100
111
151 0 die "$tmp $ret";
152 }
153 } else {
154 0 $ret = $tmp;
155 }
156 } else {
157 0 $ret = $self->{hash}{$id};
158 }
159 0 ▶ if (defined($ret)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ret) 0 0 0
160 0 ▶ if (!ref($ret)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $ret) 0 0 0
161 0 $ret = XHTML::Instrumented::Control->new(text => $ret);
162 }
163 }
164 0 ▶ $ret ||= XHTML::Instrumented::Control::Dummy->new();
Condition0%0/3
$ret ||= "XHTML::Instrumented::Control::Dummy"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$ret ||= "XHTML::Instrumented::Control::Dummy"->new
$ret "XHTML::Instrumented::Control::Dummy"->new
Truth table0%0/3
A ||= B
A= $retB= "XHTML::Instrumented::Control::Dummy"->new
ABresult
1X1
011
000
165  
166 0 ▶ if ($self->{loop} && $ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"loop"} and $ret) 0 0 0
Condition0%0/3
$self->{"loop"} and $ret
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"loop"} and $ret
$self->{"loop"} $ret
Truth table0%0/3
A and B
A= $self->{"loop"}B= $ret
ABresult
0X0
100
111
167 0 $self->set_count($ret);
168 }
169 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
170 0 ▶die "bad control ($id)" . Dumper $self unless UNIVERSAL::isa($ret, 'XHTML::Instrumented::Control');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($ret, "XHTML::Instrumented::Control") 0 0 0
171  
172 0 return $ret;
173 }
174  
175 sub inc_loop
176 0 ▶{
Subroutine inc_loop: not called CC=2 SCAR=17.9
Pod documented
177 0 my $self = shift;
178  
179 0 ▶ if (my $loop = $self->{loop}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $loop = $self->{'loop'}) { } 0 0 0
180 0 $loop->inc;
181 } else {
182 0 warn 'Not in loop';
183 }
184 }
185  
186 4 1;
187 __END__
« Instrumented/Entry.pm ↑ Summary Instrumented/Form/Checkbox.pm »