blib/lib/HTML/XHTML/DVSM.pm

filter: Statementstmt 57.6% 370 / 642 Branchbran 47.8% 131 / 274 Conditioncond 50.0% 31 / 62 MC/DCmcdc 31.4% 11 / 35 Subroutinesub 61.2% 30 / 49 Podpod 19.4% 7 / 36 totaltotal 52.8% 580 / 1098 CC 172 SCAR 35.5
CC
172
Cov
54%
sbDebugPrintDocument
132.0
sbDebugDumpTags
132.0
sbInitPage
110.0
CRAP 34.8
↑ Summary
1 #!/usr/bin/perl
2 # Copyright © 2007-2010 Stuart Butler (perldev@yahoo.co.uk) and Grant Holman (grant@collegeroad.eclipse.co.uk).
3 # This program is distributed under the terms of the The GNU General Public License (GPL), which can be viewed at http://www.opensource.org/licenses/gpl-license.php
4 #
5 package HTML::XHTML::DVSM;
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $VERSION = '1.2';
9 }
10 1 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 my $ELEMENT = 1;
13 1 my $PROC_INSTR = 2;
14 1 my $COMMENT = 3;
15 1 my $DOCUMENT_ROOT = 0;
16
17 1 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
18 1 my $class = shift;
19 1 my $self = {};
20 1 bless($self, $class );
21 1 $self->sbInit();
22 1 $self->{MarkupCache} = {};
23 1 $self->{SubsCache} = {};
24 1 $self->{StopOnError} = 0;
25 1 $self->{EvalPackage} = "main";
26 1 ▶ $self->{Stream} = *STDOUT if ( ! $self->{Stream} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Stream"} 1 0 1
27 1 return $self;
28 }
29
30 0 ▶sub sbGetLastError() {
Subroutine sbGetLastError: not called CC=1 SCAR=6.9
Pod undocumented
31 0 my $self = shift;
32 0 my $lasterror = $self->{LastError};
33 0 return $lasterror;
34 }
35
36 1 ▶sub sbSetStopOnError {
Subroutine sbSetStopOnError: called CC=1 SCAR=0.0
Pod documented
37 1 my $self = shift;
38 1 my $sbStopOnError = shift;
39 1 $self->{StopOnError} = $sbStopOnError;
40 }
41 0 ▶sub sbIsStopOnError {
Subroutine sbIsStopOnError: not called CC=1 SCAR=6.9
Pod undocumented
42 0 my $self = shift;
43 0 return $self->{StopOnError};
44 }
45
46 0 ▶sub sbSetEvalPackage {
Subroutine sbSetEvalPackage: not called CC=2 SCAR=17.9
Pod undocumented
47 0 my $self = shift;
48 0 my $pkg = shift;
49 0 ▶ $pkg = "main" if ( ! $pkg );
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg 0 0 0
50 0 $self->{EvalPackage} = $pkg;
51 0 return $pkg;
52 }
53 0 ▶sub sbManageError {
Subroutine sbManageError: not called CC=3 SCAR=24.8
Pod undocumented
54 0 my $self = shift;
55 0 my $error = shift;
56 0 ▶ return if ( ! $error );
Branch: 1 branch
BranchTrueFalseTotal
unless $error 0 0 0
57 0 warn( $error );
58 0 $self->{LastError} = $error;
59 0 ▶ die( $error ) if ( $self->{StopOnError} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"StopOnError"} 0 0 0
60 }
61
62 0 ▶sub sbHash2String {
Subroutine sbHash2String: not called CC=3 SCAR=24.8
Pod undocumented
63 0 my $self = shift;
64 0 my $hash = shift;
65 0 ▶ return "" if ( ! $hash );
Branch: 1 branch
BranchTrueFalseTotal
unless $hash 0 0 0
66 0 my $res = "";
67 0 foreach my $k ( keys %$hash ) {
68 0 $res .= "$k => $$hash{$k}, ";
69 }
70 0 return $res;
71 }
72
73 0 ▶sub sbPrintHash {
Subroutine sbPrintHash: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my $self = shift;
75 0 my $pre = shift;
76 0 my $post = shift;
77 0 my $hash = shift;
78 0 print STDERR $pre;
79 0 print STDERR $self->sbHash2String($hash);
80 0 print STDERR $post;
81 }
82
83 0 ▶sub sbGetContents {
Subroutine sbGetContents: not called CC=5 SCAR=34.0
Pod undocumented
84 0 my $self = shift;
85 0 my $htmldir = shift;
86 0 my $file_name = shift;
87 0 my $instr_file = shift;
88 0 my $contents = shift;
89 0 my $instructions = shift;
90 0 my $subs = shift;
91
92 0 ▶ open( FIL, "< $htmldir/$file_name" ) || open( FIL, "< $file_name" ) || die( "Can't open file $file_name: $!" );
Branch: 1 branch
BranchTrueFalseTotal
open FIL, "< $htmldir/$file_name" or open FIL, "< $file_name" or die "Can't open file ${file_name}: $!" 0 0 0
Condition0%0/3
open FIL, "< $htmldir/$file_name" or open FIL, "< $file_name"
l!l&&r!l&&!r
000
MC/DC0%0/2
open FIL, "< $htmldir/$file_name" or open FIL, "< $file_name"
open FIL, "< $htmldir/$file_name" open FIL, "< $file_name"
Truth table0%0/3
A or B
A= open FIL, "< $htmldir/$file_name"B= open FIL, "< $file_name"
ABresult
1X1
011
000
93 {
94 0 local $/;
95 0 $$contents = <FIL>;
96 }
97 0 close( FIL );
98 0 ▶ if ( $instr_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($instr_file) 0 0 0
99 0 local $/; #read all file in one go, slurp mode.
100 0 ▶ open( FIL, "< $instr_file" ) || return "Can't find instruction file $instr_file";
Branch: 1 branch
BranchTrueFalseTotal
open FIL, "< $instr_file" or return "Can't find instruction file $instr_file" 0 0 0
101 0 $$contents .= <FIL>; # load all instructions into a string
102 0 close( FIL );
103 }
104 0 return $self->sbAnalyseContents( $htmldir, $contents, $instructions, $subs )
105 }
106
107 12 ▶sub sbAnalyseContents {
Subroutine sbAnalyseContents: called CC=12 SCAR=33.7
Pod undocumented
108 12 my $self = shift;
109 12 my $htmldir = shift;
110 12 my $contents = shift;
111 12 my $instructions = shift;
112 12 my $subs = shift;
113
114 12 ▶ my $SCRIPT_TAG = ($self->{SCRIPT_TAG} || "DVSM" );
Condition50%1/2
$self->{'SCRIPT_TAG'} || 'DVSM'
l!l
012
MC/DC0%0/1
$self->{'SCRIPT_TAG'} || 'DVSM'
$self->{'SCRIPT_TAG'}
Truth table50%1/2
A
A= $self->{'SCRIPT_TAG'}
Aresult
11
00
115 12 ▶ my $SUBS_TAG = ($self->{SUBS_TAG} || "DSUBS");
Condition50%1/2
$self->{'SUBS_TAG'} || 'DSUBS'
l!l
012
MC/DC0%0/1
$self->{'SUBS_TAG'} || 'DSUBS'
$self->{'SUBS_TAG'}
Truth table50%1/2
A
A= $self->{'SUBS_TAG'}
Aresult
11
00
116 12 ▶ while ( $$contents =~ m#(<(\?|!--)${SCRIPT_TAG}_include\s+(.*?)\s*(--|\?)>)#gsi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$contents =~ /(<(\?|!--)${SCRIPT_TAG}_include\s+(.*?)\s*(--|\?)>)/sig) 0 12 12
117 0 my $label = $1;
118 0 my $snippet = $3;
119 0 my $snippet_txt = "";
120 0 ▶ open( FIL, "< $htmldir/$snippet" ) || open( FIL, "< $snippet" ) || die( "Can't find snippet $snippet: $!" );
Branch: 1 branch
BranchTrueFalseTotal
open FIL, "< $htmldir/$snippet" or open FIL, "< $snippet" or die "Can't find snippet ${snippet}: $!" 0 0 0
Condition0%0/3
open FIL, "< $htmldir/$snippet" or open FIL, "< $snippet"
l!l&&r!l&&!r
000
MC/DC0%0/2
open FIL, "< $htmldir/$snippet" or open FIL, "< $snippet"
open FIL, "< $htmldir/$snippet" open FIL, "< $snippet"
Truth table0%0/3
A or B
A= open FIL, "< $htmldir/$snippet"B= open FIL, "< $snippet"
ABresult
1X1
011
000
121 {
122 0 local $/;
123 0 $snippet_txt = <FIL>
124 }
125 0 close( FIL );
126 0 $$contents =~ s#$label#$snippet_txt#gsie;
127 }
128
129 12 ▶ while ( $$contents =~ s|<\?${SCRIPT_TAG}(.*?)\?>\n*||si ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$contents =~ s/<\?$SCRIPT_TAG(.*?)\?>\n*//is) 0 12 12
130 0 $$instructions .= $1;
131 }
132 12 ▶ while ( $$contents =~ s|<!--${SCRIPT_TAG}(.*?)-->\n*||si ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$contents =~ s/<!--$SCRIPT_TAG(.*?)-->\n*//is) 12 12 24
133 12 $$instructions .= $1;
134 }
135 12 ▶ while ( $$contents =~ s|<\?${SUBS_TAG}(.*?)\?>\n*||si ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$contents =~ s/<\?$SUBS_TAG(.*?)\?>\n*//is) 0 12 12
136 0 $$subs .= $1;
137 }
138 12 ▶ while ( $$contents =~ s|<!--${SUBS_TAG}(.*?)-->\n*||si ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$contents =~ s/<!--$SUBS_TAG(.*?)-->\n*//is) 10 12 22
139 10 $$subs .= $1;
140 }
141 12 $$subs .= "\nreturn 1;\n";
142 12 ▶ if ( $self->{DEBUG} && open( D, "> /tmp/dvsmsubs$$.pl") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DEBUG"} and open D, "> /tmp/dvsmsubs${$}.pl") 0 12 12
Condition33%1/3
$self->{"DEBUG"} and open D, "> /tmp/dvsmsubs${$}.pl"
!ll&&!rl&&r
1200
MC/DC0%0/2
$self->{"DEBUG"} and open D, "> /tmp/dvsmsubs${$}.pl"
$self->{"DEBUG"} open D, "> /tmp/dvsmsubs${$}.pl"
Truth table33%1/3
A and B
A= $self->{"DEBUG"}B= open D, "> /tmp/dvsmsubs${$}.pl"
ABresult
0X0
100
111
143 0 print D $$subs;
144 0 close( D );
145 }
146 12 return 1;
147 }
148
149 9 ▶sub sbParseInstructions {
Subroutine sbParseInstructions: called CC=19 SCAR=30.7
Pod undocumented
150 9 my $self = shift;
151 9 my $instructionsStr = shift; # reference to a string
152 9 my $instructions = shift; # reference to an array of instructions
153 9 my @lines = split( /\n/, $$instructionsStr );
154 9 ▶ for ( my $i = 0; $i < @lines; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @lines) 20 9 29
155 20 my $line = $lines[$i];
156 20 ▶ if ( $line =~ m|^\s*set\s+(\S+)\s+to\s+"([^"]+)"\s+where\s+(\S+)\s*=\s*"([^"]+)"|i ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($line =~ /^\s*set\s+(\S+)\s+to\s+"([^"]+)"\s+where\s+(\S+)\s*=\s*"([^"]+)"/i) { } 6 14 20
elsif ($line =~ /^\s*toggle\s+(\S+)\s+to\s+"([^"]+)"\s+where\s+(\S+)\s*=\s*"([^"]+)"/i) { } 1 13 14
elsif ($line =~ /^\s*load\s+module\s+"([^"]+)"/i) { } 0 13 13
elsif ($line =~ /^\s*run\s+"([^"]+)"/i) { } 2 11 13
elsif ($line =~ /^\s*(while|if)\s+"([^"]+)"\s+where\s+(\S+)\s*=\s*"([^"]+)"/i) { } 3 8 11
elsif ($line =~ /^\s*delete\s+where\s+(\S+)\s*=\s*"([^"]+)"/i) { } 2 6 8
elsif ($line =~ /^\s*$/) { } 6 0 6
elsif ($line =~ /^\s*#/) { } 0 0 0
157 #set textnode to getTitle('Login') where tagname = title
158 6 my %instr = ();
159 6 $instr{cmd} = "set";
160 6 $instr{target} = $1;
161 6 $instr{exec} = $2;
162 6 $instr{where} = $3;
163 6 $instr{value} = $4;
164 6 ▶ if ( $line =~ m|\bif\s+"([^"]+)"|i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\bif\s+"([^"]+)"/i) 0 6 6
165 0 $instr{condition} = $1;
166 }
167 6 push( @$instructions, \%instr ); #add instruction structure to the array of instructions
168 }
169 elsif ( $line =~ m|^\s*toggle\s+(\S+)\s+to\s+"([^"]+)"\s+where\s+(\S+)\s*=\s*"([^"]+)"|i ) {
170 #toggle checked to "canAddProject()" where name = "canaddproj"
171 1 my %instr = ();
172 1 $instr{cmd} = "toggle";
173 1 $instr{target} = $1;
174 1 $instr{exec} = $2;
175 1 $instr{where} = $3;
176 1 $instr{value} = $4;
177 1 push( @$instructions, \%instr ); #add instruction structure to the array of instructions
178 }
179 elsif ( $line =~ m|^\s*load\s+module\s+"([^"]+)"|i ) {
180 #load module "routines.pl"
181 0 ▶ if ( $1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 0 0 0
182 0 my %instr = ();
183 0 $instr{cmd} = "load";
184 0 $instr{exec} = $1;
185 0 push( @$instructions, \%instr ); #add instruction structure to the array of instructions
186 }
187 }
188 elsif ( $line =~ m|^\s*run\s+"([^"]+)"|i ) {
189 #run "rSecurity()"
190 2 ▶ if ( $1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 2 0 2
191 2 my %instr = ();
192 2 $instr{cmd} = "run";
193 2 $instr{exec} = $1;
194 2 ▶ if ( $line =~ m|\s+where\s+(\S+)\s*=\s*"([^"]+)"|i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\s+where\s+(\S+)\s*=\s*"([^"]+)"/i) 1 1 2
195 1 $instr{where} = $1;
196 1 $instr{value} = $2;
197 }
198 2 push( @$instructions, \%instr ); #add instruction structure to the array of instructions
199 }
200 }
201 elsif ( $line =~ m|^\s*(while\|if)\s+"([^"]+)"\s+where\s+(\S+)\s*=\s*"([^"]+)"|i ) {
202 #while "nextRole()" where name = "template"
203 #end while
204 3 my $cmd = lc( $1 );
205 3 my %instr = ();
206 3 $instr{cmd} = $cmd;
207 3 $instr{exec} = $2;
208 3 $instr{where} = $3;
209 3 $instr{value} = $4;
210 3 my $subinstr = "";
211 3 my @subinstr = ();
212 3 my $pop = 1;
213 WHILELOOP:
214 3 ▶ for ( ++$i; $i < @lines; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @lines) 7 0 7
215 7 ▶ $pop++ if ( $lines[$i] =~ m#^\s*(while|if)\b#i );
Branch: 1 branch
BranchTrueFalseTotal
if $lines[$i] =~ /^\s*(while|if)\b/i 0 7 7
216 7 ▶ if ( $lines[$i] =~ m#^\s*end\b#i ){
Branch: 1 branch
BranchTrueFalseTotal
if ($lines[$i] =~ /^\s*end\b/i) 3 4 7
217 3 $pop--;
218 3 ▶ die( $instr{cmd}." START/END stack not even\n" ) if ( $pop < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $pop < 0 0 3 3
219 3 ▶ if ( $pop <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pop <= 0) 3 0 3
220 3 last WHILELOOP;
221 }
222 }
223 4 $subinstr .= $lines[$i]."\n";
224 }
225 3 $self->sbParseInstructions( \$subinstr, \@subinstr ); # get child instructions for this while or if loop
226 #{
227 3 my @mychildren = @subinstr;
228 3 my %myinstr = %instr;
229 3 $myinstr{children} = \@mychildren; # add child instructions to the instruction's children attribute.
230 3 push( @$instructions, \%myinstr ); #add instruction structure to the array of instructions
231 #}
232 #if ( $lines[$i] =~ m#^\s*else\b#i ) {
233 # $pop = 1;
234 # $subinstr = "";
235 # @subinstr = ();
236 # my $ifinstr = $$instructions[@$instructions - 1];
237 # $instr{cmd} = "else";
238 # $instr{exec} = "";
239 # $instr{if} = $ifinstr;
240 # #$instr{where} is same
241 # #$instr{value} is same
242 # delete( $instr{children} );
243 # goto WHILELOOP;
244 #}
245 }
246 elsif ( $line =~ m|^\s*delete\s+where\s+(\S+)\s*=\s*"([^"]+)"|i ) {
247 #delete where name = "deleteme"
248 2 my %instr = ();
249 2 $instr{cmd} = "delete";
250 2 $instr{where} = $1;
251 2 $instr{value} = $2;
252 2 push( @$instructions, \%instr ); #add instruction structure to the array of instructions
253 }
254 elsif ( $line =~ m|^\s*$| ) {
255 6 next; # empty line
256 }
257 elsif ( $line =~ m|^\s*#| ) {
258 0 next; # comment
259 }
260 else {
261 0 $self->sbManageError( "ERROR: Invalid command: $line" );
262 }
263 }
264 9 return "";
265 }
266
267
268 82 ▶sub sbTrim {
Subroutine sbTrim: called CC=1 SCAR=0.0
Pod undocumented
269 82 my $class = shift;
270 82 my $str = shift;
271 82 $str =~ s/^\s+//s;
272 82 $str =~ s/\s+$//s;
273 82 return $str;
274 }
275
276 0 ▶sub sbTrimStr {
Subroutine sbTrimStr: not called CC=1 SCAR=6.9
Pod undocumented
277 0 my $class = shift;
278 0 my $str = shift;
279 0 my $trm = shift;
280 0 $str =~ s#^$trm##s;
281 0 $str =~ s#$trm$##s;
282 0 return $str;
283 }
284
285 #sbOnEndTag - Called to process an </endtag>
286 41 ▶sub sbOnEndTag {
Subroutine sbOnEndTag: called CC=10 SCAR=23.8
Pod undocumented
287 41 my $self = shift;
288 41 my $endtag = shift; # reference to a string containing tag name if to be terminated by </tag>
289 41 my $orphantext = shift; #text not within tags - e.g. <a href=x>A</a> | <a href=y>B</a> - the | is orphaned
290 41 my $currenttag = 0;
291 41 my $sbTagparents = $self->{Tagparents};
292 41 my $sbInstrstack = $self->{Instrstack};
293 41 ▶ while( @{$sbTagparents} ) { # loop tags that are still open, e.g if we are now a tr typically might have <table><body><html> still open
Branch: 1 branch
BranchTrueFalseTotal
if (@{$sbTagparents;}) 41 0 41
294 41 $currenttag = pop( @$sbTagparents ); # get the most recent tag on the list of open tags.
295 41 ▶ if ( ! $currenttag ) { # there should be one, else we don't have an opening <tag>
Branch: 1 branch
BranchTrueFalseTotal
unless ($currenttag) 0 41 41
296 0 warn( "Found no tag for endtag=$$endtag" );
297 0 last;
298 }
299 41 my $instructionarr = $$currenttag{instructions}; #Get the instructions for this current tag
300 41 foreach my $instr ( @$instructionarr ) { # loop through the tag's instructions
301 18 ▶ next if ( ! $$instr{children} ); # If there are no child instructions to this instruction, go get the next instruction
Branch: 1 branch
BranchTrueFalseTotal
unless $instr->{"children"} 15 3 18
302 3 ▶ for( my $i = 1; $i < @$sbInstrstack ; $i++ ) { # Now try to find that array of child instructions in our global instruction stack
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$sbInstrstack) 3 0 3
303 3 ▶ next if ( $$instr{children} != $$sbInstrstack[$i] ); # if this is not it keep on search
Branch: 1 branch
BranchTrueFalseTotal
if $instr->{"children"} != $sbInstrstack->[$i] 0 3 3
304 3 ▶ for ( ; $i < @$sbInstrstack; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$sbInstrstack) 3 3 6
305 #printHash( "POP INSTRSTACK FOR $$endtag", "\n", $instr );
306 3 delete( $$sbInstrstack[$i] ); # we have found the top of the global instruction stack, so we can pop them - don't need them any more
307 }
308 3 last;
309 }
310 }
311 41 ▶ next if ( $$currenttag{tagend} ); # This tag is a self close one <tag/> - tagend is /
Branch: 1 branch
BranchTrueFalseTotal
if $currenttag->{"tagend"} 0 41 41
312 41 ▶ next if ( $$currenttag{tag} !~ m|^$$endtag$|i ); # This current tag is not our endtag, so continue searching
Branch: 1 branch
BranchTrueFalseTotal
unless $currenttag->{"tag"} =~ /^$$endtag$/i 0 41 41
313 41 $$currenttag{orphantext} = $orphantext; # Save any text that comes at the end of the </tag> so we keep exact format
314 41 last; # finished
315 }
316 }
317
318 #sbOnTag - called when the start of a tag is found
319 47 ▶sub sbOnTag {
Subroutine sbOnTag: called CC=13 SCAR=25.9
Pod undocumented
320 47 my $self = shift;
321 47 my $tag = shift; # reference to a string with tagname in it
322 47 my $type = shift; # reference to the tag type 1 for ELEMENT
323 47 my $tagend = shift; # Reference to the tagend string - "/" or "" if terminated with </tag>
324 47 my $attribstr = shift; # Reference to a string with the attributes e.g. src="something.pl" border="0"
325 47 my $attribs = shift; # Reference to a hash of the attributes e.g. src => somethinth.pl, border => 0
326 47 my $text = shift; # Reference to textnode text between <tag>text</tag>
327 47 my $orphantext = shift; # reference to orphantext to be output after the tag
328 47 my $pretext = shift; # Reference to orphantext to be output before the tag
329 47 my %tagdata = ( tag => $$tag, # save tag as plain string
330 type => $$type, # save type as plain int string
331 tagend => $$tagend, # save tagend as reference
332 attribs => $attribs, # save attribute hash as reference
333 attribstr => $attribstr, # save attribute string as reference
334 text => $text, # save text as reference
335 orphantext => $orphantext, # save any orphan text if self closing "<p/> stuf"
336 pretext => $pretext, # save any text that came before the tag
337 );
338 47 $tagdata{instructions} = []; # initialise instructions to a reference to an empty array
339 47 my $sbInstrstack = $self->{Instrstack};
340 47 my $sbTagparents = $self->{Tagparents};
341 47 ▶ my $instructions = $$sbInstrstack[$#{$sbInstrstack}] if ( @$sbInstrstack ); # Get the current array of instructions
Branch: 1 branch
BranchTrueFalseTotal
if @$sbInstrstack 47 0 47
342 47 ▶ if ( ! $instructions ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($instructions) 0 47 47
343 0 warn( "NO INSTRUCTIONS for <$$tag $$attribstr>" );
344 }
345 47 ▶ if ( $$type == $DOCUMENT_ROOT ) { # this is the first
Branch: 1 branch
BranchTrueFalseTotal
if ($$type == $DOCUMENT_ROOT) { } 6 41 47
346 6 $self->{Markup} = \%tagdata;
347 6 push( @$sbTagparents, \%tagdata );
348 6 return;
349 }
350 else {
351 41 my $currenttag = $$sbTagparents[$#{$sbTagparents}];
352 41 my $children = $$currenttag{ children };
353 41 ▶ $children = [] if ( ! $children );
Branch: 1 branch
BranchTrueFalseTotal
unless $children 28 13 41
354 41 push( @$children, \%tagdata );
355 41 $$currenttag{ children } = $children;
356 41 ▶ if ( $$type == $ELEMENT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$type == $ELEMENT) 41 0 41
357 41 ▶ if ( $$tagend !~ m|/| ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$tagend =~ m[/]) 41 0 41
358 41 push( @$sbTagparents, \%tagdata );
359 }
360 41 ▶ if ( ! $$currenttag{pop_child_instructions} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($currenttag->{"pop_child_instructions"}) 28 13 41
361 28 my $instructarr = $$currenttag{instructions};
362 28 foreach my $instr ( @$instructarr ) {
363 6 my $childinstrs = $$instr{children};
364 6 ▶ next if ( ! $childinstrs || ! @$childinstrs );
Branch: 1 branch
BranchTrueFalseTotal
unless $childinstrs and @$childinstrs 3 3 6
Condition66%2/3
$childinstrs and @$childinstrs
!ll&&!rl&&r
303
MC/DC50%1/2
$childinstrs and @$childinstrs
$childinstrs @$childinstrs
Truth table66%2/3
A and B
A= $childinstrsB= @$childinstrs
ABresult
0X0
100
111
365 3 push( @$sbInstrstack, $childinstrs );
366 #see if there are any instructions that are relevant for the parent tag
367 }
368 28 $$currenttag{pop_child_instructions} = 1;
369 28 ▶ $instructions = $$sbInstrstack[$#{$sbInstrstack}] if ( @$sbInstrstack );
Branch: 1 branch
BranchTrueFalseTotal
if @$sbInstrstack 28 0 28
370 }
371 }
372 }
373 41 ▶ return if ( ! $instructions );
Branch: 1 branch
BranchTrueFalseTotal
unless $instructions 0 41 41
374 41 $self->sbAllocateInstr( $instructions, \%tagdata );
375 }
376
377 58 ▶sub sbAllocateInstr {
Subroutine sbAllocateInstr: called CC=15 SCAR=30.3
Pod undocumented
378 58 my $self = shift;
379 58 my $instructions = shift;
380 58 my $tagdata = shift;
381 58 my $norecurse = shift;
382 58 my $tag = $$tagdata{tag};
383 58 my $attribs = $$tagdata{attribs};
384 58 foreach my $instr ( @$instructions ) {
385 72 ▶ if ( $$instr{where} && $$instr{where} =~ m|^tagname$|i
Branch: 3 branches
BranchTrueFalseTotal
if ($instr->{'where'} and $instr->{'where'} =~ /^tagname$/i and $instr->{'value'} and $instr->{'value'} =~ /^$tag$/i) { } 0 72 72
elsif ($instr->{'where'} and exists $$attribs{$instr->{'where'}} and $instr->{'value'} =~ /^$$attribs{$instr->{'where'}}$/i) { } 17 55 72
elsif (not $instr->{'allocated'} || $instr->{'where'} and $instr->{'cmd'} eq 'load' || $instr->{'cmd'} eq 'run') { } 1 108 109
Condition44%4/9
$instr->{"where"} and $instr->{"where"} =~ /^tagname$/i and $instr->{"value"} and $instr->{"value"} =~ /^$tag$/i
!ll&&!rl&&r
7200
$instr->{"where"} and $instr->{"where"} =~ /^tagname$/i and $instr->{"value"}
!ll&&!rl&&r
7200
$instr->{"where"} and $instr->{"where"} =~ /^tagname$/i
!ll&&!rl&&r
3690
MC/DC0%0/4
$instr->{"where"} and $instr->{"where"} =~ /^tagname$/i and $instr->{"value"} and $instr->{"value"} =~ /^$tag$/i
$instr->{"where"} $instr->{"where"} =~ /^tagname$/i $instr->{"value"} $instr->{"value"} =~ /^$tag$/i
Truth table40%2/5
A and B and C and D
A= $instr->{"where"}B= $instr->{"where"} =~ /^tagname$/iC= $instr->{"value"}D= $instr->{"value"} =~ /^$tag$/i
ABCDresult
0XXX0
10XX0
110X0
11100
11111
386 && $$instr{value} && $$instr{value} =~ m|^$tag$|i ) {
387 0 my $instructionarr = $$tagdata{instructions};
388 0 push( @$instructionarr, $instr );
389 0 ▶ $self->sbAllocateInstr( $$instr{children}, $tagdata, 1 )
Branch: 1 branch
BranchTrueFalseTotal
unless $norecurse 0 0 0
390 if ( ! $norecurse ); # for while and if can be child instructions that are relevant
391 }
392 ▶ elsif ( $$instr{where} && exists( $$attribs{$$instr{where}} )
Condition100%6/6
$instr->{"where"} and exists $$attribs{$instr->{"where"}} and $instr->{"value"} =~ /^$$attribs{$instr->{"where"}}$/i
!ll&&!rl&&r
431217
$instr->{"where"} and exists $$attribs{$instr->{"where"}}
!ll&&!rl&&r
34029
MC/DC100%3/3
$instr->{"where"} and exists $$attribs{$instr->{"where"}} and $instr->{"value"} =~ /^$$attribs{$instr->{"where"}}$/i
$instr->{"where"} exists $$attribs{$instr->{"where"}} $instr->{"value"} =~ /^$$attribs{$instr->{"where"}}$/i
Truth table100%4/4
A and B and C
A= $instr->{"where"}B= exists $$attribs{$instr->{"where"}}C= $instr->{"value"} =~ /^$$attribs{$instr->{"where"}}$/i
ABCresult
0XX0
10X0
1100
1111
393 && $$instr{value} =~ m|^$$attribs{$$instr{where}}$|i ) {
394 17 my $instructionarr = $$tagdata{instructions};
395 17 push( @$instructionarr, $instr );
396 17 ▶ $self->sbAllocateInstr( $$instr{children}, $tagdata, 1 )
Branch: 1 branch
BranchTrueFalseTotal
unless $norecurse 17 0 17
397 if ( ! $norecurse ); # for while and if can be child instructions that are relevant
398 }
399 ▶ elsif ( ! $$instr{allocated} && ! $$instr{where}
Condition66%6/9
not $instr->{"allocated"} || $instr->{"where"} and $instr->{"cmd"} eq "load" || $instr->{"cmd"} eq "run"
!ll&&!rl&&r
5401
$instr->{'allocated'} || $instr->{'where'}
l!l&&r!l&&!r
2521
$instr->{"cmd"} eq "load" or $instr->{"cmd"} eq "run"
l!l&&r!l&&!r
010
MC/DC50%2/4
not $instr->{"allocated"} || $instr->{"where"} and $instr->{"cmd"} eq "load" || $instr->{"cmd"} eq "run"
$instr->{'allocated'} $instr->{'where'} $instr->{"cmd"} eq "load" $instr->{"cmd"} eq "run"
Truth table60%3/5
not(A || B) and C or D
A= $instr->{'allocated'}B= $instr->{'where'}C= $instr->{"cmd"} eq "load"D= $instr->{"cmd"} eq "run"
ABCDresult
1XXX0
01XX0
00000
001X1
00011
400 && ( $$instr{cmd} eq "load" || $$instr{cmd} eq "run" ) ) {
401 1 my $instructionarr = $$tagdata{instructions}; # for while and if can be child instructions that are relevant
402 1 push( @$instructionarr, $instr );
403 1 $$instr{allocated} = 1;
404 }
405 }
406 }
407
408 41 ▶sub sbGetAttribs {
Subroutine sbGetAttribs: called CC=6 SCAR=19.3
Pod undocumented
409 41 my $self = shift;
410 41 my $tag = shift;
411 41 my $attribstr = shift;
412 41 my $attribs = shift;
413 41 $$attribstr = $$tag;
414 41 $$attribstr =~ s#^\s*(\S+)##s;
415 41 my $save_attribstr = $$attribstr;
416 41 $$tag = $1;
417 41 ▶ while( $$attribstr =~ m#\s*([^=\s]+)#gs ) { #=(["'][^"']*["']|\S+)|\S+)
Branch: 1 branch
BranchTrueFalseTotal
if ($$attribstr =~ /\s*([^=\s]+)/gs) 25 41 66
418 25 my $attrib = $1;
419 25 $$attribstr = substr( $$attribstr, pos( $$attribstr ) );
420 25 my $value = undef;
421 25 ▶ if ( $$attribstr =~ m#^\s*=\s*#s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$attribstr =~ /^\s*=\s*/s) 25 0 25
422 25 $$attribstr = $';
423 25 ▶ if ( $$attribstr =~ m#^"([^"]*)"#s ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($$attribstr =~ /^"([^"]*)"/s) { } 25 0 25
elsif ($$attribstr =~ /^'([^']*)'/s) { } 0 0 0
elsif ($attribstr =~ /^(\S+)/s) { } 0 0 0
424 25 $value = $1;
425 25 $$attribstr = $';
426 }
427 elsif ( $$attribstr =~ m#^'([^']*)'#s ) {
428 0 $value = $1;
429 0 $$attribstr = $';
430 }
431 elsif ( $attribstr =~ m#^(\S+)#s ) {
432 0 $value = $1;
433 0 $attribstr = $';
434 }
435 }
436 25 $$attribs{$attrib} = $value;
437 }
438 41 $$attribstr = $save_attribstr;
439 41 return "";
440 }
441
442 6 ▶sub sbParseMarkup {
Subroutine sbParseMarkup: called CC=10 SCAR=28.2
Pod undocumented
443 6 my $self = shift;
444 6 my $contents = shift;
445 6 my $gotelement = 0;
446 6 ▶ $self->{documentroot} = "_document_root_" if ( ! $self->{documentroot} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"documentroot"} 1 5 6
447 6 my $root = $self->{documentroot};
448 6 my $root_type = $DOCUMENT_ROOT;
449 6 my $root_attribs = "";
450 6 $self->sbOnTag( \$root, \$root_type, \"", \"", {}, \"" , \"" );
451 6 ▶ while ( $$contents =~ m#<#gm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$contents =~ /</gm) 82 6 88
452 82 $$contents = substr( $$contents, pos( $$contents ) );
453 82 ▶ if ( $$contents =~ m#(^!\[CDATA\[.*?\]\])>([^<]*)#s ) { # //<![CDATA] ... ]]> ...
Branch: 6 branches
BranchTrueFalseTotal
if ($$contents =~ /(^!\[CDATA\[.*?\]\])>([^<]*)/s) { } 0 82 82
elsif ($$contents =~ /(^!--.*?--)>([^<]*)/s) { } 0 82 82
elsif ($$contents =~ /(^!.*?)>([^<]*)/s) { } 0 82 82
elsif ($$contents =~ /(^\?.*?\?)>([^<]*)/s) { } 0 82 82
elsif ($$contents =~ m[^\s*\/([^>]+)>([^<]*)]s) { } 41 41 82
elsif ($$contents =~ /(^[^>]+)>([^<]*)/s) { } 41 0 41
454 0 my $tag = $1;
455 0 my $orphantext = $2;
456 0 my $type = $COMMENT;
457 0 $$contents = $';
458 0 $self->sbOnTag( \$tag, \$type, \"", \"", {}, \"" , \$orphantext );
459 }
460 elsif ( $$contents =~ m#(^!--.*?--)>([^<]*)#s ) { # <!-- ... --> ...
461 0 my $tag = $1;
462 0 my $orphantext = $2;
463 0 my $type = $COMMENT;
464 0 $$contents = $';
465 0 $self->sbOnTag( \$tag, \$type, \"", \"", {}, \"" , \$orphantext );
466 }
467 elsif ( $$contents =~ m#(^!.*?)>([^<]*)#s ) { # <!DOCTYPE ... > ...
468 0 my $tag = $1;
469 0 my $orphantext = $2;
470 0 my $type = $COMMENT;
471 0 $$contents = $';
472 0 $self->sbOnTag( \$tag, \$type, \"", \"", {}, \"" , \$orphantext );
473 }
474 elsif ( $$contents =~ m#(^\?.*?\?)>([^<]*)#s ) { # <? ... ?> ...
475 0 my $tag = $1;
476 0 my $orphantext = $2;
477 0 my $type = $PROC_INSTR;
478 0 $$contents = $';
479 0 $self->sbOnTag( \$tag, \$type, \"", \"", {}, \"" , \$orphantext );
480 }
481 elsif ( $$contents =~ m#^\s*\/([^>]+)>([^<]*)#s ) { # </tagname>...
482 41 my $tag = $1;
483 41 my $orphantext = $2;
484 41 $$contents = $';
485 41 $tag = $self->sbTrim( $tag );
486 41 $self->sbOnEndTag( \$tag, \$orphantext );
487 }
488 elsif ( $$contents =~ m#(^[^>]+)>([^<]*)#s ) { # <tagname attrib1=value1>...
489 41 my $tag = $1;
490 41 my $text = $2;
491 41 $$contents = $';
492 41 $tag = $self->sbTrim( $tag );
493 41 my $notextnode = "";
494 41 ▶ $notextnode = "/" if ( $tag =~ s#/$##s );
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ s[/$][]s 0 41 41
495 41 my $type = $ELEMENT;
496 41 my $attribstr = "";
497 41 my %attribs = ();
498 41 $self->sbGetAttribs( \$tag, \$attribstr, \%attribs );
499 41 $self->sbOnTag( \$tag, \$type, \$notextnode, \$attribstr, \%attribs, \$text, \"" );
500 }
501 else {
502 0 warn( "sbParseMarkup - no tag regexp worked: $$contents" );
503 }
504 }
505 }
506
507 37 ▶sub sbPrintTag {
Subroutine sbPrintTag: called CC=8 SCAR=22.8
Pod undocumented
508 37 my $self = shift;
509 37 my $indent = shift;
510 37 my $tag = shift;
511 37 my $stream = $self->{Stream};
512 37 my $text = $$tag{text};
513 37 my $orphantext = $$tag{orphantext}; # often white space which helps keep format, but can be text between text e.g. <a>A</a> | <a>B</b> - the " | " is orphan
514 37 ▶ if ( ! $text ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($text) 0 37 37
515 0 my $txt = "";
516 0 $text = \$txt;
517 0 $$tag{text} = $text;
518 }
519 37 my $attribs = $$tag{attribs};
520 37 print $stream "<$$tag{tag}";
521 37 foreach my $attrib ( keys %$attribs ) {
522 24 ▶ next if ( ! defined( $attrib ));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attrib 0 24 24
523 24 ▶ $$attribs{$attrib} = "" if ( ! defined( $$attribs{$attrib} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attribs->{$attrib} 0 24 24
524 24 print $stream " $attrib=\"$$attribs{$attrib}\"";
525 }
526 37 print $stream "$$tag{tagend}>$$text";
527 37 $self->sbMergeDocument( $indent + 1, $$tag{children});
528 37 ▶ print $stream "</$$tag{tag}>" if ( $$tag{type} == $ELEMENT && ! $$tag{tagend} );
Branch: 1 branch
BranchTrueFalseTotal
if $tag->{"type"} == $ELEMENT and not $tag->{"tagend"} 37 0 37
Condition33%1/3
$tag->{"type"} == $ELEMENT and not $tag->{"tagend"}
!ll&&!rl&&r
0037
MC/DC0%0/2
$tag->{"type"} == $ELEMENT and not $tag->{"tagend"}
$tag->{"type"} == $ELEMENT not $tag->{"tagend"}
Truth table33%1/3
A and not(B)
A= $tag->{"type"} == $ELEMENTB= not $tag->{"tagend"}
ABresult
0X0
100
111
529 37 ▶ print $stream $$orphantext if ( $orphantext );
Branch: 1 branch
BranchTrueFalseTotal
if $orphantext 37 0 37
530 }
531
532 3 ▶sub sbGetCurrentTagValue {
Subroutine sbGetCurrentTagValue: called CC=6 SCAR=19.4
Pod documented
533 3 my $self = shift;
534 3 my $attrib = shift;
535 3 my $sbCurrentTag = $self->{CurrentTag};
536 3 ▶ return "" if ( ! $sbCurrentTag || ! $attrib );
Branch: 1 branch
BranchTrueFalseTotal
unless $sbCurrentTag and $attrib 0 3 3
Condition33%1/3
$sbCurrentTag and $attrib
!ll&&!rl&&r
003
MC/DC0%0/2
$sbCurrentTag and $attrib
$sbCurrentTag $attrib
Truth table33%1/3
A and B
A= $sbCurrentTagB= $attrib
ABresult
0X0
100
111
537 3 ▶ return $$sbCurrentTag{tag} if ( $attrib eq "tagname" );
Branch: 1 branch
BranchTrueFalseTotal
if $attrib eq "tagname" 0 3 3
538 3 ▶ return $$sbCurrentTag{text} if ( $attrib eq "textnode" );
Branch: 1 branch
BranchTrueFalseTotal
if $attrib eq "textnode" 0 3 3
539 3 my $attribs = $$sbCurrentTag{attribs};
540 3 ▶ return "" if ( ! $attribs );
Branch: 1 branch
BranchTrueFalseTotal
unless $attribs 0 3 3
541 3 return $$attribs{$attrib};
542 }
543
544 0 ▶sub sbDebugCurrentTag {
Subroutine sbDebugCurrentTag: not called CC=1 SCAR=6.9
Pod undocumented
545 0 my $self = shift;
546 0 my $attrib = shift;
547 0 my $sbCurrentTag = $self->{CurrentTag};
548 0 my $res="<$$sbCurrentTag{tag} ${$$sbCurrentTag{attribstr}}>";
549 0 return $res;
550 }
551
552 43 ▶sub sbCopyTag {
Subroutine sbCopyTag: called CC=3 SCAR=11.0
Pod undocumented
553 43 my $self = shift;
554 43 my $origtag = shift;
555 43 my %copytag = %{$origtag};
556 43 my $tag = \%copytag;
557 43 my $text = $$tag{text};
558 43 ▶ $text = \"" if ( ! $text );
Branch: 1 branch
BranchTrueFalseTotal
unless $text 0 43 43
559 43 my $copytext = $$text;
560 43 $$tag{text} = \$copytext;
561 43 my $attribs = $$tag{attribs};
562 43 ▶ $attribs = {} if ( ! $attribs );
Branch: 1 branch
BranchTrueFalseTotal
unless $attribs 0 43 43
563 43 my %copyattribs = %{$attribs};
564 43 $$tag{attribs} = \%copyattribs;
565 43 return $tag;
566 }
567
568
569 #sbMergeDocument - merges data into the markup and prints it
570 43 ▶sub sbMergeDocument {
Subroutine sbMergeDocument: called CC=31 SCAR=38.4
Pod undocumented
571 43 my $self = shift;
572 43 my $indent = shift;
573 43 my $tags = shift;
574 43 my $error;
575 TAGLOOP:
576 43 foreach my $origtag ( @$tags ) {
577 40 my $run = 0;
578 40 my $cmd = "";
579 40 my $exec = "";
580 40 my $inrepeat = 0;
581 40 ▶ do { # while inrepeat
Branch: 1 branch
BranchTrueFalseTotal
$inrepeat and do { do { my $tag = $self->sbCopyTag($origtag); $self->{"CurrentTag"} = $tag; my $text = $tag->{"text"}; unless ($text) { my $txt = ""; $text = \$txt; $tag->{"text"} = $text; } ; my $attribstr = $tag->{"attribstr"}; $attribstr = \"" unless $attribstr; my $attribs = $tag->{"attribs"}; my $instructionarr = $tag->{"instructions"}; $run = 0; for (my $count = 0; ; ++$count) { my $instruction = $instructionarr->[$count] if $instructionarr and $count < @$instructionarr; $run = 1 if $count == 0 and not $instruction; last if $count > 0 and not $instruction; next unless $instruction; $cmd = lc $instruction->{"cmd"}; $exec = $instruction->{"exec"}; if ($cmd eq "load") { require $exec; if ($@) { $error = "ERROR: ${exec}: $@"; $self->sbManageError($error); } ; $run = 1; } elsif ($cmd eq "run") { eval 'package ' . $self->{"EvalPackage"} . '; ' . $exec; if ($@) { $error = "ERROR: ${exec}: $@"; $self->sbManageError($error); } ; $run = 1; } elsif ($cmd eq "set") { my $cond = 1; $cond = eval 'package ' . $self->{"EvalPackage"} . '; ' . $instruction->{"condition"} if $instruction->{"condition"}; if ($cond) { my $res = eval 'package ' . $self->{"EvalPackage"} . '; ' . $instruction->{"exec"}; if ($@) { $error = "ERROR: ${exec}: $@"; $self->sbManageError($error); } ; if (lc $instruction->{"target"} eq "textnode") { $$text = $res; } else { $$attribs{$instruction->{"target"}} = $res; } ; } ; $run = 1; } elsif ($cmd eq "toggle") { my $res = eval 'package ' . $self->{"EvalPackage"} . '; ' . $instruction->{"exec"}; if ($@) { $error = "ERROR: ${exec}: $@"; $self->sbManageError($error); } ; if ($res) { $$attribs{$instruction->{"target"}} = "true"; } else { delete $$attribs{$instruction->{"target"}}; } ; $run = 1; } elsif ($cmd eq "delete") { next TAGLOOP; } elsif ($cmd eq "if") { $run = eval 'package ' . $self->{"EvalPackage"} . '; ' . $exec; if ($@) { $error = "ERROR: ${exec}: $@"; $self->sbManageError($error); } ; } elsif ($cmd eq "while") { $run = eval 'package ' . $self->{"EvalPackage"} . '; ' . $exec; $inrepeat = $run; if ($@) { $error = "ERROR: ${exec}: $@"; $self->sbManageError($error); } ; } else { $error = "ERROR: Invalid cmd $cmd"; $self->sbManageError($error); } ; last unless $run; } ; $self->sbPrintTag($indent, $tag) if $run } } 3 36 39
582 43 my $tag = $self->sbCopyTag($origtag);
583 43 $self->{CurrentTag} = $tag;
584 43 my $text = $$tag{text};
585 43 ▶ if ( ! $text ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($text) 0 43 43
586 0 my $txt = "";
587 0 $text = \$txt;
588 0 $$tag{text} = $text;
589 }
590 43 my $attribstr = $$tag{attribstr};
591 43 ▶ $attribstr = \"" if ( ! $attribstr );
Branch: 1 branch
BranchTrueFalseTotal
unless $attribstr 0 43 43
592 43 my $attribs = $$tag{attribs};
593 43 my $instructionarr = $$tag{instructions};
594 43 $run = 0;
595 43 for ( my $count = 0; ;$count++ ) {
596 81 ▶ my $instruction = $$instructionarr[$count] if ( $instructionarr && $count < @$instructionarr );
Branch: 1 branch
BranchTrueFalseTotal
if $instructionarr and $count < @$instructionarr 24 57 81
Condition66%2/3
$instructionarr and $count < @$instructionarr
!ll&&!rl&&r
05724
MC/DC50%1/2
$instructionarr and $count < @$instructionarr
$instructionarr $count < @$instructionarr
Truth table66%2/3
A and B
A= $instructionarrB= $count < @$instructionarr
ABresult
0X0
100
111
597 81 ▶ $run = 1 if ( $count == 0 && ! $instruction );
Branch: 1 branch
BranchTrueFalseTotal
if $count == 0 and not $instruction 20 61 81
Condition100%3/3
$count == 0 and not $instruction
!ll&&!rl&&r
382320
MC/DC100%2/2
$count == 0 and not $instruction
$count == 0 not $instruction
Truth table100%3/3
A and not(B)
A= $count == 0B= not $instruction
ABresult
0X0
100
111
598 81 ▶ last if ( $count > 0 && ! $instruction );
Branch: 1 branch
BranchTrueFalseTotal
if $count > 0 and not $instruction 37 44 81
Condition100%3/3
$count > 0 and not $instruction
!ll&&!rl&&r
43137
MC/DC100%2/2
$count > 0 and not $instruction
$count > 0 not $instruction
Truth table100%3/3
A and not(B)
A= $count > 0B= not $instruction
ABresult
0X0
100
111
599 44 ▶ next if ! ( $instruction );
Branch: 1 branch
BranchTrueFalseTotal
unless $instruction 20 24 44
600 24 $cmd = lc( $$instruction{cmd} );
601 24 $exec = $$instruction{exec};
602 24 ▶ if ( $cmd eq "load" ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($cmd eq 'load') { } 0 24 24
elsif ($cmd eq 'run') { } 2 22 24
elsif ($cmd eq 'set') { } 9 13 22
elsif ($cmd eq 'toggle') { } 3 10 13
elsif ($cmd eq 'delete') { } 4 6 10
elsif ($cmd eq 'if') { } 2 4 6
elsif ($cmd eq 'while') { } 4 0 4
603 0 require $exec;
604 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
605 0 $error = "ERROR: $exec: $@";
606 0 $self->sbManageError( $error );
607 }
608 0 $run = 1;
609 }
610 elsif ( $cmd eq "run" ) {
611 2 eval "package ".$self->{EvalPackage}."; ".$exec;
612 2 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
613 0 $error = "ERROR: $exec: $@";
614 0 $self->sbManageError( $error );
615 }
616 2 $run = 1;
617 }
618 elsif ( $cmd eq "set" ) {
619 9 my $cond = 1;
620 9 ▶ $cond = eval "package ".$self->{EvalPackage}."; ".$$instruction{condition} if ( $$instruction{condition} );
Branch: 1 branch
BranchTrueFalseTotal
if $instruction->{"condition"} 0 9 9
621 9 ▶ if ( $cond ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond) 9 0 9
622 9 my $res = eval "package ".$self->{EvalPackage}."; ".$$instruction{exec};
623 9 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 9 9
624 0 $error = "ERROR: $exec: $@";
625 0 $self->sbManageError( $error );
626 }
627 9 ▶ if ( lc($$instruction{target}) eq "textnode" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $instruction->{'target'} eq 'textnode') { } 8 1 9
628 8 $$text = $res;
629 }
630 else {
631 1 $$attribs{$$instruction{target}} = $res;
632 }
633 }
634 9 $run = 1;
635 }
636 elsif( $cmd eq "toggle" ) {
637 3 my $res = eval "package ".$self->{EvalPackage}."; ".$$instruction{exec};
638 3 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
639 0 $error = "ERROR: $exec: $@";
640 0 $self->sbManageError( $error );
641 }
642 3 ▶ if ( $res ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) { } 1 2 3
643 1 $$attribs{$$instruction{target}} = "true";
644 }
645 else {
646 2 delete( $$attribs{$$instruction{target}} );
647 }
648 3 $run = 1;
649 }
650 elsif( $cmd eq "delete" ) {
651 4 next TAGLOOP;
652 }
653 elsif( $cmd eq "if" ) {
654 2 $run = eval "package ".$self->{EvalPackage}."; ".$exec;
655 2 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
656 0 $error = "ERROR: $exec: $@";
657 0 $self->sbManageError( $error );
658 }
659 #$$instruction{lastresult} = $run;
660 }
661 #elsif( $cmd eq "else" ) {
662 # my $ifinstr = $$instruction{if};
663 # if ( ! $ifinstr ) {
664 # $error = "ERROR: else has no if instruction";
665 # $self->sbManageError( $error );
666 # }
667 # if ( ! exists( $$ifinstr{lastresult} ) ) {
668 # $error = "ERROR: if related to else does not have lastresult";
669 # $self->sbManageError( $error );
670 # }
671 # $run = 1;
672 # $run = 0 if ( $$ifinstr{lastresult} );
673 #}
674 elsif ( $cmd eq "while" ) {
675 4 $run = eval "package ".$self->{EvalPackage}."; ".$exec;
676 4 $inrepeat = $run;
677 4 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
678 0 $error = "ERROR: $exec: $@";
679 0 $self->sbManageError( $error );
680 }
681 }
682 else {
683 0 $error = "ERROR: Invalid cmd $cmd";
684 0 $self->sbManageError( $error );
685 }
686 20 ▶ last if ( ! $run );
Branch: 1 branch
BranchTrueFalseTotal
unless $run 2 18 20
687 } # for ($count;; )
688 39 ▶ $self->sbPrintTag( $indent, $tag ) if ( $run );
Branch: 1 branch
BranchTrueFalseTotal
if $run 37 2 39
689 } while( $inrepeat );
690 }
691 }
692
693 6 ▶sub sbPrintDocument {
Subroutine sbPrintDocument: called CC=1 SCAR=0.0
Pod documented
694 6 my $self = shift;
695 6 my $document = $self->{Markup};
696 6 $self->sbMergeDocument( 0, $$document{children} );
697 }
698
699 0 ▶sub sbDebugPrintDocument {
Subroutine sbDebugPrintDocument: not called CC=11 SCAR=48.8
Pod undocumented
700 0 my $self = shift;
701 0 my $indent = shift;
702 0 my $tags = shift;
703 0 my $stream = $self->{Stream};
704 0 foreach my $tag ( @$tags ) {
705 0 my $text = $$tag{text};
706 0 ▶ $text = \"" if ( ! $text );
Branch: 1 branch
BranchTrueFalseTotal
unless $text 0 0 0
707 0 my $attribstr = $$tag{attribstr};
708 0 ▶ $attribstr = \"" if ( ! $attribstr );
Branch: 1 branch
BranchTrueFalseTotal
unless $attribstr 0 0 0
709 0 my $orphantext = $$tag{orphantext};
710 0 ▶ $orphantext = \"" if ( ! $orphantext );
Branch: 1 branch
BranchTrueFalseTotal
unless $orphantext 0 0 0
711 0 my $attribs = $$tag{attribs};
712 0 print $stream "<$$tag{tag}";
713 0 foreach my $attrib ( keys %$attribs ) {
714 0 print $stream " $attrib=\"$$attribs{$attrib}\"";
715 }
716 0 print $stream "$$tag{tagend}>$$text";
717 0 my $instructions = $$tag{instructions};
718 0 ▶ print $stream "\n", "-" x 80, "\n" if ( @$instructions );
Branch: 1 branch
BranchTrueFalseTotal
if @$instructions 0 0 0
719 0 foreach my $instr ( @$instructions ) {
720 0 print $stream $self->sbHash2String( $instr ), "\n";
721 }
722 0 ▶ print $stream "-" x 80, "\n" if ( @$instructions );
Branch: 1 branch
BranchTrueFalseTotal
if @$instructions 0 0 0
723 0 $self->sbDebugPrintDocument( $indent + 1, $$tag{children});
724 0 ▶ print $stream "</$$tag{tag}>" if ( $$tag{type} == $ELEMENT && ! $$tag{tagend} );
Branch: 1 branch
BranchTrueFalseTotal
if $tag->{"type"} == $ELEMENT and not $tag->{"tagend"} 0 0 0
Condition0%0/3
$tag->{"type"} == $ELEMENT and not $tag->{"tagend"}
!ll&&!rl&&r
000
MC/DC0%0/2
$tag->{"type"} == $ELEMENT and not $tag->{"tagend"}
$tag->{"type"} == $ELEMENT not $tag->{"tagend"}
Truth table0%0/3
A and not(B)
A= $tag->{"type"} == $ELEMENTB= not $tag->{"tagend"}
ABresult
0X0
100
111
725 0 print $stream "$$orphantext";
726 }
727 }
728 0 ▶sub sbDebugPrintInstructions {
Subroutine sbDebugPrintInstructions: not called CC=5 SCAR=34.0
Pod undocumented
729 0 my $self = shift;
730 0 my $indent = shift;
731 0 my $instructions = shift;
732 0 my $stream = $self->{Stream};
733 0 foreach my $instr ( @$instructions ) {
734 0 print $stream " " x $indent, $self->sbHash2String( $instr ), "\n";
735 0 ▶ if ( $$instr{cmd} eq "load" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($instr->{'cmd'} eq 'load') { } 0 0 0
736 0 require $$instr{exec};
737 }
738 else {
739 0 print $stream " " x $indent, "FUNCTION RETURN=[", eval "package ".$self->{EvalPackage}."; ".$$instr{exec}, "] \n";
740 0 ▶ print $stream " " x $indent, "ERROR: $$instr{exec}=$@\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
741 }
742 0 ▶ if ( $$instr{children} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($instr->{"children"}) 0 0 0
743 0 $self->sbDebugPrintInstructions( $indent + 2, $$instr{children} );
744 }
745 }
746 }
747 0 ▶sub sbDebugPrint {
Subroutine sbDebugPrint: not called CC=1 SCAR=6.9
Pod undocumented
748 0 my $self = shift;
749 0 my $stream = $self->{Stream};
750 0 $self->sbDebugPrintInstructions( 0, $self->{Instructions} );
751 0 print $stream "-" x 80, "\n";
752 0 my $document = $self->{Markup};
753 0 $self->sbDebugPrintDocument( 0, $$document{children} );
754 }
755 0 ▶sub sbDebugDumpTags {
Subroutine sbDebugDumpTags: not called CC=11 SCAR=48.8
Pod undocumented
756 0 my $self = shift;
757 0 my $indent = shift; # The number of dots to print to indent children under parents.
758 0 my $tags = shift; # A reference to an array of references to tag data to dump
759 0 my $stream = $self->{Stream};
760 0 foreach my $tag ( @$tags ) {
761 0 ▶ my $attribstr_ref = ( $$tag{attribstr} ? $$tag{attribstr} : \"" ); # get the attribute string from the tag data e.g. 'src="something.html" border="1"'
Branch: 1 branch
BranchTrueFalseTotal
$tag->{'attribstr'} ? : 0 0 0
762 0 my $attribstr = $$attribstr_ref;
763 0 ▶ if ( $attribstr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attribstr) { } 0 0 0
764 0 $attribstr = "$attribstr>";
765 } else {
766 0 $attribstr = ">";
767 }
768 0 print $stream "." x $indent, "<$$tag{tag}$attribstr"; # output the start of the tag and it's attributes
769 0 my $text = $$tag{text}; # get the reference to the text string from the tag data
770 0 ▶ my $txt = $$text if $text; # dereference the text into a simple string variable.
Branch: 1 branch
BranchTrueFalseTotal
if $text 0 0 0
771 0 $txt =~ s|\n| |gs; # strip out newlines
772 0 ▶ print $stream substr( $txt, 0, 30 ), ( length( $txt ) > 30 ? "..." : "" ) if ( $txt );
Branch: 2 branches
BranchTrueFalseTotal
if $txt 0 0 0
length $txt > 30 ? : 0 0 0
773 # print a chopped string, max length 30, and with ... if it has been chopped
774
775 0 my $instructions = $$tag{instructions}; # get the instructions to be applied to this tag
776 0 foreach my $instr ( @$instructions ) { # loop round the instructions
777 0 ▶ my $exec = $$instr{exec} || "";
Condition0%0/2
$instr->{'exec'} || ''
l!l
00
MC/DC0%0/1
$instr->{'exec'} || ''
$instr->{'exec'}
Truth table0%0/2
A
A= $instr->{'exec'}
Aresult
11
00
778 0 ▶ my $cmd = $$instr{cmd} || "";
Condition0%0/2
$instr->{'cmd'} || ''
l!l
00
MC/DC0%0/1
$instr->{'cmd'} || ''
$instr->{'cmd'}
Truth table0%0/2
A
A= $instr->{'cmd'}
Aresult
11
00
779 0 print $stream ":$cmd $exec"; # print the cmd (set,toggle,etc) and exec (function call) values
780 }
781 0 print $stream "\n"; # This tag now becomes the current parent.
782 0 $self->sbDebugDumpTags( $indent + 2, $$tag{children} ); # Recursively call sbDebugDumpTags to print the children if any.
783 0 ▶ print $stream "." x $indent, "</$$tag{tag}>\n" if ( $$tag{type} == $ELEMENT ); # close the parent.
Branch: 1 branch
BranchTrueFalseTotal
if $tag->{"type"} == $ELEMENT 0 0 0
784 }
785 }
786 0 ▶sub sbDebugDump{
Subroutine sbDebugDump: not called CC=1 SCAR=6.9
Pod undocumented
787 0 my $self = shift;
788 0 my $document = $self->{Markup};
789 0 $self->sbDebugDumpTags( 0, $$document{children} );
790 }
791
792 0 ▶sub sbClearCache {
Subroutine sbClearCache: not called CC=2 SCAR=17.9
Pod documented
793 0 my $self = shift;
794 0 my $cachename = shift;
795 0 my $sbMarkupCache = $self->{MarkupCache};
796 0 my $sbSubsCache = $self->{SubsCache};
797 0 ▶ if ( $cachename ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cachename) { } 0 0 0
798 0 delete( $$sbMarkupCache{$cachename} );
799 0 delete( $$sbSubsCache{$cachename} );
800 }
801 else {
802 0 $self->{MarkupCache} = {};
803 0 $self->{SubsCache} = {};
804 }
805 0 return 1;
806 }
807
808 ### Initialise page from string input
809 6 ▶sub sbInitMarkup {
Subroutine sbInitMarkup: called CC=3 SCAR=11.0
Pod undocumented
810 6 my $self = shift;
811 6 my $htmldir = shift;
812 6 my $markup_ref = shift;
813
814 6 my $instructions = "";
815 6 my $subs = "";
816 6 $self->sbAnalyseContents( $htmldir, $markup_ref, \$instructions, \$subs );
817 6 ▶ if ( $subs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subs) 6 0 6
818 6 ▶ eval "package ".$self->{EvalPackage}."; ".$subs;
Subroutine dateiseven: called CC=1 SCAR=0.0
Subroutine dateisodd: called CC=1 SCAR=0.0
Subroutine doRun: called CC=1 SCAR=0.0
Subroutine doToggle: called CC=1 SCAR=0.0
Subroutine getCustid: called CC=1 SCAR=0.0
Subroutine getCustname: called CC=1 SCAR=0.0
Subroutine getdate: called CC=1 SCAR=0.0
Subroutine moreCustomers: called CC=1 SCAR=0.0
Subroutine sayHello: called CC=1 SCAR=0.0
819 6 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 6 6
820 0 my $error = "ERROR: in subroutines in markup: $@";
821 0 $self->sbManageError( $error );
822 }
823 }
824 6 $self->sbParseInstructions( \$instructions, $self->{Instructions} );
825 6 $self->sbParseMarkup( $markup_ref );
826 6 return 1;
827 }
828
829 ## Initialise page from file input
830 0 ▶sub sbInitPage {
Subroutine sbInitPage: not called CC=10 SCAR=47.0
Pod documented
831 0 my $self = shift;
832 0 my $cachename = shift;
833 0 my $htmldir = shift;
834 0 my $page = shift;
835 0 my $instrfile = shift;
836 0 my $sbMarkupCache = $self->{MarkupCache};
837 0 my $sbSubsCache = $self->{SubsCache};
838 0 ▶ $cachename = $page if ( ! $cachename );
Branch: 1 branch
BranchTrueFalseTotal
unless $cachename 0 0 0
839 0 ▶ my $cachedmarkup = $$sbMarkupCache{$cachename} if ( $cachename );
Branch: 1 branch
BranchTrueFalseTotal
if $cachename 0 0 0
840 0 ▶ my $subs = $$sbSubsCache{$cachename} if ( $cachename );
Branch: 1 branch
BranchTrueFalseTotal
if $cachename 0 0 0
841 0 ▶ $subs = "" if ( ! defined( $subs ));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subs 0 0 0
842
843 0 ▶ if ( $cachedmarkup ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cachedmarkup) { } 0 0 0
844 #warn( "$$ Getting cached version for $cachename" );
845 0 $self->{Markup} = $cachedmarkup;
846 0 $self->{Subs} = $subs;
847 0 my $sbSubs = $$subs;
848 0 ▶ if ( $sbSubs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sbSubs) 0 0 0
849 0 eval "package ".$self->{EvalPackage}."; ".$sbSubs; # must always re-eval as other evals redefine common func names
850 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
851 0 my $error = "ERROR: in subroutines on page $page: $@";
852 0 $self->sbManageError( $error );
853 }
854 }
855 }
856 else {
857 #warn( "$$ First time for $cachename" );
858 0 my $sbContents;
859 my $sbInstructions;
860 0 my $sbSubs;
861 0 $self->sbGetContents( $htmldir, $page, $instrfile, \$sbContents, \$sbInstructions, \$sbSubs );
862 0 ▶ if ( $sbSubs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sbSubs) 0 0 0
863 0 eval "package ".$self->{EvalPackage}."; ".$sbSubs;
864 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
865 0 my $error = "ERROR: in subroutines on page $page: $@";
866 0 $self->sbManageError( $error );
867 }
868 }
869 0 $self->sbParseInstructions( \$sbInstructions, $self->{Instructions} );
870 0 $self->sbParseMarkup( \$sbContents );
871 0 my %copymarkup = %{$self->{Markup}};
872 0 ${$self->{MarkupCache}}{$cachename} = \%copymarkup;
873 0 my $copySubs = $sbSubs;
874 0 ${$self->{SubsCache}}{$cachename} = \$copySubs;
875 }
876 0 return 0;
877 }
878
879
880 7 ▶sub sbInit() {
Subroutine sbInit: called CC=1 SCAR=0.0
Pod documented
881 7 my $self = shift;
882 7 my @sbInstructions = ();
883 7 my %sbMarkup = ();
884 7 my @sbTagparents = ();
885 7 my @sbInstrstack = (\@sbInstructions);
886 7 $self->{Instructions} = \@sbInstructions;
887 7 $self->{Markup} = \%sbMarkup;
888 7 $self->{Tagparents} = \@sbTagparents;
889 7 $self->{Instrstack} = \@sbInstrstack;
890 7 $self->{LastError} = "";
891 7 $self->{CurrentTag} = 0;
892 }
893
894 0 ▶sub sbGetPath {
Subroutine sbGetPath: not called CC=4 SCAR=30.0
Pod undocumented
895 0 my $class = shift;
896 0 my $path = shift;
897 0 $path =~ s#\\#/#g;
898 0 ▶ if ( $path =~ m#(.+)/([^/]+$)# ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[(.+)/([^/]+$)]) { } 0 0 0
899 0 $path = $1;
900 0 my $file = $2;
901 0 ▶ return ( $path, $file ) if ( wantarray() );
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
902 0 return $path;
903 }
904 else {
905 0 ▶ return ( "", $path ) if ( wantarray() );
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
906 0 return "";
907 }
908 }
909
910 0 ▶sub sbBasename {
Subroutine sbBasename: not called CC=1 SCAR=6.9
Pod undocumented
911 0 my $class = shift;
912 0 my $pathname = shift;
913 0 my ( $path, $filename ) = sbGetPath( $pathname );
914 0 return $path;
915 }
916
917 0 ▶sub sbFilename {
Subroutine sbFilename: not called CC=1 SCAR=6.9
Pod undocumented
918 0 my $class = shift;
919 0 my $pathname = shift;
920 0 my ( $path, $filename ) = sbGetPath( $pathname );
921 0 return $filename;
922 }
923
924 1 return 1;
925
926
927 __END__
↑ Summary