Chunks/Super.pm

filter: Statementstmt 16.8% 14 / 83 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 44.4% 4 / 9 Podpod 20.0% 1 / 5 totaltotal 10.9% 19 / 174 CC 29 SCAR 53.8
CC
29
Cov
10%
buildTree
380.0
outputNode
90.0
outputBasicChunk
6.0
CRAP 217.8
↑ Summary Chunks.pm »
1 package HTML::Chunks::Super;
2  
3 1 ▶use Safe;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use IO::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base qw(HTML::Chunks);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = "1.01";
9  
10 sub new
11 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
12 0 my $class = shift;
13 0 my $self = $class->SUPER::new(@_);
14  
15 0 return $self;
16 }
17  
18 # override basic chunk output to support conditionals
19 sub outputBasicChunk
20 0 ▶{
Subroutine outputBasicChunk: not called CC=2 SCAR=17.9
Pod undocumented
21 0 my $self = shift;
22 0 my $chunk = shift;
23 0 ▶ my $chunkRef = ref $chunk ? $chunk : \$chunk;
Branch: 1 branch
BranchTrueFalseTotal
ref $chunk ? : 0 0 0
24  
25 0 my $tree = $self->buildTree($chunkRef);
26 0 $self->outputNode($tree, @_);
27 }
28  
29 # parse a chunk into a decision tree. it might be possible to gain some
30 # efficiencies by doing this parsing when chunks are loaded, but it would
31 # be tricky to avoid confusing our parent class.
32 sub buildTree
33 0 ▶{
Subroutine buildTree: not called CC=19 SCAR=59.4
Pod undocumented
34 0 my $self = shift;
35 0 my ($chunk) = @_;
36  
37 0 ▶ my $chunkRef = ref $chunk ? $chunk : \$chunk;
Branch: 1 branch
BranchTrueFalseTotal
ref $chunk ? : 0 0 0
38 0 my $tree = [];
39 0 my @stack;
40 0 my $pos = 0;
41  
42 0 ▶ while ($$chunkRef =~ /\G(.*?)<!--\s*(IF|ELSIF|ELSE|ENDIF)\b\s*(.*?)\s*-->/gs)
Branch: 1 branch
BranchTrueFalseTotal
if ($$chunkRef =~ /\G(.*?)<!--\s*(IF|ELSIF|ELSE|ENDIF)\b\s*(.*?)\s*-->/gs) 0 0 0
43 {
44 0 my $beginDepth = @stack;
45 0 ▶ my $node = $beginDepth ? $stack[-1]->{current} : $tree;
Branch: 1 branch
BranchTrueFalseTotal
$beginDepth ? : 0 0 0
46  
47 0 ▶ if (defined $1 && length $1)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1 and length $1) 0 0 0
Condition0%0/3
defined $1 and length $1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $1 and length $1
defined $1 length $1
Truth table0%0/3
A and B
A= defined $1B= length $1
ABresult
0X0
100
111
48 {
49 0 push @{$node}, $1;
50 }
51  
52 0 my $cmd = uc($2);
53  
54 0 ▶ if ($cmd eq 'ELSE' || $cmd eq 'ELSIF')
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "ELSE" or $cmd eq "ELSIF") 0 0 0
Condition0%0/3
$cmd eq "ELSE" or $cmd eq "ELSIF"
l!l&&r!l&&!r
000
MC/DC0%0/2
$cmd eq "ELSE" or $cmd eq "ELSIF"
$cmd eq "ELSE" $cmd eq "ELSIF"
Truth table0%0/3
A or B
A= $cmd eq "ELSE"B= $cmd eq "ELSIF"
ABresult
1X1
011
000
55 {
56 0 ▶ my $branch = @stack ? $stack[-1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@stack ? : 0 0 0
57  
58 0 ▶ if ($branch && $branch->{current} == $branch->{true})
Branch: 1 branch
BranchTrueFalseTotal
if ($branch and $branch->{"current"} == $branch->{"true"}) 0 0 0
Condition0%0/3
$branch and $branch->{"current"} == $branch->{"true"}
!ll&&!rl&&r
000
MC/DC0%0/2
$branch and $branch->{"current"} == $branch->{"true"}
$branch $branch->{"current"} == $branch->{"true"}
Truth table0%0/3
A and B
A= $branchB= $branch->{"current"} == $branch->{"true"}
ABresult
0X0
100
111
59 {
60 0 $node = $branch->{current} = $branch->{false} = [];
61 }
62 }
63  
64 0 ▶ if ($cmd eq 'ENDIF' || $cmd eq 'ELSIF')
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "ENDIF" or $cmd eq "ELSIF") 0 0 0
Condition0%0/3
$cmd eq "ENDIF" or $cmd eq "ELSIF"
l!l&&r!l&&!r
000
MC/DC0%0/2
$cmd eq "ENDIF" or $cmd eq "ELSIF"
$cmd eq "ENDIF" $cmd eq "ELSIF"
Truth table0%0/3
A or B
A= $cmd eq "ENDIF"B= $cmd eq "ELSIF"
ABresult
1X1
011
000
65 {
66 0 my $branch = pop @stack;
67 0 ▶ delete $branch->{current} if $branch;
Branch: 1 branch
BranchTrueFalseTotal
if $branch 0 0 0
68 }
69  
70 0 ▶ if ($cmd eq 'IF' || ($cmd eq 'ELSIF' && $beginDepth))
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "IF" or $cmd eq "ELSIF" and $beginDepth) 0 0 0
Condition0%0/6
$cmd eq "IF" or $cmd eq "ELSIF" and $beginDepth
l!l&&r!l&&!r
000
$cmd eq "ELSIF" and $beginDepth
!ll&&!rl&&r
000
MC/DC0%0/3
$cmd eq "IF" or $cmd eq "ELSIF" and $beginDepth
$cmd eq "IF" $cmd eq "ELSIF" $beginDepth
Truth table0%0/4
A or B and C
A= $cmd eq "IF"B= $cmd eq "ELSIF"C= $beginDepth
ABCresult
1XX1
0111
00X0
0100
71 {
72 0 my $branch = {
73 test => $3,
74 true => []
75 };
76  
77 0 push @{$node}, $branch;
78 0 push @stack, $branch;
79 0 $branch->{current} = $branch->{true};
80 }
81  
82 0 $pos = pos $$chunkRef;
83 }
84  
85 0 my $tail = substr $$chunkRef, $pos;
86 0 ▶ push @{$tree}, $tail if (defined $tail && length $tail);
Branch: 1 branch
BranchTrueFalseTotal
if defined $tail and length $tail 0 0 0
Condition0%0/3
defined $tail and length $tail
!ll&&!rl&&r
000
MC/DC0%0/2
defined $tail and length $tail
defined $tail length $tail
Truth table0%0/3
A and B
A= defined $tailB= length $tail
ABresult
0X0
100
111
87  
88 0 return $tree;
89 }
90  
91 sub outputNode
92 0 ▶{
Subroutine outputNode: not called CC=9 SCAR=45.0
Pod undocumented
93 0 my $self = shift;
94 0 my $node = shift;
95  
96 0 ▶ if (defined $node)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node) 0 0 0
97 {
98 0 ▶ die "what is this? => ", $node, "\n" unless (ref $node eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node eq "ARRAY" 0 0 0
99  
100 0 foreach my $thing (@{$node})
101 {
102 0 ▶ if (ref $thing eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing eq 'HASH') { } 0 0 0
103 {
104 0 ▶ if (exists $thing->{test} && $self->testsTrue($thing->{test}, @_))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $thing->{'test'} and $self->testsTrue($thing->{'test'}, @_)) { } 0 0 0
Condition0%0/3
exists $thing->{"test"} and $self->testsTrue($thing->{"test"}, @_)
!ll&&!rl&&r
000
MC/DC0%0/2
exists $thing->{"test"} and $self->testsTrue($thing->{"test"}, @_)
exists $thing->{"test"} $self->testsTrue($thing->{"test"}, @_)
Truth table0%0/3
A and B
A= exists $thing->{"test"}B= $self->testsTrue($thing->{"test"}, @_)
ABresult
0X0
100
111
105 {
106 0 ▶ $self->outputNode($thing->{true}, @_) if (exists $thing->{true});
Branch: 1 branch
BranchTrueFalseTotal
if exists $thing->{"true"} 0 0 0
107 }
108 else
109 {
110 0 ▶ $self->outputNode($thing->{false}, @_) if (exists $thing->{false});
Branch: 1 branch
BranchTrueFalseTotal
if exists $thing->{"false"} 0 0 0
111 }
112 }
113 else
114 {
115 # call the normal HTML::Chunk output routine when we're down to a
116 # basic unadulterated chunk
117 0 $self->SUPER::outputBasicChunk(\$thing, @_);
118 }
119 }
120 }
121 }
122  
123 sub testsTrue
124 0 ▶{
Subroutine testsTrue: not called CC=2 SCAR=17.9
Pod undocumented
125 0 my $self = shift;
126 0 my $test = shift;
127 0 our %values;
128 0 local %values;
129  
130 # Translate any data tokens into scalars containing the actual data values
131  
132 0 $test =~ s/\#\#([\w\.]+)\#\#/
133 0 my $name = $1;
134 0 my $f = new IO::Scalar \$values{$name};
135 0 my $oldfh = select $f;
136 0 $self->outputData($name, @_);
137 0 select $oldfh;
138 0 close $f;
139  
140 0 "\$values{'$name'}";
141 /gex;
142  
143 # select STDERR, otherwise a 'print' in the test will blow up apache
144 0 my $oldfh = select STDERR;
145  
146 # now safely evaluate the test
147 0 my $safe = new Safe;
148 0 $safe->share('%values');
149 0 my $status = $safe->reval($test);
150  
151 # put filehandle things back
152 0 select $oldfh;
153  
154 0 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
155  
156 0 return $status;
157 }
158  
159 1 1;
160  
161 __END__
↑ Summary Chunks.pm »