Instrumented/Loop.pm

filter: Statementstmt 13.9% 13 / 93 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 26.6% 4 / 15 Podpod 100% 10 / 10 totaltotal 17.8% 27 / 151 CC 18 SCAR 31.4
CC
18
Cov
10%
to_text
56.0
get_id
42.0
children
12.0
CRAP 23.1
« Instrumented/Control.pm ↑ Summary Instrumented/Form/ElementControl.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::Loop;
6  
7 2 ▶use base 'XHTML::Instrumented::Control';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Params::Validate qw (validate ARRAYREF HASHREF);
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 inclusive => 0,
16 headers => {
17 optional => 1,
18 type => ARRAYREF,
19 },
20 data => {
21 optional => 1,
22 type => ARRAYREF,
23 depends => [ 'headers' ],
24 },
25 default => 0,
26 } );
27 0 my $self = bless { headers => [], data => [], _count => 0, %p }, $class;
28  
29 0 ▶ for (my $x = 0; $x < @{$self->{headers}}; $x++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < @{$self->{"headers"};}) 0 0 0
30 0 $self->{hash}{ $self->{headers}[$x] } = $x;
31 }
32  
33 0 return $self;
34 }
35  
36 sub count
37 0 ▶{
Subroutine count: not called CC=1 SCAR=6.9
Pod documented
38 0 my $self = shift;
39 0 $self->{_count};
40 }
41  
42 sub inc
43 0 ▶{
Subroutine inc: not called CC=1 SCAR=6.9
Pod documented
44 0 my $self = shift;
45  
46 0 $self->{_count}++;
47 }
48  
49 sub _have_data
50 0 ▶{
Subroutine _have_data: not called CC=2 SCAR=17.9
51 0 my $self = shift;
52 0 my @data = @{$self->{data}};
53 0 ▶ if ($self->{_count} >= @data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_count'} >= @data) { } 0 0 0
54 0 $self->{_count} = 0;
55 0 return 0;
56 } else {
57 0 return 1;
58 }
59 }
60  
61 sub expand_content
62 0 ▶{
Subroutine expand_content: not called CC=1 SCAR=6.9
Pod documented
63 0 my $self = shift;
64  
65 0 my @ret = $self->SUPER::expand_content(@_);
66  
67 0 return @ret;
68 }
69  
70 sub get_id
71 0 ▶{
Subroutine get_id: not called CC=6 SCAR=37.4
Pod documented
72 0 my $self = shift;
73 0 my $id = shift;
74 0 my %hash;
75 0 my $x = 0;
76  
77 0 for my $h (@{$self->{headers}}) {
78 0 $hash{$h} = $x++;
79 }
80  
81 0 my $data;
82  
83 0 ▶ if (defined $hash{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash{$id}) 0 0 0
84 0 ▶ if ($self->{_count} >= @{$self->{data}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_count'} >= @{$self->{'data'};}) { } 0 0 0
85 0 ▶ if (ref $self->{default} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'default'} eq 'ARRAY') { } 0 0 0
86 0 $data = $self->{default}[$hash{$id}];
87 } else {
88 0 ▶ $data = $self->{default} || 'N/A';
Condition0%0/2
$self->{'default'} || 'N/A'
l!l
00
MC/DC0%0/1
$self->{'default'} || 'N/A'
$self->{'default'}
Truth table0%0/2
A
A= $self->{'default'}
Aresult
11
00
89 }
90 } else {
91 0 $data = $self->{data}[$self->{_count}][$hash{$id}];
92 }
93 }
94  
95 0 return $data;
96 }
97  
98 sub if
99 0 ▶{
Subroutine if: not called CC=2 SCAR=17.9
Pod documented
100 0 my $count = shift->rows;
101 0 ▶ $count ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$count ? : 0 0 0
102 }
103  
104 sub rows
105 0 ▶{
Subroutine rows: not called CC=1 SCAR=6.9
Pod documented
106 0 my $self = shift;
107 0 scalar @{$self->{data}};
108 }
109  
110 sub children
111 0 ▶{
Subroutine children: not called CC=3 SCAR=24.8
Pod documented
112 0 my $self = shift;
113  
114 0 my %p = validate(@_, {
115 context => { isa => 'XHTML::Instrumented::Context' },
116 children => ARRAYREF,
117 });
118  
119 0 my @ret;
120  
121 0 ▶ if ($self->inclusive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->inclusive) { } 0 0 0
122 0 my $context = $p{context}->copy;
123 0 @ret = ($self->SUPER::children(@_, context => $context));
124 } else {
125 0 ▶ while ($self->_have_data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_have_data) 0 0 0
126 0 my $context = $p{context}->copy;
127 0 push(@ret, $self->SUPER::children(%p, context => $context));
128 0 $self->inc;
129 }
130 }
131 0 return @ret;
132 }
133  
134 sub to_text
135 0 ▶{
Subroutine to_text: not called CC=7 SCAR=40.3
Pod documented
136 0 my $self = shift;
137 0 my %p = validate(@_, {
138 tag => 1,
139 children => ARRAYREF,
140 args => HASHREF,
141 flags => HASHREF,
142 context => { isa => 'XHTML::Instrumented::Context' },
143 });
144 0 my @ret;
145  
146 0 my $context = $p{context};
147  
148 # remove the entire loop element branch if no data
149 # TODO This may need an option
150  
151 0 my $count = $self->rows;
152  
153 0 ▶ die 'if in loop' if (!!$p{flags}->{if}); # A loop never has an if.
Branch: 1 branch
BranchTrueFalseTotal
unless not $p{"flags"}{"if"} 0 0 0
154  
155 0 my $inclusive = $self->inclusive;
156  
157 0 ▶ if ($p{flags}->{ex}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"flags"}{"ex"}) 0 0 0
158 0 $inclusive = 0;
159 }
160 0 ▶ if ($p{flags}->{in}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"flags"}{"in"}) 0 0 0
161 0 $inclusive = 1;
162 }
163  
164 0 ▶ if ($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) 0 0 0
165 0 ▶ if ($inclusive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inclusive) { } 0 0 0
166 0 my $s = $self->{inclusive};
167 0 $self->{inclusive} = $inclusive;
168  
169 0 my $x = 1;
170 0 ▶ while (my $q = $self->_have_data) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $q = $self->_have_data) 0 0 0
171 0 my $x = $context->copy(loop => $self);
172  
173 0 $x->set_count($self);
174 0 push @ret, $self->SUPER::to_text(%p, context => $x);
175 0 $self->inc;
176 }
177 0 $self->{inclusive} = $s;
178 } else {
179 0 my $x = $context->copy(loop => $self);
180  
181 0 push @ret, $self->SUPER::to_text(%p, context => $x);
182 }
183 }
184  
185 0 return @ret;
186 }
187  
188 sub inclusive
189 0 ▶{
Subroutine inclusive: not called CC=2 SCAR=17.9
Pod documented
190 0 my $self = shift;
191 0 ▶ $self->{inclusive} || 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"inclusive"} or 0 0 0 0
192 }
193  
194 2 1;
195 __END__
« Instrumented/Control.pm ↑ Summary Instrumented/Form/ElementControl.pm »