Graph.pm

filter: Statementstmt 57.9% 256 / 442 Branchbran 54.7% 104 / 190 Conditioncond 53.7% 29 / 54 MC/DCmcdc 32.2% 10 / 31 Subroutinesub 51.4% 18 / 35 Podpod 0.0% 0 / 29 totaltotal 53.3% 417 / 781 CC 127 SCAR 34.8
CC
127
Cov
57%
removematch
182.0
listmatch
90.0
_print
33.7
CRAP 32.6
↑ Summary Path.pm »
1 # Graph.pm
2 # This class implements a nested named list.
3 # author 'Rolf Veen'
4 # license zlib
5 # date 20030609
6 # Modified by Hui Zhou <zhouhui@wam.umd.edu>
7  
8 package OGDL::Graph;
9  
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 2 ▶use OGDL::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 154 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
17 154 my ($class,$name)=@_;
18 154 my $rec = {
19 parent=>undef,
20 name => $name,
21 list => [ () ]
22 };
23 # print "New Graph node: [$name]\n";
24 154 return bless $rec,$class;
25 }
26  
27 #$g->addGraph($name); append node with name=$name
28 0 ▶sub addGraph {
Subroutine addGraph: not called CC=1 SCAR=6.9
Pod undocumented
29 0 my ($self,$name) = @_;
30 0 my $n=OGDL::Graph->new($name);
31 0 $self->addNode($n);
32 0 return $n;
33 }
34 #$g->addNode($sub); append node to the end
35 160 ▶sub addNode {
Subroutine addNode: called CC=1 SCAR=0.0
Pod undocumented
36 160 my ($self,$node) = @_;
37 160 my $list = $self->{list};
38 160 my $len = @$list;
39 160 $node->{parent}=$self;
40 160 $self->{list}[$len] = $node;
41 # print "Adding node: [",$node->{name},"]\n";
42 }
43  
44 0 ▶sub merge{
Subroutine merge: not called CC=2 SCAR=17.9
Pod undocumented
45 0 my ($self,$node)=@_;
46 0 my $list1=$self->{"list"};
47 0 my $list2=$node->{"list"};
48 0 ▶ if(!$list2){return;}
Branch: 1 branch
BranchTrueFalseTotal
unless ($list2) 0 0 0
49 0 push @$list1, @$list2;
50 }
51  
52 0 ▶sub unlink{
Subroutine unlink: not called CC=3 SCAR=24.8
Pod undocumented
53 0 my $node=shift;
54 0 my $parent=$node->{"parent"};
55 0 $node->{"parent"}=undef;
56 0 my $j=0;
57 0 my $l=$$parent{"list"};
58 0 ▶ while($j<=$#$l){
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $l->$#*) 0 0 0
59 0 ▶ if($$l[$j]==$node){
Branch: 1 branch
BranchTrueFalseTotal
if ($l->[$j] == $node) 0 0 0
60 0 splice @$l,$j,1;
61 0 return;
62 }
63 0 $j++;
64 }
65 }
66  
67 1 ▶sub getname{
Subroutine getname: called CC=2 SCAR=7.6
Pod undocumented
68 1 my $node=get(@_);
69 0 ▶ if(!$node){return undef;}
Branch: 1 branch
BranchTrueFalseTotal
unless ($node) 0 1 1
70 1 return $$node{"name"};
71 }
72  
73 0 ▶sub childrencount{
Subroutine childrencount: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my $g=shift;
75 0 my $list=$$g{"list"};
76 0 return scalar @$list;
77 }
78  
79 0 ▶sub getChildren{
Subroutine getChildren: not called CC=1 SCAR=6.9
Pod undocumented
80 0 my $g=shift;
81 0 my $list=$$g{"list"};
82 0 return @$list;
83 }
84  
85 0 ▶sub isempty{
Subroutine isempty: not called CC=1 SCAR=6.9
Pod undocumented
86 0 my $g=shift;
87 0 my $l=$$g{"list"};
88 0 return (! scalar(@$l));
89 }
90
91 0 ▶sub clear{
Subroutine clear: not called CC=2 SCAR=17.9
Pod undocumented
92 0 my $g=shift;
93 0 my $l=$$g{"list"};
94 0 foreach(@$l){
95 0 $_->{"parent"}=undef;
96 }
97 0 $$g{"list"}=[ () ];
98 }
99  
100 #Not sure how to deal with the order
101 #sub diff{
102 # my ($g1,$g2)=@_;
103 # my ($pg1,$pg2);
104 #}
105  
106 0 ▶sub listmatch{
Subroutine listmatch: not called CC=9 SCAR=45.0
Pod undocumented
107 0 my ($g,$list,$rnum,@path)=@_;
108 0 my $inum=-1; #match all index
109 0 my $namepat;
110 0 my $pat=shift @path;
111 0 ▶ if($pat=~/(.*)(\[(\d*)\])/){
Branch: 1 branch
BranchTrueFalseTotal
if ($pat =~ /(.*)(\[(\d*)\])/) { } 0 0 0
112 0 ▶ if($3 eq ""){$inum=-1;}
Branch: 1 branch
BranchTrueFalseTotal
if ($3 eq '') { } 0 0 0
113 0 else{$inum=$3;}
114 0 ▶ if($1 eq ""){$namepat="^*\$";}
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq '') { } 0 0 0
115 0 else{$namepat="^$1\$";}
116 }
117 else{
118 0 $inum=-1;
119 0 $namepat="^$pat\$";
120 }
121 0 $namepat=~s/\*/\.\*/g;
122 0 $namepat=~s/\?/\./g;
123 0 $inum++;
124
125 # print "listmatch ",$$g{"name"},"=~$namepat\n";
126 0 ▶ if($$g{"name"}=~/$namepat/){
Branch: 1 branch
BranchTrueFalseTotal
if ($g->{"name"} =~ /$namepat/) 0 0 0
127 0 $$rnum=$$rnum+1;
128 # print "Match: ",$$rnum,", $inum, (",$#path,")\n";
129 0 ▶ if($inum>0 && $$rnum!=$inum){ #index doesn't match
Branch: 1 branch
BranchTrueFalseTotal
if ($inum > 0 and $$rnum != $inum) 0 0 0
Condition0%0/3
$inum > 0 and $$rnum != $inum
!ll&&!rl&&r
000
MC/DC0%0/2
$inum > 0 and $$rnum != $inum
$inum > 0 $$rnum != $inum
Truth table0%0/3
A and B
A= $inum > 0B= $$rnum != $inum
ABresult
0X0
100
111
130 0 return undef;
131 }
132 0 ▶ if($#path==-1){
Branch: 1 branch
BranchTrueFalseTotal
if ($#path == -1) 0 0 0
133 # print "Matched\n";
134 0 {push @$list,$g;return 1;} #matches finally
135 }
136 0 my $n=0;
137 0 my $l=$g->{list};
138 0 foreach(@$l){
139 0 $_->listmatch($list,\$n,@path);
140 }
141 }
142 }
143  
144 0 ▶sub glist{
Subroutine glist: not called CC=2 SCAR=17.9
Pod undocumented
145 0 my @list;
146 0 my ($g,$pathstr)=@_;
147 0 my @path=splitPath($pathstr);
148 0 ▶ if($#path<0){push @list,$g;return @list;}
Branch: 1 branch
BranchTrueFalseTotal
if ($#path < 0) 0 0 0
149 0 unshift @path,"*";
150 0 my $n=0;
151 # my $j=0; foreach(@path){print "$j:[$_],";$j++;}print "\n";
152 0 listmatch($g,\@list,\$n,@path);
153 0 return @list;
154 }
155  
156 0 ▶sub removematch{
Subroutine removematch: not called CC=13 SCAR=52.0
Pod undocumented
157 0 my ($g,$list,@path)=@_;
158 0 my $inum=-1; #match all index
159 0 my $namepat;
160 0 my $pat=shift @path;
161 0 ▶ if($pat=~/(.*)(\[(\d*)\])/){
Branch: 1 branch
BranchTrueFalseTotal
if ($pat =~ /(.*)(\[(\d*)\])/) { } 0 0 0
162 0 ▶ if($3 eq ""){$inum=-1;}
Branch: 1 branch
BranchTrueFalseTotal
if ($3 eq '') { } 0 0 0
163 0 else{$inum=$3;}
164 0 ▶ if($1 eq ""){$namepat="^*\$";}
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq '') { } 0 0 0
165 0 else{$namepat="^$1\$";}
166 }
167 else{
168 0 $inum=-1;
169 0 $namepat="^$pat\$";
170 }
171 0 $namepat=~s/\*/\.\*/g;
172 0 $namepat=~s/\?/\./g;
173 0 ▶ if($inum>=0){$inum++;}
Branch: 1 branch
BranchTrueFalseTotal
if ($inum >= 0) 0 0 0
174
175 0 my $j=0;
176 0 my $num=0;
177 0 my $l=$g->{"list"};
178 0 my $n=$$l[$j];
179 0 ▶ while($n){
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 0 0
180 # print "removematch ",$$n{"name"},"=~/$namepat/\n";
181 0 ▶ if($$n{"name"}=~/$namepat/){
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{'name'} =~ /$namepat/) { } 0 0 0
182 0 $num++;
183 # print "Match :$num, $inum\n";
184 0 ▶ if($inum>=0 && $num!=$inum){ #index doesn't match
Branch: 1 branch
BranchTrueFalseTotal
if ($inum >= 0 and $num != $inum) { } 0 0 0
Condition0%0/3
$inum >= 0 and $num != $inum
!ll&&!rl&&r
000
MC/DC0%0/2
$inum >= 0 and $num != $inum
$inum >= 0 $num != $inum
Truth table0%0/3
A and B
A= $inum >= 0B= $num != $inum
ABresult
0X0
100
111
185 0 $j++;
186 }
187 else{
188 0 {my $j=0; foreach(@path){print "$j:[$_],";$j++;}print "\n";}
189 0 ▶ if($#path==-1){
Branch: 1 branch
BranchTrueFalseTotal
if ($#path == -1) { } 0 0 0
190 0 push @$list,$n;
191 0 splice(@$l,$j,1);
192 0 ▶ if($inum>=0){ last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($inum >= 0) { } 0 0 0
193 else{
194 0 $num++;
195 }
196 }
197 else{
198 0 removematch($n,$list,@path);
199 0 ▶ if($inum>=0){last;}
Branch: 1 branch
BranchTrueFalseTotal
if ($inum >= 0) 0 0 0
200 0 $j++;
201 }
202 }
203 }
204 else{
205 0 $j++;
206 }
207 0 $n=$$l[$j];
208 }
209 }
210  
211 0 ▶sub gremove{
Subroutine gremove: not called CC=3 SCAR=24.8
Pod undocumented
212 0 my ($g,$pathstr)=@_;
213 0 my @path=splitPath($pathstr);
214 0 ▶ if($#path<0){unshift @path,"*";}
Branch: 1 branch
BranchTrueFalseTotal
if ($#path < 0) 0 0 0
215 0 my @list;
216 0 ▶ if($#path<0){return $g;}
Branch: 1 branch
BranchTrueFalseTotal
if ($#path < 0) 0 0 0
217 0 removematch($g,\@list,@path);
218 0 return @list;
219 }
220  
221 0 ▶sub gmove{
Subroutine gmove: not called CC=2 SCAR=17.9
Pod undocumented
222 0 my ($g,$from,$to)=@_;
223 0 my @frompath=splitPath($from);
224 0 my @topath=splitPath($to);
225 0 my @remove=gremove($from);
226 0 foreach (@remove){
227 0 addmatch($g,$_,@topath);
228 }
229 }
230  
231 26 ▶sub addmatch{
Subroutine addmatch: called CC=16 SCAR=28.3
Pod undocumented
232 26 my ($g,$node,@path)=@_;
233 26 ▶ if($#path<0){
Branch: 1 branch
BranchTrueFalseTotal
if ($#path < 0) 9 17 26
234 9 ▶ if($node){
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 0 9 9
235 0 $g->clear;
236 0 $g->addNode($node)
237 };
238 9 return;
239 }
240 17 my $inum=-1; #match all index
241 17 my $uniq=1;
242 17 my $namepat;
243 17 my $pat=shift @path;
244 17 ▶ if($pat=~/(.*)(\[(\d*)\])/){
Branch: 1 branch
BranchTrueFalseTotal
if ($pat =~ /(.*)(\[(\d*)\])/) { } 1 16 17
245 0 ▶ if($3 eq ""){ $uniq=0;$inum=-1;}
Branch: 1 branch
BranchTrueFalseTotal
if ($3 eq '') { } 0 1 1
246 1 else{$inum=$3;}
247 0 ▶ if($1 eq ""){$namepat="*";}
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq '') { } 0 1 1
248 1 else{$namepat="$1";}
249 }
250 else{
251 16 $namepat="$pat";
252 }
253 17 ▶ if($namepat=~/[*?]/){
Branch: 1 branch
BranchTrueFalseTotal
if ($namepat =~ /[*?]/) 3 14 17
254 3 $namepat=~s/\*/\.\*/g;
255 3 $namepat=~s/\?/\./g;
256 3 $uniq=0;
257 }
258 17 ▶ if($inum>=0){$inum++;}
Branch: 1 branch
BranchTrueFalseTotal
if ($inum >= 0) 1 16 17
259
260 17 my $j=0;
261 17 my $num=0;
262 17 my $n=$g->{list}[$j];
263 17 my $exist=0;
264 17 ▶ while($n){
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 12 17 29
265 # print "addmatch ",$$n{"name"},"=~/^$namepat\$/\n";
266 12 ▶ if($$n{"name"}=~/^$namepat$/){
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"name"} =~ /^$namepat$/) 11 1 12
267 11 $num++;
268 # print "Match: $num, $inum\n";
269 11 ▶ if($inum<0 || $num==$inum){ # match
Branch: 1 branch
BranchTrueFalseTotal
if ($inum < 0 or $num == $inum) 11 0 11
Condition33%1/3
$inum < 0 or $num == $inum
l!l&&r!l&&!r
1100
MC/DC0%0/2
$inum < 0 or $num == $inum
$inum < 0 $num == $inum
Truth table33%1/3
A or B
A= $inum < 0B= $num == $inum
ABresult
1X1
011
000
270 11 $exist=1;
271 11 addmatch($n,$node,@path);
272 }
273 }
274 12 $j++;
275 12 $n=$g->{list}[$j];
276 }
277 17 ▶ if(!$exist && $uniq){
Branch: 1 branch
BranchTrueFalseTotal
if (not $exist and $uniq) 12 5 17
Condition66%2/3
not $exist and $uniq
!ll&&!rl&&r
5012
MC/DC50%1/2
not $exist and $uniq
not $exist $uniq
Truth table66%2/3
not(A) and B
A= not $existB= $uniq
ABresult
0X0
100
111
278 # print "Add $namepat?\n";
279 12 $j=$num;
280 12 ▶ if($inum<0){$inum=1;}
Branch: 1 branch
BranchTrueFalseTotal
if ($inum < 0) 11 1 12
281 12 ▶ while($j<$inum){
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $inum) 17 12 29
282 17 $n=OGDL::Graph->new($namepat);
283 17 $g->addNode($n);
284 17 $j++;
285 # print "Added node [$namepat]\n";
286 }
287 12 addmatch($n,$node,@path);
288 }
289 }
290  
291 3 ▶sub gadd{
Subroutine gadd: called CC=2 SCAR=7.2
Pod undocumented
292 3 my ($g,$pathstr,$str)=@_;
293 3 my @path=splitPath($pathstr);
294 # my $j=0;foreach(@path){print "$j:[$_],";$j++;}print "\n";
295 3 my $node=undef;
296 3 ▶ if($str){
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 0 3 3
297 0 $node=OGDL::Graph->new($str);
298 }
299 3 addmatch($g,$node,@path);
300 }
301  
302 # g->add(path, string)
303 # doesn't work with numeric indices
304 sub add
305 0 ▶{
Subroutine add: not called CC=1 SCAR=6.9
Pod undocumented
306 0 my ($g,$path,$string)=@_;
307 0 my $n=$g->get($path);
308 0 return $n->addGraph($string);
309 }
310  
311 #$g->getNode($index); return subnode by index
312 59 ▶sub getNode {
Subroutine getNode: called CC=1 SCAR=0.0
Pod undocumented
313 59 my $self = shift;
314 59 return $self->{list}[$_[0]];
315 }
316  
317 35 ▶sub getNodeByName {
Subroutine getNodeByName: called CC=3 SCAR=11.0
Pod undocumented
318 35 my $self = shift;
319 35 my $name = shift;
320
321 35 my $list = $self->{list};
322 35 my $i=0;
323
324 35 for (@$list) {
325 90 ▶ if ($_->{name} eq $name)
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"name"} eq $name) 35 55 90
326 35 { return $i; }
327 55 $i++;
328 }
329 0 return -1;
330 }
331  
332 # look for the nth ocurrence of a name
333  
334 5 ▶sub getNodeByNameN {
Subroutine getNodeByNameN: called CC=4 SCAR=13.9
Pod undocumented
335 5 my $self = shift;
336 5 my $name = shift;
337 5 my $n = shift;
338  
339 5 my $list = $self->{list};
340 5 my $i=0;
341
342 5 for (@$list) {
343 30 ▶ if ($_->{name} eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"name"} eq $name) 14 16 30
344 14 ▶ if ($n-- == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($n-- == 0) 5 9 14
345 5 { return $i; }
346 }
347 25 $i++;
348 }
349 0 return -1;
350 }
351  
352 # make a new Graph with all nodes with given name.
353  
354 2 ▶sub newGraphByName {
Subroutine newGraphByName: called CC=4 SCAR=13.9
Pod undocumented
355 2 my $self = shift;
356 2 my $name = shift;
357 2 my $list = $self->{list};
358 2 my $i=0;
359 2 my $g = OGDL::Graph->new($name);
360 2 my $list2;
361
362 2 for (@$list) {
363 14 ▶ if ($_->{name} eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"name"} eq $name) 6 8 14
364 6 $list2=$_->{list};
365 6 for (@$list2) {
366 12 $g->addNode($_);
367 }
368 }
369 14 $i++;
370 }
371 2 return $g;
372 }
373  
374 sub get
375 19 ▶{
Subroutine get: called CC=11 SCAR=24.4
Pod undocumented
376 19 my $self = shift;
377 19 my @path = OGDL::Path::path2list(shift);
378 19 my $node = $self;
379 19 my $i=0;
380 19 my $prev; # to distinguish between x[n] and x.[n] and hold the
381 # previous node
382
383 19 for (@path) {
384 0 ▶ if ( !$_ && $_ ne '0') { last; } # Whose bug is this ?
Branch: 1 branch
BranchTrueFalseTotal
if (not $_ and $_ ne 0) 0 96 96
Condition33%1/3
not $_ and $_ ne 0
!ll&&!rl&&r
9600
MC/DC0%0/2
not $_ and $_ ne 0
not $_ $_ ne 0
Truth table33%1/3
not(A) and B
A= not $_B= $_ ne 0
ABresult
0X0
100
111
385
386 96 ▶ if ($_ eq ".") { $prev=""; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq ".") 35 61 96
387  
388 # [n]?
389 61 ▶ if(/\[(\d*)\]/){
Branch: 1 branch
BranchTrueFalseTotal
if (/\[(\d*)\]/) { } 26 35 61
390 # if ( substr($_,0,1) eq '[') {
391 # $i = 0 + substr($_,1,100); # get the numeric index
392 26 ▶ if($1 eq ""){$i=0;}
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq '') { } 2 24 26
393 24 else{$i=$1;}
394
395 # if prev & i>0 then we must look for ith ocurrence
396 # of prev
397
398 # if prev & i==0 then we group all nodes with the same name
399 # as $node->{name} in a new Graph and continue from there.
400
401 26 ▶ if ( $prev ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev) 7 19 26
402 7 ▶ if ( $i > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i > 0) { } 5 2 7
elsif ($i == 0) { } 2 0 2
403 5 $i = $prev->getNodeByNameN($node->{name},$i);
404 5 $node = $prev->getNode($i);
405 5 $prev = 0;
406 5 next;
407 }
408 elsif ( $i == 0 ) {
409 2 $node = $prev->newGraphByName($node->{name});
410 2 $prev = 0;
411 2 next;
412 }
413 0 else { $i = -1; }
414 }
415 }
416 else {
417 35 $i = $node->getNodeByName($_);
418 }
419
420 0 ▶ if ($i == -1) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($i == -1) 0 54 54
421 54 $prev = $node;
422 54 $node = $node->getNode($i);
423 }
424
425 19 return $node;
426 }
427  
428 sub getGraph
429 0 ▶{
Subroutine getGraph: not called CC=1 SCAR=6.9
Pod undocumented
430 0 return get(@_);
431 }
432  
433 sub getScalar
434 0 ▶{
Subroutine getScalar: not called CC=3 SCAR=24.8
Pod undocumented
435 0 my $node = get(@_);
436 0 ▶ if ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 0 0 0
437 0 $node = $node->{list}[0];
438 0 ▶ if ($node)
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 0 0 0
439 0 { return $node->{name}; }
440 }
441 0 return undef;
442 }
443  
444  
445 #_print_str($name,$indent,$pending,$blockquote,$noquote,*FILE)
446 sub _print_str
447 132 ▶{
Subroutine _print_str: called CC=19 SCAR=29.8
448 132 my ($s,$n,$pending,$blockquote,$noquote,$sameline,$output)=@_;
449 #$pending = $_[2]; #Whether continuing at previous line or starting at begining of new line
450 #$blockquote=$_[3]; #Whether use \ quote or " quote
451 # see what type of string it is: word, quoted or block
452 132 ▶ if ($s =~ /[ \n\r]/) {#block
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /[ \n\r]/) { } 4 128 132
453 4 ▶ if($blockquote && $pending){
Branch: 1 branch
BranchTrueFalseTotal
if ($blockquote and $pending) { } 2 2 4
Condition66%2/3
$blockquote and $pending
!ll&&!rl&&r
202
MC/DC50%1/2
$blockquote and $pending
$blockquote $pending
Truth table66%2/3
A and B
A= $blockquoteB= $pending
ABresult
0X0
100
111
454 2 print $output " \\\n";
455 2 my $c;
456 2 my $pend=1;
457 2 print $output ' ' x $n; $pend = 0;
458 2 ▶ for (my $i=0;$i<length($s);$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $s) 1560 2 1562
459 1560 $c = substr($s,$i,1) ;
460 # if(!defined $c) {last;}
461 1560 ▶ if ( $pend == 1 ) { print $output ' ' x $n; $pend = 0;}
Branch: 1 branch
BranchTrueFalseTotal
if ($pend == 1) 24 1536 1560
462 1560 ▶ if ($c eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") 24 1536 1560
463 24 $pend = 1;
464 }
465 1560 print $output $c;
466 }
467 0 ▶ if($pend){$pending = 0;}
Branch: 1 branch
BranchTrueFalseTotal
if ($pend) { } 0 2 2
468 2 else{$pending=1;}
469 }
470 else{ #use double quote block
471 2 ▶ if($pending){
Branch: 1 branch
BranchTrueFalseTotal
if ($pending) 2 0 2
472 0 ▶ if($sameline){print $output ' ';}
Branch: 1 branch
BranchTrueFalseTotal
if ($sameline) { } 0 2 2
473 else{
474 2 print $output "\n";
475 2 print $output ' ' x $n;
476 }
477 }
478 2 my $c;
479 2 my $i=0;
480 2 my $pend=0;
481 2 ▶ if(!$noquote){ print $output '"';$n++;} #Opening quote
Branch: 1 branch
BranchTrueFalseTotal
unless ($noquote) 2 0 2
482 2 ▶ for (my $i=0;$i<length($s);$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $s) 1560 2 1562
483 1560 $c = substr($s,$i,1);
484 1560 ▶ if ( $pend == 1 ) { print $output ' ' x $n; $pend = 0;}
Branch: 1 branch
BranchTrueFalseTotal
if ($pend == 1) 24 1536 1560
485 1560 ▶ if ($c eq "\n") {
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq "\n") { } 24 1536 1560
elsif ($c eq '"' and not $noquote) { } 4 3064 3068
486 24 $pend = 1;
487 }
488 4 ▶ elsif($c eq '"' && !$noquote) { print $output "\\"; } #Quote the quote
Condition66%2/3
$c eq "\"" and not $noquote
!ll&&!rl&&r
153204
MC/DC50%1/2
$c eq "\"" and not $noquote
$c eq "\"" not $noquote
Truth table66%2/3
A and not(B)
A= $c eq "\""B= not $noquote
ABresult
0X0
100
111
489 1560 print $output $c;
490 }
491 2 ▶ if(!$noquote){print $output '"'; }#Closing quote
Branch: 1 branch
BranchTrueFalseTotal
unless ($noquote) 2 0 2
492 2 $pending = 1;
493 }
494 }
495 else {
496 128 ▶ if ($pending == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pending == 1) { } 119 9 128
497 119 ▶ if($sameline){
Branch: 1 branch
BranchTrueFalseTotal
if ($sameline) { } 0 119 119
498 0 print $output ' ';
499 }
500 else{
501 119 print $output "\n" ;
502 119 print $output ' ' x $n;
503 }
504 }
505 else{
506 9 print $output ' ' x $n;
507 }
508 128 print $output $s;
509 128 $pending = 1;
510 }
511 132 return $pending;
512 }
513  
514 #assuming it always start at $indentlevel==0
515 132 ▶sub _print {
Subroutine _print: called CC=22 SCAR=35.2
516 2 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
517 132 my ($self,$output,$indentlevel,$indentwidth,$pending,$single,$singlequote,$noblockquote,$depth, $group)=@_;
518 132 my $list = $self->{list};
519 132 my @l = @$list;
520  
521 132 my $indent=$indentwidth*$indentlevel;
522 132 my $blockquote=0;
523 132 my $noquote=0;
524 132 my $sameline=0;
525 0 ▶ if($group==0){$sameline=1;}
Branch: 1 branch
BranchTrueFalseTotal
if ($group == 0) 0 132 132
526 132 ▶ if (!$noblockquote && $single && $#l<0){$blockquote=1;}
Branch: 1 branch
BranchTrueFalseTotal
if (not $noblockquote and $single and $#l < 0) 3 129 132
Condition100%6/6
not $noblockquote and $single and $#l < 0
!ll&&!rl&&r
12633
not $noblockquote and $single
!ll&&!rl&&r
74526
MC/DC100%3/3
not $noblockquote and $single and $#l < 0
not $noblockquote $single $#l < 0
Truth table100%4/4
not(A) and B and C
A= not $noblockquoteB= $singleC= $#l < 0
ABCresult
0XX0
10X0
1100
1111
527 132 ▶ if (!$singlequote && $indentlevel==0 && $single && ($#l<0 ||$depth ==0)){$noquote=1;}#single node output
Branch: 1 branch
BranchTrueFalseTotal
if (not $singlequote and $indentlevel == 0 and $single and $#l < 0 || $depth == 0) 1 131 132
Condition66%8/12
not $singlequote and $indentlevel == 0 and $single and $#l < 0 || $depth == 0
!ll&&!rl&&r
13101
not $singlequote and $indentlevel == 0 and $single
!ll&&!rl&&r
13101
not $singlequote and $indentlevel == 0
!ll&&!rl&&r
74571
$#l < 0 or $depth == 0
l!l&&r!l&&!r
010
MC/DC40%2/5
not $singlequote and $indentlevel == 0 and $single and $#l < 0 || $depth == 0
not $singlequote $indentlevel == 0 $single $#l < 0 $depth == 0
Truth table50%3/6
not(A) and B and C and D or E
A= not $singlequoteB= $indentlevel == 0C= $singleD= $#l < 0E= $depth == 0
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
528 132 $pending = _print_str($self->{name}, $indent, $pending,$blockquote,$noquote,$sameline,$output);
529 132 ▶ if($#l==0){
Branch: 1 branch
BranchTrueFalseTotal
if ($#l == 0) { } 18 114 132
530 18 $single=1;
531 }
532 else{
533 114 $single=0;
534 }
535 132 $indentlevel++;
536
537 #negative $depth is equivalent to infinity depth
538 132 $depth--;
539 132 ▶ if($depth==0 || $#l<0){return $pending;}
Branch: 1 branch
BranchTrueFalseTotal
if ($depth == 0 or $#l < 0) 83 49 132
Condition66%2/3
$depth == 0 or $#l < 0
l!l&&r!l&&!r
08349
MC/DC50%1/2
$depth == 0 or $#l < 0
$depth == 0 $#l < 0
Truth table66%2/3
A or B
A= $depth == 0B= $#l < 0
ABresult
1X1
011
000
540 0 ▶ if($group>0){$group--;}
Branch: 1 branch
BranchTrueFalseTotal
if ($group > 0) 0 49 49
541 0 ▶ if($group==0){$sameline=1;}
Branch: 1 branch
BranchTrueFalseTotal
if ($group == 0) 0 49 49
542 49 ▶ if($sameline){
Branch: 1 branch
BranchTrueFalseTotal
if ($sameline) 0 49 49
543 0 ▶ if($#l>0){print $output " (";}
Branch: 1 branch
BranchTrueFalseTotal
if ($#l > 0) 0 0 0
544 }
545 49 my $j=$#l;
546 {
547 49 foreach my $g(@l){
548 123 $pending=$g->_print($output,$indentlevel,$indentwidth,$pending,$single,$singlequote,$noblockquote,$depth,$group);
549 123 ▶ if($sameline && $j>0){
Branch: 1 branch
BranchTrueFalseTotal
if ($sameline and $j > 0) 0 123 123
Condition33%1/3
$sameline and $j > 0
!ll&&!rl&&r
12300
MC/DC0%0/2
$sameline and $j > 0
$sameline $j > 0
Truth table33%1/3
A and B
A= $samelineB= $j > 0
ABresult
0X0
100
111
550 0 print $output ",";
551 0 $j--;
552 }
553 }
554 49 ▶ if($sameline){
Branch: 1 branch
BranchTrueFalseTotal
if ($sameline) 0 49 49
555 0 ▶ if($#l>0){print $output " )";}
Branch: 1 branch
BranchTrueFalseTotal
if ($#l > 0) 0 0 0
556 }
557 }
558 49 return $pending;
559 }
560  
561 # arguments: A hash with keys: depth, indentwidth, filehandle, singlequote, printroot, noblockquote
562 3 ▶sub print{
Subroutine print: called CC=12 SCAR=25.4
Pod undocumented
563 3 my ($g,%params) = @_;
564 3 my $list = $g->{list};
565 3 my @l = @$list;
566 3 my $singleblock=0;
567 3 my $indentwidth=4;
568 3 my $quote=0;
569 3 my $depth=0;#infinity
570 3 my $pending=0;
571 3 my $noblockquote=0;
572 3 my $output=*STDOUT;
573 3 my $group=-1; #put all nodes after $group depth in one line
574 0 ▶ if($params{"indentwidth"}){$indentwidth=$params{"indentwidth"};}
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"indentwidth"}) 0 3 3
575 3 ▶ if($params{"singlequote"}){$quote=$params{"singlequote"};}
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"singlequote"}) 2 1 3
576 3 ▶ if($params{"filehandle"}){$output=$params{"filehandle"};}
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"filehandle"}) 2 1 3
577 0 ▶ if($params{"depth"}){$depth=$params{"depth"};}
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"depth"}) 0 3 3
578 0 ▶ if(exists $params{"group"}){$group=$params{"group"};}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{"group"}) 0 3 3
579 3 ▶ if($params{"noblockquote"}){$noblockquote=$params{"noblockquote"};}
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"noblockquote"}) 2 1 3
580 3 ▶ if(defined $params{printroot} and $params{"printroot"} eq "0"){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{'printroot'} and $params{'printroot'} eq '0') { } 2 1 3
Condition66%2/3
defined $params{"printroot"} and $params{"printroot"} eq 0
!ll&&!rl&&r
102
MC/DC50%1/2
defined $params{"printroot"} and $params{"printroot"} eq 0
defined $params{"printroot"} $params{"printroot"} eq 0
Truth table66%2/3
A and B
A= defined $params{"printroot"}B= $params{"printroot"} eq 0
ABresult
0X0
100
111
581 2 $g=$list->[0];
582 2 foreach my $g2(@$list){
583 8 my $indent=0;
584 8 $pending = $g2->_print($output,$indent,$indentwidth,0,1,$quote,$noblockquote,$depth,$group);
585 8 ▶ if ($pending) { print $output "\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($pending) 8 0 8
586 }
587 }
588 else{
589 1 my $indent=0;
590 1 $pending = $g->_print($output,$indent,$indentwidth,0,1,$quote,$noblockquote,$depth,$group);
591 1 ▶ if ($pending) { print $output "\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($pending) 1 0 1
592 }
593 }
594  
595 0 ▶sub printnodes{
Subroutine printnodes: not called CC=2 SCAR=17.9
Pod undocumented
596 0 my ($g,%params)=@_;
597 0 my $list=$g->{list};
598 0 foreach(@$list){
599 0 $_->print(%params);
600 }
601 }
602  
603 0 ▶sub dump{
Subroutine dump: not called CC=3 SCAR=24.8
Pod undocumented
604 0 my ($g,$file,%params)=@_;
605 0 $params{"quote"}=1;
606 0 ▶ open my $fh, ">$file" or return 0;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">$file" or return 0 0 0 0
607 0 my $l=$g->{"list"};
608 0 foreach(@$l){
609 0 $_->print(%params,"filehandle"=>$fh);
610 }
611 }
612  
613  
614 ###############Path##############
615 3 ▶sub splitPath{
Subroutine splitPath: called CC=9 SCAR=27.3
Pod undocumented
616 3 my $path=shift;
617 3 my @paths;
618 0 ▶ if(!defined $path || $path eq "" || $path eq "."){return @paths;}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $path or $path eq "" or $path eq ".") 0 3 3
Condition33%2/6
not defined $path or $path eq "" or $path eq "."
l!l&&r!l&&!r
003
not defined $path or $path eq ""
l!l&&r!l&&!r
003
MC/DC0%0/3
not defined $path or $path eq "" or $path eq "."
not defined $path $path eq "" $path eq "."
Truth table25%1/4
not(A) or B or C
A= not defined $pathB= $path eq ""C= $path eq "."
ABCresult
1XX1
01X1
0011
0000
619 3 my $n=length($path);
620 3 my $j=0;
621 3 my $c;
622 3 my $s="";
623 3 ▶ while($j<$n){
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $n) 27 3 30
624 27 my $c=substr($path,$j,1);$j++;
625 27 ▶ if($c eq '.' ){
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq '.') { } 7 20 27
elsif ($c eq '\\') { } 0 20 20
626 7 push @paths,$s;
627 7 $s="";
628 }
629 elsif($c eq '\\'){
630 0 ▶ if($j==$n){$s=$s.$c;}
Branch: 1 branch
BranchTrueFalseTotal
if ($j == $n) { } 0 0 0
631 else{
632 0 $c=substr($path,$j,1);$j++;
633 0 ▶ if($c eq '.'){$s=$s.$c;}
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq '.') { } 0 0 0
634 0 else{$s=$s."\\$c";}
635 }
636 }
637 else{
638 20 $s=$s.$c;
639 }
640 }
641 3 push @paths,$s;
642 3 return @paths;
643 }
644 2 1;
645 __END__
↑ Summary Path.pm »