Template/Iterator.pm

filter: Statementstmt 15.7% 11 / 70 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 36.3% 4 / 11 Podpod 50.0% 3 / 6 totaltotal 12.5% 18 / 144 CC 24 SCAR 34.4
CC
24
Cov
9%
new
72.0
_do_globals
42.0
enter_scope
20.0
CRAP 31.1
« Template/Container/Worksheet.pm ↑ Summary Template/Factory.pm »
1 package Excel::Template::Iterator;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 BEGIN {
6 1 ▶ use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ @ISA = qw(Excel::Template::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶ use Excel::Template::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 }
11  
12 sub new
13 {
14 0 ▶ my $class = shift;
Subroutine new: not called CC=8 SCAR=42.8
Pod undocumented
15 0 my $self = $class->SUPER::new(@_);
16  
17 0 ▶ unless (Excel::Template::Factory::isa($self->{CONTEXT}, 'CONTEXT'))
Branch: 1 branch
BranchTrueFalseTotal
unless (Excel::Template::Factory::isa($self->{"CONTEXT"}, "CONTEXT")) 0 0 0
18 {
19 0 die "Internal Error: No context object passed to ", __PACKAGE__, $/;
20 }
21  
22 0 ▶ $self->{MAXITERS} ||= 0;
Condition0%0/2
$self->{"MAXITERS"} ||= 0
l!l
00
MC/DC0%0/1
$self->{"MAXITERS"} ||= 0
$self->{"MAXITERS"}
Truth table0%0/2
A
A= $self->{"MAXITERS"}
Aresult
11
00
23  
24 # This is the index we will work on NEXT, in whatever direction the
25 # iterator is going.
26 0 $self->{INDEX} = -1;
27  
28 # This is a short-circuit parameter to let the iterator function in a
29 # null state.
30 0 $self->{NO_PARAMS} = 0;
31 0 ▶ unless ($self->{NAME} =~ /\w/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"NAME"} =~ /\w/) 0 0 0
32 {
33 0 $self->{NO_PARAMS} = 1;
34  
35 0 ▶ warn "INTERNAL ERROR: 'NAME' was blank was blank when passed to ", __PACKAGE__, $/ if $^W;
Branch: 1 branch
BranchTrueFalseTotal
if $^W 0 0 0
36  
37 0 return $self;
38 }
39  
40 # Cache the reference to the appropriate data.
41 0 $self->{DATA} = $self->{CONTEXT}->param($self->{NAME});
42  
43 0 ▶ unless (ref $self->{DATA} eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->{"DATA"} eq "ARRAY") 0 0 0
44 {
45 0 $self->{NO_PARAMS} = 1;
46 0 ▶ warn "'$self->{NAME}' does not have a list of parameters", $/ if $^W;
Branch: 1 branch
BranchTrueFalseTotal
if $^W 0 0 0
47  
48 0 return $self;
49 }
50  
51 0 ▶ unless (@{$self->{DATA}})
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"DATA"};}) 0 0 0
52 {
53 0 $self->{NO_PARAMS} = 1;
54 }
55  
56 0 $self->{MAX_INDEX} = $#{$self->{DATA}};
57  
58 0 return $self;
59 }
60  
61 sub enter_scope
62 {
63 0 ▶ my $self = shift;
Subroutine enter_scope: not called CC=4 SCAR=30.0
Pod undocumented
64  
65 0 ▶ return 0 if $self->{NO_PARAMS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NO_PARAMS"} 0 0 0
66  
67 0 for my $x ($self->{DATA}[$self->{INDEX}])
68 {
69 0 $x->{uc $_} = delete $x->{$_} for keys %$x;
70 }
71  
72 0 push @{$self->{CONTEXT}{PARAM_MAP}}, $self->{DATA}[$self->{INDEX}];
73  
74 0 return 1;
75 }
76  
77 sub exit_scope
78 {
79 0 ▶ my $self = shift;
Subroutine exit_scope: not called CC=3 SCAR=24.8
Pod undocumented
80  
81 0 ▶ return 0 if $self->{NO_PARAMS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NO_PARAMS"} 0 0 0
82  
83 # There has to be the base parameter map and at least the one that
84 # Iterator::enter_scope() added on top.
85 0 ▶ @{$self->{CONTEXT}{PARAM_MAP}} > 1 ||
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{"CONTEXT"}{"PARAM_MAP"};} > 1 or die "Internal Error: ", __PACKAGE__, "'s internal param_map off!", $/ 0 0 0
86 die "Internal Error: ", __PACKAGE__, "'s internal param_map off!", $/;
87  
88 0 pop @{$self->{CONTEXT}{PARAM_MAP}};
89  
90 0 return 1;
91 }
92  
93 sub can_continue
94 {
95 0 ▶ my $self = shift;
Subroutine can_continue: not called CC=3 SCAR=24.8
Pod documented
96  
97 0 ▶ return 0 if $self->{NO_PARAMS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NO_PARAMS"} 0 0 0
98  
99 0 ▶ return 1 if $self->more_params;
Branch: 1 branch
BranchTrueFalseTotal
if $self->more_params 0 0 0
100  
101 0 return 0;
102 }
103  
104 sub more_params
105 {
106 0 ▶ my $self = shift;
Subroutine more_params: not called CC=3 SCAR=24.8
Pod documented
107  
108 0 ▶ return 0 if $self->{NO_PARAMS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NO_PARAMS"} 0 0 0
109  
110 0 ▶ return 1 if $self->{MAX_INDEX} > $self->{INDEX};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MAX_INDEX"} > $self->{"INDEX"} 0 0 0
111  
112 0 return 0;
113 }
114  
115 # Call this method BEFORE incrementing the index to the next value.
116 sub _do_globals
117 {
118 0 ▶ my $self = shift;
Subroutine _do_globals: not called CC=6 SCAR=37.4
119  
120 0 my $data = $self->{DATA}[$self->{INDEX}];
121  
122 # Perl's arrays are 0-indexed. Thus, the first element is at index "0".
123 # This means that odd-numbered elements are at even indices, and vice-versa.
124 # This also means that MAX (the number of elements in the array) can never
125 # be the value of an index. It is NOT the last index in the array.
126  
127 0 ▶ $data->{'__FIRST__'} ||= ($self->{INDEX} == 0);
Condition0%0/3
$data->{"__FIRST__"} ||= $self->{"INDEX"} == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->{"__FIRST__"} ||= $self->{"INDEX"} == 0
$data->{"__FIRST__"} $self->{"INDEX"} == 0
Truth table0%0/3
A ||= B
A= $data->{"__FIRST__"}B= $self->{"INDEX"} == 0
ABresult
1X1
011
000
128 0 ▶ $data->{'__INNER__'} ||= (0 < $self->{INDEX} && $self->{INDEX} < $self->{MAX_INDEX});
Condition0%0/6
$data->{"__INNER__"} ||= 0 < $self->{"INDEX"} && $self->{"INDEX"} < $self->{"MAX_INDEX"}
l!l&&r!l&&!r
000
0 < $self->{'INDEX'} && $self->{'INDEX'} < $self->{'MAX_INDEX'}
!ll&&!rl&&r
000
MC/DC0%0/3
$data->{"__INNER__"} ||= 0 < $self->{"INDEX"} && $self->{"INDEX"} < $self->{"MAX_INDEX"}
$data->{"__INNER__"} 0 < $self->{'INDEX'} $self->{'INDEX'} < $self->{'MAX_INDEX'}
Truth table0%0/4
A ||= B && C
A= $data->{"__INNER__"}B= 0 < $self->{'INDEX'}C= $self->{'INDEX'} < $self->{'MAX_INDEX'}
ABCresult
1XX1
0111
00X0
0100
129 0 ▶ $data->{'__LAST__'} ||= ($self->{INDEX} == $self->{MAX_INDEX});
Condition0%0/3
$data->{"__LAST__"} ||= $self->{"INDEX"} == $self->{"MAX_INDEX"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->{"__LAST__"} ||= $self->{"INDEX"} == $self->{"MAX_INDEX"}
$data->{"__LAST__"} $self->{"INDEX"} == $self->{"MAX_INDEX"}
Truth table0%0/3
A ||= B
A= $data->{"__LAST__"}B= $self->{"INDEX"} == $self->{"MAX_INDEX"}
ABresult
1X1
011
000
130 0 ▶ $data->{'__ODD__'} ||= !($self->{INDEX} % 2);
Condition0%0/3
$data->{"__ODD__"} ||= !($self->{"INDEX"} % 2)
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->{"__ODD__"} ||= !($self->{"INDEX"} % 2)
$data->{"__ODD__"} !($self->{"INDEX"} % 2)
Truth table0%0/3
A ||= not(B)
A= $data->{"__ODD__"}B= !($self->{"INDEX"} % 2)
ABresult
1X1
011
000
131  
132 0 return 1;
133 }
134  
135 sub next
136 {
137 0 ▶ my $self = shift;
Subroutine next: not called CC=3 SCAR=24.8
Pod documented
138  
139 0 ▶ return 0 if $self->{NO_PARAMS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NO_PARAMS"} 0 0 0
140  
141 0 ▶ return 0 unless $self->more_params;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->more_params 0 0 0
142  
143 0 $self->exit_scope;
144  
145 0 $self->{INDEX}++;
146  
147 0 $self->_do_globals;
148  
149 0 $self->enter_scope;
150  
151 0 return 1;
152 }
153  
154 # This method doesn't seem to be used ...
155 # If it is reinstated, here's the POD for it
156 #=head2 back_up
157 #
158 #Go to the previous iteration of the loop
159 #
160 #sub back_up
161 #{
162 # my $self = shift;
163 #
164 # return 0 if $self->{NO_PARAMS};
165 #
166 # $self->exit_scope;
167 #
168 # $self->{INDEX}--;
169 #
170 # $self->_do_globals;
171 #
172 # $self->enter_scope;
173 #
174 # return 1;
175 #}
176  
177 # This method doesn't seem to be used ...
178 # If it is reinstated, here's the POD for it
179 #=head2 reset
180 #
181 #Resets the iterator
182 #
183 #sub reset
184 #{
185 # my $self = shift;
186 #
187 # return 0 if $self->{NO_PARAMS};
188 #
189 # $self->{INDEX} = -1;
190 #
191 # return 1;
192 #}
193  
194 1 1;
195 __END__
« Template/Container/Worksheet.pm ↑ Summary Template/Factory.pm »