blib/lib/HTML/Processor.pm

filter: Statementstmt 3.3% 17 / 514 Branchbran 0.0% 0 / 184 Conditioncond 0.0% 0 / 137 MC/DCmcdc 0.0% 0 / 71 Subroutinesub 8.3% 4 / 48 Podpod 16.6% 6 / 36 totaltotal 2.7% 27 / 990 CC 153 SCAR 55.3
CC
153
Cov
2%
iterate_loop
702.0
sort
650.0
compare
462.0
CRAP 251.2
↑ Summary
1 package HTML::Processor;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION $syntax_pre $syntax_post @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 require Exporter;
7  
8 1 @ISA = qw(Exporter);
9  
10 1 $VERSION = '0.2.1';
11  
12 #----------------------------------------------
13 # Constructor for Template Object
14 #----------------------------------------------
15 0 ▶sub new {
Subroutine new: not called CC=10 SCAR=47.0
Pod undocumented
16 # new Template
17 0 my $proto = shift;
18 0 my $config_ref = shift; # hash of config options
19
20 # BEGIN CONFIG ////////////////////////////////
21 # These are template defaults and can be changed
22 # prior to installation or over-ridden when
23 # setting up the object
24 0 my %config = (
25 clean => 0,
26 escape => 0,
27 debug => 'Off',
28 footprint => 1,
29 syntax_pre => '\[TPL ',
30 syntax_post => '\]'
31 );
32 # END CONFIG //////////////////////////////////
33
34
35 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
36 0 my $self = {
37 PATHS => {},
38 DEBUG_LEVELS=> {
39 Fatal => 3,
40 Normal => 2,
41 Verbose => 1,
42 Off => 0
43 },
44 DEBUG_LEVEL => {},
45 FOOTPRINT => {},
46 CLEAN => {},
47 ESCAPE => {},
48 NESTS => {},
49 LOOPS => {},
50 VARIABLES => {},
51 OPTIONS => {},
52 INCLUDES => {},
53 HEADER => undef
54 };
55
56 # set up configs with passed data or default
57 0 ▶ $self->{ DEBUG_LEVEL } = $self->{DEBUG_LEVELS}{ $config_ref->{ debuglevel } } || $self->{DEBUG_LEVELS}{$config{ debug }};
Condition0%0/3
$self->{'DEBUG_LEVELS'}{$config_ref->{'debuglevel'}} || $self->{'DEBUG_LEVELS'}{$config{'debug'}}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'DEBUG_LEVELS'}{$config_ref->{'debuglevel'}} || $self->{'DEBUG_LEVELS'}{$config{'debug'}}
$self->{'DEBUG_LEVELS'}{$config_ref->{'debuglevel'}} $self->{'DEBUG_LEVELS'}{$config{'debug'}}
Truth table0%0/3
A || B
A= $self->{'DEBUG_LEVELS'}{$config_ref->{'debuglevel'}}B= $self->{'DEBUG_LEVELS'}{$config{'debug'}}
ABresult
1X1
011
000
58 0 ▶ $self->{ FOOTPRINT } = $config_ref->{ footprint } || $config{ footprint };
Condition0%0/3
$config_ref->{'footprint'} || $config{'footprint'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$config_ref->{'footprint'} || $config{'footprint'}
$config_ref->{'footprint'} $config{'footprint'}
Truth table0%0/3
A || B
A= $config_ref->{'footprint'}B= $config{'footprint'}
ABresult
1X1
011
000
59 0 ▶ $self->{ CLEAN } = $config_ref->{ clean } || $config{ clean };
Condition0%0/3
$config_ref->{'clean'} || $config{'clean'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$config_ref->{'clean'} || $config{'clean'}
$config_ref->{'clean'} $config{'clean'}
Truth table0%0/3
A || B
A= $config_ref->{'clean'}B= $config{'clean'}
ABresult
1X1
011
000
60 0 ▶ $self->{ ESCAPE } = $config_ref->{ escape } || $config{ escape };
Condition0%0/3
$config_ref->{'escape'} || $config{'escape'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$config_ref->{'escape'} || $config{'escape'}
$config_ref->{'escape'} $config{'escape'}
Truth table0%0/3
A || B
A= $config_ref->{'escape'}B= $config{'escape'}
ABresult
1X1
011
000
61 0 ▶ $syntax_pre = $config_ref->{ syntax_pre } || $config{ syntax_pre };
Condition0%0/3
$config_ref->{'syntax_pre'} || $config{'syntax_pre'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$config_ref->{'syntax_pre'} || $config{'syntax_pre'}
$config_ref->{'syntax_pre'} $config{'syntax_pre'}
Truth table0%0/3
A || B
A= $config_ref->{'syntax_pre'}B= $config{'syntax_pre'}
ABresult
1X1
011
000
62 0 ▶ $syntax_post = $config_ref->{ syntax_post } || $config{ syntax_post };
Condition0%0/3
$config_ref->{'syntax_post'} || $config{'syntax_post'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$config_ref->{'syntax_post'} || $config{'syntax_post'}
$config_ref->{'syntax_post'} $config{'syntax_post'}
Truth table0%0/3
A || B
A= $config_ref->{'syntax_post'}B= $config{'syntax_post'}
ABresult
1X1
011
000
63 0 bless($self, $class);
64
65 # debug the debug level!
66 0 ▶ if($config_ref->{ debuglevel } && !exists $self->{DEBUG_LEVELS}{ $config_ref->{ debuglevel } }){
Branch: 1 branch
BranchTrueFalseTotal
if ($config_ref->{"debuglevel"} and not exists $self->{"DEBUG_LEVELS"}{$config_ref->{"debuglevel"}}) 0 0 0
Condition0%0/3
$config_ref->{"debuglevel"} and not exists $self->{"DEBUG_LEVELS"}{$config_ref->{"debuglevel"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$config_ref->{"debuglevel"} and not exists $self->{"DEBUG_LEVELS"}{$config_ref->{"debuglevel"}}
$config_ref->{"debuglevel"} not exists $self->{"DEBUG_LEVELS"}{$config_ref->{"debuglevel"}}
Truth table0%0/3
A and not(B)
A= $config_ref->{"debuglevel"}B= not exists $self->{"DEBUG_LEVELS"}{$config_ref->{"debuglevel"}}
ABresult
0X0
100
111
67 0 $self->debug("param",3,"Invalid debug level: '<b>$config_ref->{ debuglevel }</b>' not one of (". join(", ", keys %{$self->{DEBUG_LEVELS}}) . ")",3);
68 }
69 0 return $self;
70 }
71  
72  
73 #----------------------------------------------
74 # Constructor for Loop Object
75 #----------------------------------------------
76 0 ▶sub new_loop {
Subroutine new_loop: not called CC=2 SCAR=17.9
Pod undocumented
77 0 my $self = shift;
78 0 my $name = shift;
79 0 my $nest = shift;
80
81 0 ▶ if($nest){
Branch: 1 branch
BranchTrueFalseTotal
if ($nest) 0 0 0
82 0 push @{ $self->{ NESTS }->{$name}->{ KEYS } }, $nest;
83 0 $name = "${name}~${nest}";
84 }
85 0 $self->{ LOOPS }->{$name} = HTML::Processor::Loop->new();
86 0 return $self->{ LOOPS }->{$name}; # return a handle
87 }
88  
89 #----------------------------------------------
90 # build variables
91 #----------------------------------------------
92 0 ▶sub variable {
Subroutine variable: not called CC=2 SCAR=17.9
Pod documented
93 0 my $self = shift;
94 0 my $name = shift;
95 0 my $val = shift;
96  
97 0 ▶ $self->{ VARIABLES }{$name} = $val if( defined $val );
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 0 0 0
98 0 return $self->{ VARIABLES }{$name};
99  
100 }
101  
102 #----------------------------------------------
103 # concatenate variable value with input
104 #----------------------------------------------
105 0 ▶sub concat {
Subroutine concat: not called CC=2 SCAR=17.9
Pod undocumented
106 0 my $self = shift;
107 0 my $name = shift;
108 0 my $val = shift;
109 0 my $invert = shift;
110
111 0 ▶ if ( $invert ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($invert) { } 0 0 0
112 0 $self->{ VARIABLES }{$name} = $val . $self->{ VARIABLES }{$name};
113 }
114 else{
115 0 $self->{ VARIABLES }{$name} .= $val;
116 }
117 0 return $self->{ VARIABLES }{$name};
118 }
119  
120 #----------------------------------------------
121 # perform basic maths on a variable
122 #----------------------------------------------
123 0 ▶sub math {
Subroutine math: not called CC=5 SCAR=34.0
Pod documented
124 0 my $self = shift;
125 0 my ( $var, $val, $opr, $invert ) = @_;
126 0 my $result;
127 0 my %operands = (
128 '+' => \&addition,
129 '-' => \&subtraction,
130 '*' => \&multiplication,
131 '/' => \&division,
132 );
133 # check if this is a valid variable
134 0 ▶ if(!$self->{ VARIABLES }{$var}){
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'VARIABLES'}{$var}) { } 0 0 0
elsif (not $operands{$opr}) { } 0 0 0
135 0 $self->debug("process",3,"'$var' is an un-declared variable, can't do math");
136 }
137 # check if this is a valid operand
138 elsif(!$operands{$opr}){
139 0 $self->debug("process",3,"'$opr' is not a valid math operand from('+', '-', '*','/')");
140 }
141 else {
142 # retrieve the values
143 0 ▶ my $val_val = ( exists $self->{ VARIABLES }{ $val } ) ? $self->{ VARIABLES }{ $val } : $val;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'VARIABLES'}{$val} ? : 0 0 0
144 0 my $var_val = $self->{ VARIABLES }{ $var };
145  
146 0 ▶ my @pair = ($invert) ? ($val_val, $var_val) : ($var_val, $val_val);
Branch: 1 branch
BranchTrueFalseTotal
$invert ? : 0 0 0
147 0 $result = &{ $operands{$opr} }( \@pair );
148 }
149 0 $self->variable($var, $result);
150 0 return $result;
151 }
152  
153 #----------------------------------------------
154 # build included files
155 #----------------------------------------------
156 0 ▶sub include {
Subroutine include: not called CC=2 SCAR=17.9
Pod undocumented
157 0 my $self = shift;
158 0 my $name = shift;
159 0 my $file = shift;
160
161 0 ▶ $self->{ INCLUDES }{ $name } = $file if ( $file );
Branch: 1 branch
BranchTrueFalseTotal
if $file 0 0 0
162 0 return $self->{ INCLUDES }{ $name };
163 }
164 #----------------------------------------------
165 # Add base paths
166 #----------------------------------------------
167 0 ▶sub add_path {
Subroutine add_path: not called CC=1 SCAR=6.9
Pod undocumented
168 0 my $self = shift;
169 0 my $path = shift;
170
171 0 $self->{ PATHS }->{ $path }++;
172 }
173  
174 #----------------------------------------------
175 # build options
176 #----------------------------------------------
177 0 ▶sub option {
Subroutine option: not called CC=2 SCAR=17.9
Pod undocumented
178 0 my $self = shift;
179 0 my $name = shift;
180 0 my $val = shift;
181
182 0 ▶ $self->{ OPTIONS }{ $name } = $val if ( $val );
Branch: 1 branch
BranchTrueFalseTotal
if $val 0 0 0
183 0 return $self->{ OPTIONS }{ $name };
184 }
185  
186 #----------------------------------------------
187 # Print a value and exit
188 #----------------------------------------------
189 0 ▶sub print_die {
Subroutine print_die: not called CC=1 SCAR=6.9
Pod undocumented
190 0 my $self = shift;
191 0 my $data = shift;
192
193 0 print "Content-type: text/html \n\n";
194 0 print $data;
195 0 exit;
196 }
197  
198 #----------------------------------------------
199 # print content inline 4 debugging
200 #----------------------------------------------
201 0 ▶sub print {
Subroutine print: not called CC=3 SCAR=24.8
Pod undocumented
202 0 my $self = shift;
203 0 my $data = shift;
204 0 my $line_end = shift;
205 0 ▶ if(!$self->{ HEADER }){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"HEADER"}) 0 0 0
206 # print a header on first pass
207 0 print "Content-type: text/html \n\n";
208 0 $self->{ HEADER } = 1;
209 }
210 0 ▶ print $data . ($line_end || "<br>\n");
Condition0%0/2
$line_end || "<br>\n"
l!l
00
MC/DC0%0/1
$line_end || "<br>\n"
$line_end
Truth table0%0/2
A
A= $line_end
Aresult
11
00
211 }
212  
213 #----------------------------------------------
214 # Print a value and exit
215 #----------------------------------------------
216 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
217 0 my $self = shift;
218 0 my $data = shift;
219 0 my $app = shift;
220
221 0 my( $file, $line, $pack, $sub ) = id(1);
222 0 print "Content-type: text/html \n\n";
223 0 my $out = qq|<h1>$app Software Error:</h1>
224 <pre>$data
225 at: $file line: $line
226 </pre>
227 |;
228 0 print $out;
229 0 exit;
230 }
231  
232 #----------------------------------------------
233 # Set clean on||off
234 #----------------------------------------------
235 0 ▶sub set_clean {
Subroutine set_clean: not called CC=2 SCAR=17.9
Pod undocumented
236 0 my $self = shift;
237 0 my $state = shift;
238
239 0 ▶ $self->{ CLEAN } = $state || 0;
Condition0%0/2
$state || 0
l!l
00
MC/DC0%0/1
$state || 0
$state
Truth table0%0/2
A
A= $state
Aresult
11
00
240 }
241  
242 #----------------------------------------------
243 # Set escape on||off
244 #----------------------------------------------
245 0 ▶sub set_escape {
Subroutine set_escape: not called CC=2 SCAR=17.9
Pod undocumented
246 0 my $self = shift;
247 0 my $state = shift;
248  
249 0 ▶ $self->{ ESCAPE } = $state || 0;
Condition0%0/2
$state || 0
l!l
00
MC/DC0%0/1
$state || 0
$state
Truth table0%0/2
A
A= $state
Aresult
11
00
250 }
251 #----------------------------------------------
252 # Set footprint on||off
253 #----------------------------------------------
254 0 ▶sub set_footprint {
Subroutine set_footprint: not called CC=2 SCAR=17.9
Pod undocumented
255 0 my $self = shift;
256 0 my $state = shift;
257
258 0 ▶ $self->{ FOOTPRINT } = $state || 0;
Condition0%0/2
$state || 0
l!l
00
MC/DC0%0/1
$state || 0
$state
Truth table0%0/2
A
A= $state
Aresult
11
00
259 }
260  
261 #----------------------------------------------
262 # Set config options
263 #----------------------------------------------
264 0 ▶sub set_config {
Subroutine set_config: not called CC=3 SCAR=24.8
Pod undocumented
265 0 my $self = shift;
266 0 my $state = shift;
267  
268 # define cofig for various states
269 0 my %states = (
270 'email' => {
271 FOOTPRINT => 0,
272 CLEAN => 0
273 },
274 'default' => {
275 FOOTPRINT => 1,
276 CLEAN => 1
277 }
278 );
279 # set config params according to passed state
280 0 ▶ if( $states{$state} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($states{$state}) 0 0 0
281 0 foreach my $func(keys %{ $states{$state} }){
282 0 $self->{$func} = $states{$state}->{$func};
283 }
284 }
285 }
286  
287 #----------------------------------------------
288 # Sort a loop by one of its keys
289 #----------------------------------------------
290 0 ▶sub sort {
Subroutine sort: not called CC=25 SCAR=64.8
Pod undocumented
291 0 my $self = shift;
292 0 my $sortby = shift;
293
294  
295 # return if there is not sort by values
296 0 ▶ return unless $sortby;
Branch: 1 branch
BranchTrueFalseTotal
unless $sortby 0 0 0
297
298 0 $self->{ SORTBY } = $sortby;
299 0 my ( $dir, $loop, $sort_on );
300 0 my @sorts = reverse split( /-/, $sortby );
301
302 # test the sort key for: dir - sorton - loop
303 0 ▶ if ( @sorts == 3 ) {
Branch: 4 branches
BranchTrueFalseTotal
if (@sorts == 3) { } 0 0 0
elsif (@sorts == 2 and lc $sorts[0] eq 'asc' || lc $sorts[0] eq 'desc') { } 0 0 0
elsif (@sorts == 2 and lc $sorts[0] ne 'asc' || lc $sorts[0] ne 'desc') { } 0 0 0
elsif (@sorts == 1) { } 0 0 0
304 0 $dir = lc $sorts[0];
305 0 $sort_on = $sorts[1];
306 0 $loop = $sorts[2];
307 }
308 ▶ elsif (@sorts == 2 && (lc $sorts[0] eq "asc" || lc $sorts[0] eq "desc")){
Condition0%0/6
@sorts == 2 and lc $sorts[0] eq "asc" || lc $sorts[0] eq "desc"
!ll&&!rl&&r
000
lc $sorts[0] eq "asc" or lc $sorts[0] eq "desc"
l!l&&r!l&&!r
000
MC/DC0%0/3
@sorts == 2 and lc $sorts[0] eq "asc" || lc $sorts[0] eq "desc"
@sorts == 2 lc $sorts[0] eq "asc" lc $sorts[0] eq "desc"
Truth table0%0/4
A and B or C
A= @sorts == 2B= lc $sorts[0] eq "asc"C= lc $sorts[0] eq "desc"
ABCresult
0XX0
1000
11X1
1011
309 0 $dir = lc $sorts[0];
310 0 $sort_on = $sorts[1];
311 }
312 ▶ elsif (@sorts == 2 && (lc $sorts[0] ne "asc" || lc $sorts[0] ne "desc")){
Condition0%0/6
@sorts == 2 and lc $sorts[0] ne "asc" || lc $sorts[0] ne "desc"
!ll&&!rl&&r
000
lc $sorts[0] ne "asc" or lc $sorts[0] ne "desc"
l!l&&r!l&&!r
000
MC/DC0%0/3
@sorts == 2 and lc $sorts[0] ne "asc" || lc $sorts[0] ne "desc"
@sorts == 2 lc $sorts[0] ne "asc" lc $sorts[0] ne "desc"
Truth table0%0/4
A and B or C
A= @sorts == 2B= lc $sorts[0] ne "asc"C= lc $sorts[0] ne "desc"
ABCresult
0XX0
1000
11X1
1011
313 0 $dir = "asc";
314 0 $sort_on = $sorts[0];
315 0 $loop = $sorts[1];
316 }
317 elsif (@sorts == 1){
318 0 $dir = "asc";
319 0 $sort_on = $sorts[0];
320 }
321
322 # if we don't have an loop to sort on yet - go find one
323 0 my @multiples;
324 0 ▶ if ( !$loop ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($loop) 0 0 0
325 0 foreach my $loop_name ( keys %{ $self->{ LOOPS } }){
326 # use the last loop that tests true
327 0 ▶ if($self->{ LOOPS }->{ $loop_name }->{ $sort_on }){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"LOOPS"}{$loop_name}{$sort_on}) 0 0 0
328 0 $loop = $loop_name;
329 0 push @multiples, $loop_name;
330 }
331 }
332 # die if we have more than 1 possible loop
333 0 ▶ $self->debug("parse",
Branch: 1 branch
BranchTrueFalseTotal
if @multiples > 1 0 0 0
334 3,
335 "sort called without specifying loop & " .
336 "multiple possible loops [" .
337 join(", ", @multiples) .
338 "] found for sort key: $sort_on"
339 ) if @multiples > 1;
340 }
341
342 0 ▶ if($self->{ LOOPS }->{ $loop }{$sort_on}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'LOOPS'}{$loop}{$sort_on}) { } 0 0 0
343 0 my @sortkeys = @{ $self->{ LOOPS }->{ $loop }{$sort_on} };
344 # check if data is string or int
345 0 ▶ my $data_type = ($sortkeys[0] =~ /(\D)/ && $1 !~ /\.|\,/) ? "STRING" : "INT";
Branch: 1 branch
BranchTrueFalseTotal
$sortkeys[0] =~ /(\D)/ && !($1 =~ /\.|\,/) ? : 0 0 0
Condition0%0/3
$sortkeys[0] =~ /(\D)/ and not $1 =~ /\.|\,/
!ll&&!rl&&r
000
MC/DC0%0/2
$sortkeys[0] =~ /(\D)/ and not $1 =~ /\.|\,/
$sortkeys[0] =~ /(\D)/ not $1 =~ /\.|\,/
Truth table0%0/3
A and not(B)
A= $sortkeys[0] =~ /(\D)/B= not $1 =~ /\.|\,/
ABresult
0X0
100
111
346 0 ▶ if ( $data_type eq "INT" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_type eq "INT") 0 0 0
347 # strip commas
348 0 $sortkeys[$_] =~ s/,//g for 0..$#sortkeys;
349 }
350 my %sortcode = (
351 0 ▶ "STRING-asc" => sub { return sort { uc $sortkeys[$a] cmp uc $sortkeys[$b] } 0..$#sortkeys },
Subroutine __ANON__: not called CC=1 SCAR=6.9
352 0 ▶ "STRING-desc" => sub { return sort { uc $sortkeys[$b] cmp uc $sortkeys[$a] } 0..$#sortkeys },
Subroutine __ANON__: not called CC=1 SCAR=6.9
353 0 ▶ "INT-asc" => sub { return sort { $sortkeys[$a] <=> $sortkeys[$b] } 0..$#sortkeys },
Subroutine __ANON__: not called CC=1 SCAR=6.9
354 0 ▶ "INT-desc" => sub { return sort { $sortkeys[$b] <=> $sortkeys[$a] } 0..$#sortkeys }
Subroutine __ANON__: not called CC=1 SCAR=6.9
355 0 );
356 0 my @sorted = &{ $sortcode{"${data_type}-${dir}"} };
357 0 $self->{ LOOPS }->{ $loop }{$_} = [ @{$self->{ LOOPS }->{ $loop }{$_}}[@sorted] ] for keys %{ $self->{ LOOPS }->{ $loop } };
358 0 $self->{ SKEYS } = [@sorted];
359
360 # sort the bg colours if there are any
361 #--------------------------------------------------------
362 0 ▶ if ( $self->{ LOOPS }->{ $loop }{ 'bgcolor' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"LOOPS"}{$loop}{"bgcolor"}) 0 0 0
363
364 # get the unique colours
365 0 my %colours;
366 0 foreach my $colour ( @{ $self->{ LOOPS }->{ $loop }{ 'bgcolor' } } ){
367 0 $colours{ $colour }++;
368 0 ▶ last if ( scalar keys %colours >= 2 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %colours >= 2 0 0 0
369 }
370 # if we have 2 to work with
371 0 ▶ if ( keys %colours == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %colours == 2) 0 0 0
372 # create the colour toggle
373 0 my $toggle = $self->create_toggle( keys %colours );
374 0 my $colour;
375 # reset each of the bgcolour elements
376 0 ▶ for ( my $i = 0; $i < scalar @{ $self->{ LOOPS }->{ $loop }{ 'bgcolor' } }; $i++ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"LOOPS"}{$loop}{"bgcolor"};}) 0 0 0
377 0 $colour = $toggle->( $colour );
378 0 $self->{ LOOPS }->{ $loop }{ 'bgcolor' }->[$i] = $colour;
379 }
380 }
381 }
382  
383 }
384 else {
385 0 $self->debug("parse",2,"sortby called with non-existent sort key: $loop => $sortby");
386 }
387 }
388  
389 #--------------------------------------------
390 # toggle a colour
391 #--------------------------------------------
392 0 ▶sub create_toggle {
Subroutine create_toggle: not called CC=1 SCAR=6.9
Pod undocumented
393 0 my $self = shift;
394 0 my ( $primary, $secondary ) = @_;
395  
396 0 my $current = $secondary;
397 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
398 0 my $cur_ref = \$current;
399 0 ▶ $$cur_ref = ($$cur_ref eq $primary) ? $secondary : $primary;
Branch: 1 branch
BranchTrueFalseTotal
$$cur_ref eq $primary ? : 0 0 0
400 0 return $$cur_ref;
401 }
402 0 }
403  
404 #--------------------------------------------------
405 # generic subroutine for creating HTML dropdowns
406 #--------------------------------------------------
407 0 ▶sub create_dropdown {
Subroutine create_dropdown: not called CC=7 SCAR=40.3
Pod undocumented
408  
409 0 my $self = shift;
410 0 my ( $itr_name, $ref_array_id, $ref_array_name, $selected_id, $selected_name ) = @_;
411 # create loop
412 0 my $itr = $self->new_loop($itr_name);
413 0 my $count = 0;
414 # populate loop
415 0 foreach my $id ( @$ref_array_id ) {
416 0 ▶ my $name = ( $ref_array_name ) ? $$ref_array_name[$count++] : '';
Branch: 1 branch
BranchTrueFalseTotal
$ref_array_name ? : 0 0 0
417 0 my $type_selected = '';
418
419 0 $itr->array("id", $id);
420 0 ▶ $itr->array("name", $name || $id);
Condition0%0/3
$name || $id
l!l&&r!l&&!r
000
MC/DC0%0/2
$name || $id
$name $id
Truth table0%0/3
A || B
A= $nameB= $id
ABresult
1X1
011
000
421 # is this the selected item?
422 0 ▶ if ( $selected_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($selected_id) { } 0 0 0
423 0 ▶ $type_selected = ( $selected_id eq $id ) ? " SELECTED" : "";
Branch: 1 branch
BranchTrueFalseTotal
$selected_id eq $id ? : 0 0 0
424 }
425 else {
426 0 ▶ $type_selected = ( $selected_name eq $name ) ? " SELECTED" : "";
Branch: 1 branch
BranchTrueFalseTotal
$selected_name eq $name ? : 0 0 0
427 }
428 0 $itr->array("selected", $type_selected);
429 }
430 }
431  
432 #----------------------------------------------
433 # Parse and Return the template
434 #----------------------------------------------
435 0 ▶sub process {
Subroutine process: not called CC=11 SCAR=45.8
Pod undocumented
436 0 my $self = shift;
437 0 my $template_path = shift;
438 0 my $debug_object = shift;
439  
440 # prepend template path and name to output if footprint is set
441 0 ▶ my $template = ($self->{ FOOTPRINT }) ? "<!--- TEMPLATE: $template_path --->\n" : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'FOOTPRINT'} ? : 0 0 0
442  
443 # check for a template file on line 1 of template path
444 0 ▶ if ( (split /\n/, $template_path)[0] =~ /\.\w{3,4}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((split(/\n/, $template_path, 0))[0] =~ /\.\w{3,4}$/) { } 0 0 0
445 # we're processing a file
446
447 # if the file is not found: check if its relative to a stored path
448 0 ▶ unless ( -e $template_path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $template_path) 0 0 0
449 0 foreach my $stored_path ( keys %{ $self->{ PATHS } } ) {
450 # check if the template exists at the stored PATH location
451 0 ▶ if ( -e ($stored_path . $template_path) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $stored_path . $template_path) 0 0 0
452 0 $template_path = $stored_path . $template_path;
453 0 last;
454 }
455 }
456 }
457
458 0 local $/ = undef; # undef record separator for reading file into scalar
459 0 ▶ open (READFILE, $template_path) or $self->debug("file",3,"Can't open content file : $template_path $!");
Branch: 1 branch
BranchTrueFalseTotal
open READFILE, $template_path or $self->debug("file", 3, "Can't open content file : $template_path $!") 0 0 0
460 0 $template .= <READFILE>;
461 0 close READFILE;
462
463 }
464 else {
465 # we're processing a data block
466 0 $template = $template_path;
467 # set base path to Cwd for includes from data
468 1 ▶ use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
469 0 $template_path = cwd;
470 }
471
472 0 $self->{ TEMPLATE } = $template_path;
473
474 # process the html template
475 0 $self->do_includes (\$template,\$template_path);
476 0 $self->do_options (\$template);
477 0 $self->do_ifelse (\$template);
478 0 $self->do_variables (\$template);
479 0 $self->do_loops (\$template);
480 0 ▶ $self->do_sort_dir (\$template) if $self->{ SORTBY };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"SORTBY"} 0 0 0
481 0 ▶ $self->do_clean (\$template) if $self->{ CLEAN };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CLEAN"} 0 0 0
482
483 # if we are dumping object data
484 0 ▶ if( $debug_object ){
Branch: 1 branch
BranchTrueFalseTotal
if ($debug_object) 0 0 0
485 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
486 # take a copy of the object
487 0 my $debugObj = $self;
488 # clean up the object before debug display
489 0 delete $debugObj->{ IT_STACK };
490 0 delete $debugObj->{ DEBUG_LEVELS };
491 0 $template .= "<div style=\"position:relative; top:50;\"><pre>" . Dumper( $debugObj ) . "</pre></div>";
492 }
493 # add debug data
494 0 ▶ $template .= $self->build_err if($self->{ DEBUG_LEVEL } > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG_LEVEL"} > 0 0 0 0
495
496 0 return $template;
497 }
498  
499  
500  
501 #=========================================================
502 # PRIVATE METHODS
503 #=========================================================
504  
505 #=====================================
506 # math private methods
507 #=====================================
508 0 ▶sub addition {
Subroutine addition: not called CC=1 SCAR=6.9
Pod documented
509 0 my $pair = shift;
510 0 my ($this, $that) = @$pair;
511 0 return $this + $that;
512 }
513  
514 0 ▶sub subtraction {
Subroutine subtraction: not called CC=1 SCAR=6.9
Pod documented
515 0 my $pair = shift;
516 0 my ($this, $that) = @$pair;
517 0 return $this - $that;
518 }
519  
520 0 ▶sub multiplication {
Subroutine multiplication: not called CC=1 SCAR=6.9
Pod documented
521 0 my $pair = shift;
522 0 my ($this, $that) = @$pair;
523 0 return $this * $that;
524 }
525  
526 0 ▶sub division {
Subroutine division: not called CC=1 SCAR=6.9
Pod documented
527 0 my $pair = shift;
528 0 my ($this, $that) = @$pair;
529 0 return $this / $that;
530 }
531  
532 #=====================================
533  
534 #=====================================
535 # change the sort direction
536 #=====================================
537 0 ▶sub do_sort_dir {
Subroutine do_sort_dir: not called CC=4 SCAR=30.0
Pod undocumented
538 0 my $self = shift;
539 0 my $template_ref = shift;
540
541 0 ▶ return if $self->{ SORTBY } =~ /ASC|DESC/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"SORTBY"} =~ /ASC|DESC/ 0 0 0
542 0 my $out;
543 0 my $skey = $self->{ SORTBY };
544 0 $skey =~ /(asc|desc)/;
545 0 my $dir = $1;
546 0 ▶ my $dirout = ($dir eq "desc") ? "asc" : "desc";
Branch: 1 branch
BranchTrueFalseTotal
$dir eq 'desc' ? : 0 0 0
547 0 ▶ if ( $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 0 0
548 0 $out = $skey;
549 0 $out =~ s/$dir/$dirout/;
550 }
551 else {
552 0 $out = $skey . "-$dirout";
553 }
554 0 $$template_ref =~ s/sort=$skey/sort=$out/o;
555  
556 }
557  
558 #=====================================
559 # include files into template
560 #=====================================
561 0 ▶sub do_includes {
Subroutine do_includes: not called CC=11 SCAR=48.8
Pod undocumented
562 0 my $self = shift;
563 0 my $template_ref = shift;
564 0 my $template_path_ref = shift;
565  
566 # use template path as root for includes
567 0 ▶ if ( $$template_path_ref =~ m/\// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$template_path_ref =~ m[/]) { } 0 0 0
568 # if there is a path
569 0 $$template_path_ref =~ s/(.*)(\/)(.*?)$/$1$2/;
570 }
571 else {
572 # file name only
573 0 $$template_path_ref = "";
574 }
575 # start paths library
576 0 $self->{ PATHS }->{ $$template_path_ref } = 1;
577
578 0 ▶ while ( $$template_ref =~ m/\A(.*)${syntax_pre}include='(.*?)'${syntax_post}(.*)\Z/msi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$template_ref =~ /\A(.*)$HTML::Processor::syntax_preinclude='(.*?)'$HTML::Processor::syntax_post(.*)\Z/ism) 0 0 0
579 0 my $inc_pre = $1; # pre included file
580 0 my $file = $2; # $variables name for file
581 0 my $inc_post = $3; # post include data
582 0 my $filepath = '';
583
584 0 ▶ if ( $file =~ /\./ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\./) { } 0 0 0
585 0 $filepath = $$template_path_ref . $file;
586 0 my $filename;
587 0 my $local_path = "";
588 # has a path
589 0 ▶ if ($file =~ /\// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ m[/]) { } 0 0 0
590 0 $local_path = $file;
591 0 $local_path =~ s/(.*)(\/)(.*?)(\.\w{3,4}$)/$1$2/;
592 0 $filename = $3.$4;
593 }
594 else {
595 0 $filename = $file;
596 }
597 # store path
598 0 $self->{ PATHS }->{$$template_path_ref . $local_path}++;
599
600 # if the file is relative to an included file
601 0 ▶ unless ( -e $filepath ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $filepath) 0 0 0
602 0 foreach ( keys %{ $self->{PATHS} } ) {
603 0 ▶ if ( -e $_ . $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $_ . $filename) 0 0 0
604 0 $filepath = $_ . $filename;
605 }
606 }
607 }
608 }
609 else {
610 0 $filepath = $self->include($file);
611 }
612  
613 0 ▶ my $footpre = ( $self->{FOOTPRINT} ) ? "<!-- TEMPLATE BEGIN INCLUDE $filepath -->\n\n" : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'FOOTPRINT'} ? : 0 0 0
614 0 ▶ my $footpost = ( $self->{FOOTPRINT} ) ? "\n\n<!-- TEMPLATE END INCLUDE: $filepath -->\n\n" : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'FOOTPRINT'} ? : 0 0 0
615
616 # test for existence of file
617 0 ▶ if ( -e $filepath ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $filepath) { } 0 0 0
618 0 local $/ = undef;
619 0 open( INCLUDE, "< $filepath" );
620 0 my $inc_data = <INCLUDE>;
621 0 close(INCLUDE);
622 0 $$template_ref = "$inc_pre$footpre$inc_data$footpost$inc_post";
623 }
624 # no file to include
625 else {
626 0 $$template_ref = $inc_pre . "<!-- TEMPLATE ERR: no inc file - $filepath -->" . $inc_post;
627 0 $self->debug( "parse", 3, "File to <b>include</b> does not exist:'<b>$filepath</b>'" );
628 }
629 }
630 }
631 #=====================================
632 # evaluate optional content
633 #=====================================
634 0 ▶sub do_options {
Subroutine do_options: not called CC=7 SCAR=40.3
Pod undocumented
635 0 my $self = shift;
636 0 my $template_ref = shift;
637
638 0 ▶ while ($$template_ref =~ m/\A(.*)${syntax_pre}OPTION name([ !=]+)'([\w\d-]*)'${syntax_post}(.*?)${syntax_pre}OPTION END${syntax_post}(.*)\Z/msi){
Branch: 1 branch
BranchTrueFalseTotal
if ($$template_ref =~ /\A(.*)$HTML::Processor::syntax_preOPTION name([ !=]+)'([\w\d-]*)'$HTML::Processor::syntax_post(.*?)$HTML::Processor::syntax_preOPTION END$HTML::Processor::syntax_post(.*)\Z/ism) 0 0 0
639 0 my $opt_pre = $1;
640 0 my $opt_type = $2;
641 0 my $opt_name = $3;
642 0 my $opt_data = $4;
643 0 my $opt_post = $5;
644 # clean the option comarisons
645 0 $opt_type =~ s/ //g;
646 0 $opt_type =~ s/==/=/;
647
648 0 ▶ my $test_val = $self->option($opt_name) || $self->variable($opt_name);
Condition0%0/3
$self->option($opt_name) || $self->variable($opt_name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->option($opt_name) || $self->variable($opt_name)
$self->option($opt_name) $self->variable($opt_name)
Truth table0%0/3
A || B
A= $self->option($opt_name)B= $self->variable($opt_name)
ABresult
1X1
011
000
649
650 0 ▶ if($opt_type eq "=" && $test_val){
Branch: 2 branches
BranchTrueFalseTotal
if ($opt_type eq '=' and $test_val) { } 0 0 0
elsif ($opt_type eq '!=' and not $test_val) { } 0 0 0
Condition0%0/3
$opt_type eq "=" and $test_val
!ll&&!rl&&r
000
MC/DC0%0/2
$opt_type eq "=" and $test_val
$opt_type eq "=" $test_val
Truth table0%0/3
A and B
A= $opt_type eq "="B= $test_val
ABresult
0X0
100
111
651 0 $$template_ref = $opt_pre.$opt_data.$opt_post;
652 }
653 ▶ elsif($opt_type eq "!=" && !$test_val){
Condition0%0/3
$opt_type eq "!=" and not $test_val
!ll&&!rl&&r
000
MC/DC0%0/2
$opt_type eq "!=" and not $test_val
$opt_type eq "!=" not $test_val
Truth table0%0/3
A and not(B)
A= $opt_type eq "!="B= not $test_val
ABresult
0X0
100
111
654 0 $$template_ref = $opt_pre.$opt_data.$opt_post;
655 }
656 # option fails
657 else {
658 # loose the optional content
659 0 $$template_ref = $opt_pre.$opt_post;
660 }
661 }
662 }
663  
664 #=====================================
665 # Evaluate If/Else clauses
666 #=====================================
667 0 ▶sub do_ifelse {
Subroutine do_ifelse: not called CC=8 SCAR=42.8
Pod undocumented
668 0 my $self = shift;
669 0 my $template_ref = shift;
670  
671 0 ▶ while ( $$template_ref =~ m/\A(.*)${syntax_pre}IF (\w+)([ =!<>]+)'([\w-]*)'${syntax_post}(.*?)(${syntax_pre}ENDIF${syntax_post})(.*)\Z/msi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$template_ref =~ /\A(.*)$HTML::Processor::syntax_preIF (\w+)([ =!<>]+)'([\w-]*)'$HTML::Processor::syntax_post(.*?)($HTML::Processor::syntax_preENDIF$HTML::Processor::syntax_post)(.*)\Z/ism) 0 0 0
672 0 my $if_pre = $1; # pre if data
673 0 my $fs_var = $2; # first if variable
674 0 my $fs_oper = $3; # first if operand
675 0 my $fs_val = $4; # first value to test
676 0 my $if_cont = $5; # block to do work on
677 0 my $if_end = $6; # [ENDIF] end of string
678 0 my $if_post = $7; # rest of template
679 0 my $if_output = '';
680  
681 # test if the first is true
682 0 ▶ if ( $self->compare( $fs_oper, $self->variable($fs_var), $fs_val ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->compare($fs_oper, $self->variable($fs_var), $fs_val)) { } 0 0 0
683 0 ▶ $if_cont =~ s/(.*?)${syntax_pre}(ELSIF|ELSE).*\Z/$1/msi if $if_cont =~ /${syntax_pre}(ELSIF|ELSE)/msi;
Branch: 1 branch
BranchTrueFalseTotal
if $if_cont =~ /$HTML::Processor::syntax_pre(ELSIF|ELSE)/ism 0 0 0
684 0 $if_output = $if_cont;
685 }
686 # loop through remaining tests
687 else {
688 0 my $if_data = $if_cont . $if_end;
689  
690 # evaluate each ELSIF|ELSE
691 0 ▶ while ( $if_data =~ m/${syntax_pre}(ELSIF|ELSE)(| (\w+)([ =!<>]+)'([\w-]*)')${syntax_post}(.*?)(${syntax_pre}(ELSIF|ELSE|ENDIF).*)\Z/msi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($if_data =~ /$HTML::Processor::syntax_pre(ELSIF|ELSE)(| (\w+)([ =!<>]+)'([\w-]*)')$HTML::Processor::syntax_post(.*?)($HTML::Processor::syntax_pre(ELSIF|ELSE|ENDIF).*)\Z/ism) 0 0 0
692 0 my $if_type = $1; # clause type (IF|ELSIF|ELSE)
693 0 my $if_var = $3; # value to test
694 0 my $oper = $4; # if operator
695 0 my $if_val = $5; # value to test
696 0 my $if_content = $6; # output for the block
697 0 my $if_tail = $7; # following IF/ELSE clauses
698  
699 # evaluate clauses
700 0 ▶ if ( $if_type =~ /ELSIF|IF/ && $self->compare( $oper, $self->variable($if_var), $if_val ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($if_type =~ /ELSIF|IF/ and $self->compare($oper, $self->variable($if_var), $if_val)) { } 0 0 0
elsif ($if_type =~ /ELSE/) { } 0 0 0
Condition0%0/3
$if_type =~ /ELSIF|IF/ and $self->compare($oper, $self->variable($if_var), $if_val)
!ll&&!rl&&r
000
MC/DC0%0/2
$if_type =~ /ELSIF|IF/ and $self->compare($oper, $self->variable($if_var), $if_val)
$if_type =~ /ELSIF|IF/ $self->compare($oper, $self->variable($if_var), $if_val)
Truth table0%0/3
A and B
A= $if_type =~ /ELSIF|IF/B= $self->compare($oper, $self->variable($if_var), $if_val)
ABresult
0X0
100
111
701 0 $if_output = $if_content;
702 0 last; # exit if there's a match
703 }
704 # use the else if above fails
705 elsif ( $if_type =~ /ELSE/ ) {
706 0 $if_output = $if_content;
707 }
708 # truncate the string for each loop by what we just tested
709 0 $if_data = $if_tail;
710 }
711 }
712 0 $$template_ref = $if_pre . $if_output . $if_post;
713 }
714 }
715  
716  
717 #=====================================
718 # replace loops
719 #=====================================
720 #my (%it_stack);
721 0 ▶sub do_loops {
Subroutine do_loops: not called CC=5 SCAR=34.0
Pod undocumented
722 0 my $self = shift;
723 0 my $template_ref = shift;
724
725 0 $self->{ IT_STACK } = {};
726
727 0 ▶ while ( $$template_ref =~ m/\A(.*)${syntax_pre}LOOP name='([\w\d-]+)'${syntax_post}(.*?)${syntax_pre}LOOP END${syntax_post}(.*)\Z/msi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$template_ref =~ /\A(.*)$HTML::Processor::syntax_preLOOP name='([\w\d-]+)'$HTML::Processor::syntax_post(.*?)$HTML::Processor::syntax_preLOOP END$HTML::Processor::syntax_post(.*)\Z/ism) 0 0 0
728 0 my $it_pre = $1; # data before the loop block
729 0 my $it_name = $2; # name of loop
730 0 my $data = $3; # loop data to process
731 0 my $it_post = $4; # data after the loop block
732
733 # insert place holders
734 0 $$template_ref = $it_pre."[LOOP:'$it_name']".$it_post;
735 0 ▶ $self->debug("parse",1,"<b>loop</b>: <b>$it_name</b> not found in object") unless ( $self->{ LOOPS }{ $it_name } || $self->{ NESTS }{ $it_name });
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"LOOPS"}{$it_name} or $self->{"NESTS"}{$it_name} 0 0 0
Condition0%0/3
$self->{"LOOPS"}{$it_name} or $self->{"NESTS"}{$it_name}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"LOOPS"}{$it_name} or $self->{"NESTS"}{$it_name}
$self->{"LOOPS"}{$it_name} $self->{"NESTS"}{$it_name}
Truth table0%0/3
A or B
A= $self->{"LOOPS"}{$it_name}B= $self->{"NESTS"}{$it_name}
ABresult
1X1
011
000
736 # push loop block to named hash of arrays,
737 # allows for multiple loops of the same name
738 0 push @{ $self->{ IT_STACK }->{$it_name} }, $data;
739 }
740
741  
742 0 my (%multi);
743 # add looped content to template
744 0 ▶ while ($$template_ref =~ m/\A(.*)\[LOOP:'([\w\d-]+)'\](.*)\Z/msi){
Branch: 1 branch
BranchTrueFalseTotal
if ($$template_ref =~ /\A(.*)\[LOOP:'([\w\d-]+)'\](.*)\Z/ism) 0 0 0
745 0 my $pre = $1;
746 0 my $iter = $2;
747 0 my $post = $3;
748  
749 # log duplicate loops
750 0 $multi{$iter}++;
751 # go iterate over loop
752 0 $$template_ref = $pre.$self->iterate_loop( $iter, $self->{ IT_STACK }->{$iter}[$multi{$iter}-1] ).$post;
753 }
754 }
755  
756 #=====================================
757 # loop processing
758 #=====================================
759 #my (%parents);
760 0 ▶sub iterate_loop {
Subroutine iterate_loop: not called CC=26 SCAR=65.5
Pod undocumented
761 0 my $self = shift;
762 0 my $it_name = shift;
763 0 my $dat_ref = shift;
764 0 my $p_count = shift;
765 0 my ($iterated);
766 0 my $input_name = $it_name;
767  
768 # initialise position counter
769 # start at -1 so ++ on first pass gives 0
770 #if(!exists $parents{$input_name}){ $parents{$input_name} = -1 };
771 0 ▶ $self->{ PARENTS }{$input_name} = $self->{ PARENTS }{$input_name} || -1;
Condition0%0/2
$self->{'PARENTS'}{$input_name} || -1
l!l
00
MC/DC0%0/1
$self->{'PARENTS'}{$input_name} || -1
$self->{'PARENTS'}{$input_name}
Truth table0%0/2
A
A= $self->{'PARENTS'}{$input_name}
Aresult
11
00
772  
773 # if we are processing a nest - indicated by passed value for
774 # 'p_count' (parent counter)
775 0 ▶ if($p_count ne ''){
Branch: 1 branch
BranchTrueFalseTotal
if ($p_count ne "") 0 0 0
776 # use sort keys for position if we have a sorted parent
777 0 ▶ my $position = ( $self->{ SKEYS } ) ? $self->{ SKEYS }[$p_count] : $p_count;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'SKEYS'} ? : 0 0 0
778 0 my $it_key = $self->{ NESTS }->{$it_name}->{ KEYS }[$position];
779 0 $it_name = "${it_name}~${it_key}";
780 }
781  
782 0 my $max_count = 0;
783 # get the longest array for this loop
784 0 foreach (keys %{ $self->{ LOOPS }->{$it_name} }){
785 0 ▶ if(ref $self->{ LOOPS }->{$it_name}->{$_} eq "ARRAY"){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"LOOPS"}{$it_name}{$_} eq "ARRAY") 0 0 0
786 0 my $a_length = @{$self->{ LOOPS }->{$it_name}->{$_}};
787 0 ▶ $max_count = $a_length if ( $a_length > $max_count );
Branch: 1 branch
BranchTrueFalseTotal
if $a_length > $max_count 0 0 0
788 }
789 }
790  
791 # loop for the length of the longest array
792 0 ▶ for (my $count = 0; $count < $max_count; $count++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count < $max_count) 0 0 0
793 0 my $loop = $dat_ref; # deref & scope loop data
794 0 ▶ while ($loop =~ m/\A(.*)${syntax_pre}array='([\w\d-]*)'${syntax_post}(.*)\Z/msi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop =~ /\A(.*)$HTML::Processor::syntax_prearray='([\w\d-]*)'$HTML::Processor::syntax_post(.*)\Z/ism) 0 0 0
795 0 my $ins_pre = $1;
796 0 my $ins_name = $2;
797 0 my $ins_post = $3;
798
799 0 my $it_val = $self->{ LOOPS }->{$it_name}->{$ins_name}[$count];
800 0 ▶ $it_val = $self->escape_html($it_val) if $self->{ ESCAPE };# ***
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ESCAPE"} 0 0 0
801 # build the output for this instance
802 0 $loop = $ins_pre.$it_val.$ins_post;
803 }
804 # increment the count for this pass
805 0 $self->{ PARENTS }{$input_name}++;
806
807 # Loop Option processing
808 #---------------------------------------------------
809 0 ▶ while ($loop =~ m/\A(.*)${syntax_pre}LOOP OPTION name(!=|=)'([\w\d-]*)'${syntax_post}(.*?)${syntax_pre}LOOP OPTION END${syntax_post}(.*)\Z/msi){
Branch: 1 branch
BranchTrueFalseTotal
if ($loop =~ /\A(.*)$HTML::Processor::syntax_preLOOP OPTION name(!=|=)'([\w\d-]*)'$HTML::Processor::syntax_post(.*?)$HTML::Processor::syntax_preLOOP OPTION END$HTML::Processor::syntax_post(.*)\Z/ism) 0 0 0
810 0 my $opt_pre = $1;
811 0 my $opt_type = $2;
812 0 my $opt_name = $3;
813 0 my $opt_data = $4;
814 0 my $opt_post = $5;
815 0 my $opt_itr_val;
816
817 # check if there is an explicit options setting
818 0 ▶ if(exists $self->{ LOOPS }->{$it_name}->{ OPTIONS }->{$opt_name}){
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'LOOPS'}{$it_name}{'OPTIONS'}{$opt_name}) { } 0 0 0
elsif (exists $self->{'LOOPS'}{$it_name}{$opt_name}) { } 0 0 0
819 0 $opt_itr_val = $self->{ LOOPS }->{$it_name}->{ OPTIONS }->{$opt_name}[$count];
820 }
821 # otherwise look for the 'array' in the current loop
822 elsif(exists $self->{ LOOPS }->{$it_name}->{$opt_name}){
823 0 $opt_itr_val = $self->{ LOOPS }->{$it_name}->{$opt_name}[$count];
824 }
825 else {
826 0 $self->debug("process",2,"The loop option: '$opt_name' cannot be found");
827 }
828
829 # if the option variable is true
830 0 ▶ if ($opt_itr_val && $opt_type eq "="){
Branch: 2 branches
BranchTrueFalseTotal
if ($opt_itr_val and $opt_type eq '=') { } 0 0 0
elsif (not $opt_itr_val and $opt_type eq '!=') { } 0 0 0
Condition0%0/3
$opt_itr_val and $opt_type eq "="
!ll&&!rl&&r
000
MC/DC0%0/2
$opt_itr_val and $opt_type eq "="
$opt_itr_val $opt_type eq "="
Truth table0%0/3
A and B
A= $opt_itr_valB= $opt_type eq "="
ABresult
0X0
100
111
831 0 $loop = $opt_pre.$opt_data.$opt_post;
832 }
833 # if the option variable is not true
834 ▶ elsif (!$opt_itr_val && $opt_type eq "!="){
Condition0%0/3
not $opt_itr_val and $opt_type eq "!="
!ll&&!rl&&r
000
MC/DC0%0/2
not $opt_itr_val and $opt_type eq "!="
not $opt_itr_val $opt_type eq "!="
Truth table0%0/3
not(A) and B
A= not $opt_itr_valB= $opt_type eq "!="
ABresult
0X0
100
111
835 0 $loop = $opt_pre.$opt_data.$opt_post;
836 }
837 else {
838 # loose the optional content
839 0 $loop = $opt_pre.$opt_post;
840 }
841 }
842 # Loop if/else processing
843 #---------------------------------------------------------
844 0 ▶ while ( $loop =~ m/\A(.*)${syntax_pre}LOOP IF (\w+)([ =!<>]+)'([\w-]*)'${syntax_post}(.*?)(${syntax_pre}LOOP ENDIF${syntax_post})(.*)\Z/msi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop =~ /\A(.*)$HTML::Processor::syntax_preLOOP IF (\w+)([ =!<>]+)'([\w-]*)'$HTML::Processor::syntax_post(.*?)($HTML::Processor::syntax_preLOOP ENDIF$HTML::Processor::syntax_post)(.*)\Z/ism) 0 0 0
845 0 my $if_pre = $1; # pre if data
846 0 my $fs_var = $2; # first if variable
847 0 my $fs_oper = $3; # first if operand
848 0 my $fs_val = $4; # first value to test
849 0 my $if_cont = $5; # block to do work on
850 0 my $if_end = $6; # [ENDIF] end of string
851 0 my $if_post = $7; # rest of template
852 0 my $if_output = '';
853  
854 # test if the first is true
855 0 ▶ if ( $self->compare( $fs_oper, $self->{LOOPS}->{$it_name}->{$fs_var}[$count], $fs_val ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->compare($fs_oper, $self->{'LOOPS'}{$it_name}{$fs_var}[$count], $fs_val)) { } 0 0 0
856 0 ▶ $if_cont =~ s/(.*?)${syntax_pre}LOOP (ELSIF|ELSE).*\Z/$1/msi if $if_cont =~ /${syntax_pre}LOOP (ELSIF|ELSE)/msi;
Branch: 1 branch
BranchTrueFalseTotal
if $if_cont =~ /$HTML::Processor::syntax_preLOOP (ELSIF|ELSE)/ism 0 0 0
857 0 $if_output = $if_cont;
858 }
859 # loop through remaining tests
860 else {
861 0 my $if_data = $if_cont . $if_end;
862  
863 # evaluate each ELSIF|ELSE
864 0 ▶ while ( $if_data =~ m/${syntax_pre}LOOP (ELSIF|ELSE)(| (\w+)([ =!<>]+)'([\w-]*)')${syntax_post}(.*?)(${syntax_pre}LOOP (ELSIF|ELSE|ENDIF).*)\Z/msi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($if_data =~ /$HTML::Processor::syntax_preLOOP (ELSIF|ELSE)(| (\w+)([ =!<>]+)'([\w-]*)')$HTML::Processor::syntax_post(.*?)($HTML::Processor::syntax_preLOOP (ELSIF|ELSE|ENDIF).*)\Z/ism) 0 0 0
865 0 my $if_type = $1; # clause type (IF|ELSIF|ELSE)
866 0 my $if_var = $3; # value to test
867 0 my $oper = $4; # if operator
868 0 my $if_val = $5; # value to test
869 0 my $if_content = $6; # output for the block
870 0 my $if_tail = $7; # following IF/ELSE clauses
871  
872 # evaluate clauses
873 0 ▶ if ( $if_type =~ /ELSIF|IF/ && $self->compare( $oper, $self->{LOOPS}->{$it_name}->{$if_var}[$count], $if_val ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($if_type =~ /ELSIF|IF/ and $self->compare($oper, $self->{'LOOPS'}{$it_name}{$if_var}[$count], $if_val)) { } 0 0 0
elsif ($if_type =~ /ELSE/) { } 0 0 0
Condition0%0/3
$if_type =~ /ELSIF|IF/ and $self->compare($oper, $self->{"LOOPS"}{$it_name}{$if_var}[$count], $if_val)
!ll&&!rl&&r
000
MC/DC0%0/2
$if_type =~ /ELSIF|IF/ and $self->compare($oper, $self->{"LOOPS"}{$it_name}{$if_var}[$count], $if_val)
$if_type =~ /ELSIF|IF/ $self->compare($oper, $self->{"LOOPS"}{$it_name}{$if_var}[$count], $if_val)
Truth table0%0/3
A and B
A= $if_type =~ /ELSIF|IF/B= $self->compare($oper, $self->{"LOOPS"}{$it_name}{$if_var}[$count], $if_val)
ABresult
0X0
100
111
874 0 $if_output = $if_content;
875 0 last; # exit if there's a match
876 }
877 # use the else if above fails
878 elsif ( $if_type =~ /ELSE/ ) {
879 0 $if_output = $if_content;
880 }
881 # truncate the sring each loop by what we just tested
882 0 $if_data = $if_tail;
883 }
884 }
885 0 $loop = $if_pre . $if_output . $if_post;
886 }
887
888 # Nested Loop processing (recursive)
889 #---------------------------------------------------------
890 0 my %nest_multi;
891 0 ▶ while ($loop =~ /\A(.*)\[LOOP:'([\w\d-]+)'\](.*)\Z/msi){
Branch: 1 branch
BranchTrueFalseTotal
if ($loop =~ /\A(.*)\[LOOP:'([\w\d-]+)'\](.*)\Z/ism) 0 0 0
892 0 my $curr_pre = $1;
893 0 my $curr_nst = $2;
894 0 my $curr_post = $3;
895
896 0 ▶ $self->debug("parse",1,"<b>loop</b>: <b>$it_name</b> not found in object") unless $self->{ LOOPS }{ $it_name };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"LOOPS"}{$it_name} 0 0 0
897
898 # handle duplicate naming of nested loops
899 0 $nest_multi{$curr_nst}++ ;
900 0 my $thisdata = $self->iterate_loop( $curr_nst, $self->{ IT_STACK }->{$curr_nst}[$nest_multi{$curr_nst}-1], $self->{ PARENTS }{$input_name} );
901 0 $loop = $curr_pre . $thisdata . $curr_post;
902
903 }
904 # add to iterated content
905 0 $iterated .= $loop;
906 }
907 0 return $iterated;
908 }
909  
910 #=====================================
911 # replace normal variables
912 #=====================================
913 0 ▶sub do_variables {
Subroutine do_variables: not called CC=2 SCAR=17.9
Pod undocumented
914 0 my $self = shift;
915 0 my $template_ref = shift;
916  
917 0 ▶ $$template_ref =~ s/${syntax_pre}variable='([\d\w-]+)'${syntax_post}/$self->{ ESCAPE } ? $self->escape_html($self->variable($1)) : ($self->variable($1) )/eg;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ESCAPE'} ? : 0 0 0
918 }
919  
920  
921 # encode html un-friendly entities
922 #----------------------------------
923 0 ▶sub escape_html {
Subroutine escape_html: not called CC=1 SCAR=6.9
Pod undocumented
924 0 my $self = shift;
925 0 my $data = shift;
926 0 my %esc = (
927 '"' => '&#34;',
928 '&' => '&#38;',
929 '<' => '&lt;',
930 '>' => '&gt;'
931 );
932 0 $data =~ s/([\"<>])/$esc{$1}/g;
933 0 return $data;
934 }
935  
936 #=====================================
937 # Clean spaces
938 #=====================================
939 0 ▶sub do_clean {
Subroutine do_clean: not called CC=2 SCAR=17.9
Pod undocumented
940 0 my $self = shift;
941 0 my $template_ref = shift;
942
943 # remove empty lines except in text areas
944 0 ▶ $$template_ref =~ s/\s+\n/\n/sg unless $$template_ref =~ /textarea(.*?)\s+\n(.*?)\/textarea/msi;
Branch: 1 branch
BranchTrueFalseTotal
unless $$template_ref =~ m[textarea(.*?)\s+\n(.*?)/textarea]ism 0 0 0
945 0 $$template_ref =~ s/\n\s+</\n</sg; # space before tag
946 }
947  
948 #=====================================
949 # perform comparisons
950 #=====================================
951 0 ▶sub compare {
Subroutine compare: not called CC=21 SCAR=61.4
Pod undocumented
952 0 my $self = shift;
953 0 my $oper = shift;
954 0 ▶ my $left = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
955 0 ▶ my $right = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
956 0 $oper =~ s/ //g;
957  
958 0 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if ($oper eq '=' and $left eq $right or $oper eq '==' and $left eq $right or $oper eq '!=' and $left ne $right or $oper eq '<' and $left < $right or $oper eq '<=' and $left <= $right or $oper eq '>' and $left > $right or $oper eq '>=' and $left >= $right or $oper eq 'LIKE' and $left =~ /$right/ or $oper eq 'NOTLIKE' and not $left =~ /$right/) { } 0 0 0
Condition0%0/51
$oper eq "=" and $left eq $right or $oper eq "==" and $left eq $right or $oper eq "!=" and $left ne $right or $oper eq "<" and $left < $right or $oper eq "<=" and $left <= $right or $oper eq ">" and $left > $right or $oper eq ">=" and $left >= $right or $oper eq "LIKE" and $left =~ /$right/ or $oper eq "NOTLIKE" and not $left =~ /$right/
l!l&&r!l&&!r
000
$oper eq "=" and $left eq $right or $oper eq "==" and $left eq $right or $oper eq "!=" and $left ne $right or $oper eq "<" and $left < $right or $oper eq "<=" and $left <= $right or $oper eq ">" and $left > $right or $oper eq ">=" and $left >= $right or $oper eq "LIKE" and $left =~ /$right/
l!l&&r!l&&!r
000
$oper eq "=" and $left eq $right or $oper eq "==" and $left eq $right or $oper eq "!=" and $left ne $right or $oper eq "<" and $left < $right or $oper eq "<=" and $left <= $right or $oper eq ">" and $left > $right or $oper eq ">=" and $left >= $right
l!l&&r!l&&!r
000
$oper eq "=" and $left eq $right or $oper eq "==" and $left eq $right or $oper eq "!=" and $left ne $right or $oper eq "<" and $left < $right or $oper eq "<=" and $left <= $right or $oper eq ">" and $left > $right
l!l&&r!l&&!r
000
$oper eq "=" and $left eq $right or $oper eq "==" and $left eq $right or $oper eq "!=" and $left ne $right or $oper eq "<" and $left < $right or $oper eq "<=" and $left <= $right
l!l&&r!l&&!r
000
$oper eq "=" and $left eq $right or $oper eq "==" and $left eq $right or $oper eq "!=" and $left ne $right or $oper eq "<" and $left < $right
l!l&&r!l&&!r
000
$oper eq "=" and $left eq $right or $oper eq "==" and $left eq $right or $oper eq "!=" and $left ne $right
l!l&&r!l&&!r
000
$oper eq "=" and $left eq $right or $oper eq "==" and $left eq $right
l!l&&r!l&&!r
000
$oper eq "=" and $left eq $right
!ll&&!rl&&r
000
$oper eq "==" and $left eq $right
!ll&&!rl&&r
000
$oper eq "!=" and $left ne $right
!ll&&!rl&&r
000
$oper eq "<" and $left < $right
!ll&&!rl&&r
000
$oper eq "<=" and $left <= $right
!ll&&!rl&&r
000
$oper eq ">" and $left > $right
!ll&&!rl&&r
000
$oper eq ">=" and $left >= $right
!ll&&!rl&&r
000
$oper eq "LIKE" and $left =~ /$right/
!ll&&!rl&&r
000
$oper eq "NOTLIKE" and not $left =~ /$right/
!ll&&!rl&&r
000
MC/DC0%0/18
$oper eq "=" and $left eq $right or $oper eq "==" and $left eq $right or $oper eq "!=" and $left ne $right or $oper eq "<" and $left < $right or $oper eq "<=" and $left <= $right or $oper eq ">" and $left > $right or $oper eq ">=" and $left >= $right or $oper eq "LIKE" and $left =~ /$right/ or $oper eq "NOTLIKE" and not $left =~ /$right/
too many conditions
959 ( $oper eq "=" && $left eq $right ) ||
960 ( $oper eq "==" && $left eq $right ) ||
961 ( $oper eq "!=" && $left ne $right ) ||
962 ( $oper eq "<" && $left < $right ) ||
963 ( $oper eq "<=" && $left <= $right ) ||
964 ( $oper eq ">" && $left > $right ) ||
965 ( $oper eq ">=" && $left >= $right ) ||
966 ( $oper eq "LIKE" && $left =~ m/$right/ ) ||
967 ( $oper eq "NOTLIKE" && $left !~ m/$right/ )
968 0 ) { return 1; }
969 0 else { return 0; }
970 }
971  
972 #=====================================
973 # debug template data
974 #=====================================
975 1 my $error_count;
976 0 ▶sub debug {
Subroutine debug: not called CC=3 SCAR=24.8
Pod undocumented
977 0 my $self = shift;
978 0 my $type = shift;
979 0 my $level = shift;
980 0 my $msg = shift;
981
982 0 $$error_count++;
983 # get caller data
984 0 my( $file, $line, $pack, $sub ) = id(2);
985
986 0 ▶ if( !$level ) { print "no debug level at: at $file line $line"; exit; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($level) 0 0 0
987
988 # insert the error in to the object hash
989 0 $self->{ DEBUG }{ $level }{ $type }{ $$error_count }{ MSG } = $msg;
990 0 $self->{ DEBUG }{ $level }{ $type }{ $$error_count }{ SUB } = $sub;
991 0 $self->{ DEBUG }{ $level }{ $type }{ $$error_count }{ LOC } = "at $file line $line";
992
993 # HIGH level debugging: print error and exit
994 #---------------------------------
995 0 ▶ if ( $level == $self->{DEBUG_LEVELS}{'Fatal'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == $self->{"DEBUG_LEVELS"}{"Fatal"}) 0 0 0
996 0 print $self->build_err($self->{DEBUG_LEVELS}{'Fatal'});
997 0 exit;
998 }
999  
1000 }
1001 #===============================
1002 # format error data
1003 #===============================
1004 0 ▶sub build_err {
Subroutine build_err: not called CC=7 SCAR=40.3
Pod undocumented
1005 0 my $self = shift;
1006 0 my $level = shift;
1007
1008 # possible error types
1009 0 my %error_types = (
1010 param => "setup parameter",
1011 file => "file open / close / print",
1012 process => "building object data",
1013 parse => "parsing the html temlate"
1014 );
1015 0 ▶ my $level_type = $level || $self->{ DEBUG_LEVEL };
Condition0%0/3
$level || $self->{'DEBUG_LEVEL'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$level || $self->{'DEBUG_LEVEL'}
$level $self->{'DEBUG_LEVEL'}
Truth table0%0/3
A || B
A= $levelB= $self->{'DEBUG_LEVEL'}
ABresult
1X1
011
000
1016  
1017 # Shameless use of html for 'pretty' debugging
1018 # The module is, after all HTML::Processor
1019 0 my $error = qq|
1020 <style>
1021 .errlabel{ font: bold 12px verdana; }
1022 .errdata { font: normal 12px verdana; }
1023 .errhead { font: bold 14px verdana; border:1px solid #DDDDDD; background-color:#EEEEEE;}
1024 </style>
1025 <table border="0" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF" align="center">
1026 <tr><td colspan="2" class="errlabel"><font size="4">Template Processing Debug Info:</font></td></tr>
1027 |;
1028 0 ▶ if( $$error_count == 0 ) { $error .= qq|<tr><td colspan="2" class="errlabel" bgcolor="#d7fbd8">No bugs to report</td></tr>|; }
Branch: 1 branch
BranchTrueFalseTotal
if ($$error_count == 0) 0 0 0
1029 0 my %level_key = reverse %{ $self->{DEBUG_LEVELS} };
1030 0 foreach my $err_lvl(sort {{$b} <=> {$a}} keys %{ $self->{ DEBUG } } ){
1031
1032 # debug up to & including given level
1033 0 ▶ if($err_lvl >= $level_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err_lvl >= $level_type) 0 0 0
1034
1035 0 foreach my $err_typ(keys %{ $self->{ DEBUG }{ $err_lvl } } ){
1036
1037 0 $error .= qq|<tr><td colspan="2" class="errhead">GROUP: [$error_types{$err_typ}] LEVEL: $level_key{$err_lvl}</td></tr>|;
1038
1039 0 foreach my $err_num(sort {{$a} <=> {$b}} keys %{ $self->{ DEBUG }{ $err_lvl }{ $err_typ } } ){
1040 $error .= "<tr><td class=\"errlabel\" align=\"right\"><b>sub:</b></td><td class=\"errdata\">" .
1041 $self->{ DEBUG }{ $err_lvl }{ $err_typ }{ $err_num } { SUB } .
1042 "</td></tr>" .
1043 "<tr><td class=\"errlabel\" align=\"right\"><b>what:</b></td><td class=\"errdata\" bgcolor=\"#eee2bf\">" .
1044 $self->{ DEBUG }{ $err_lvl }{ $err_typ }{ $err_num } { MSG } .
1045 "</td></tr>" .
1046 "<tr><td class=\"errlabel\" align=\"right\"><b>where:</b></td><td class=\"errdata\">" .
1047 $self->{ DEBUG }{ $err_lvl }{ $err_typ }{ $err_num } { LOC } .
1048 0 "</td></tr><tr><td colspan=\"2\"><hr size=\"1\" color=\"#808080\"></td></tr>\n";
1049 }
1050 0 $error .= qq|<tr><td colspan="2"> </td></tr>|;
1051 }
1052 }
1053 }
1054 0 $error .= qq|
1055 </table>
1056 |;
1057 0 return $error;
1058 }
1059 #===============================
1060 # get error location data
1061 #===============================
1062 0 ▶sub id {
Subroutine id: not called CC=1 SCAR=6.9
Pod undocumented
1063 0 my $level = shift;
1064 0 my ( $pack, $file, $line, $sub ) = caller($level);
1065 0 my ( $id ) = $file =~ m|([^/]+)\z|;
1066 0 return ( $file, $line, $pack, $sub );
1067 }
1068  
1069  
1070 package HTML::Processor::Loop;
1071  
1072 #----------------------------------------------
1073 # Constructor for Loop Object
1074 #----------------------------------------------
1075 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
1076 0 my $proto = shift;
1077  
1078 0 ▶ my $class = ref( $proto ) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
1079 0 my $self = {};
1080  
1081 0 bless( $self, $class );
1082 0 return $self;
1083 }
1084  
1085 #----------------------------------------------
1086 # iterarion array method
1087 #----------------------------------------------
1088 0 ▶sub array {
Subroutine array: not called CC=1 SCAR=6.9
1089 0 my $self = shift;
1090 0 my ( $name, $val ) = @_;
1091
1092 0 push @{ $self->{$name} }, $val;
1093  
1094 }
1095  
1096  
1097 #----------------------------------------------
1098 # build loop options
1099 #----------------------------------------------
1100 0 ▶sub option {
Subroutine option: not called CC=1 SCAR=6.9
1101 0 my $self = shift;
1102 0 my $name = shift;
1103 0 my $val = shift;
1104 0 my $posit = shift;
1105  
1106 0 push @{ $self->{ OPTIONS }->{$name} }, $val;
1107 0 return $self->{ OPTIONS }->{$name};
1108 }
1109 1 1;
1110  
1111 __END__
↑ Summary