lib/WebDyne/Compile.pm

filter: Statementstmt 81.2% 324 / 399 Branchbran 51.7% 91 / 176 Conditioncond 46.5% 82 / 176 MC/DCmcdc 15.0% 14 / 93 Subroutinesub 95.4% 21 / 22 Podpod 0.0% 0 / 6 totaltotal 61.0% 532 / 872 CC 170 SCAR 57.5
CC
170
Cov
66%
compile
692.6
__ANON__
76.4
__ANON__
53.5
CRAP 312.7
« lib/WebDyne/Err.pm ↑ Summary lib/WebDyne/HTML/Tiny.pm »
1 #
2 # This file is part of WebDyne.
3 #
4 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 # Full license text is available at:
10 #
11 # <http://dev.perl.org/licenses/>
12 #
13 package WebDyne::Compile;
14  
15  
16 # Pragma
17 #
18 1 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use vars qw($VERSION %CGI_TAG_WEBDYNE %CGI_TAG_FORM %CGI_TAG_IMPLICIT);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶no warnings qw(uninitialized redefine once);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23  
24 # External Modules
25 #
26 1 ▶use WebDyne;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use WebDyne::HTML::TreeBuilder;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32  
33 # WebDyne Modules
34 #
35 1 ▶use WebDyne::HTML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39  
40 # Version information
41 #
42 1 $VERSION='3.029';
43  
44  
45 # Debug load
46 #
47 1 debug("Loading %s version $VERSION", __PACKAGE__);
48  
49  
50 # Get WebDyne and CGI tags from TreeBuilder module
51 #
52 1 *CGI_TAG_WEBDYNE=\%WebDyne::CGI_TAG_WEBDYNE;
53 1 *CGI_TAG_FORM=\%WebDyne::HTML::TreeBuilder::CGI_TAG_FORM;
54 1 *CGI_TAG_IMPLICIT=\%WebDyne::HTML::TreeBuilder::CGI_TAG_IMPLICIT;
55  
56  
57 # Var to hold package wide hash, for data shared across package
58 #
59 1 my %Package;
60  
61  
62 # All done. Positive return
63 #
64 1 1;
65  
66  
67 #==================================================================================================
68  
69  
70 # Packace init, attempt to load optional Time::HiRes module
71 #
72 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
73 1 eval {require Time::HiRes; Time::HiRes->import('time')};
74 1 eval {require Devel::Confess; Devel::Confess->import(qw(no_warnings))};
75 1 ▶ eval {} if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
76 }
77  
78  
79 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
80  
81  
82 # Only used when debugging from outside apache, eg test script. If so, user
83 # must create new object ref, then run the compile. See wdcompile script for
84 # example. wdcompile is only used for debugging - we do some q&d stuff here
85 # to make it work
86 #
87 0 my ($class, @opt)=@_;
88 0 ▶ my %opt=(ref($opt[0]) eq 'HASH') ? %{$opt[0]} : @opt;
Branch: 1 branch
BranchTrueFalseTotal
ref $opt[0] eq 'HASH' ? : 0 0 0
89 0 debug("$class, opt: %s", Dumper(\%opt));
90  
91  
92 # Init WebDyne module
93 #
94 0 require WebDyne::Request::Fake;
95 0 ▶ my $r=WebDyne::Request::Fake->new( filename=> ( $opt{'filename'} || $opt{'srce'} ), no_head_insert=>$opt{'no_head_insert'} );
Condition0%0/3
$opt{'filename'} || $opt{'srce'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt{'filename'} || $opt{'srce'}
$opt{'filename'} $opt{'srce'}
Truth table0%0/3
A || B
A= $opt{'filename'}B= $opt{'srce'}
ABresult
1X1
011
000
96  
97  
98 # Get appropriate cgi_or
99 #
100 0 ▶ my $html_tag_or=WebDyne::HTML::Tiny->new(mode => $WEBDYNE_HTML_TINY_MODE, r=>$r ) ||
Condition0%0/2
'WebDyne::HTML::Tiny'->new('mode', $WebDyne::Compile::WEBDYNE_HTML_TINY_MODE, 'r', $r) || (return err('unable to get new WebDyne::HTML::Tiny object'))
l!l
00
MC/DC0%0/1
'WebDyne::HTML::Tiny'->new('mode', $WebDyne::Compile::WEBDYNE_HTML_TINY_MODE, 'r', $r) || (return err('unable to get new WebDyne::HTML::Tiny object'))
'WebDyne::HTML::Tiny'->new('mode', $WebDyne::Compile::WEBDYNE_HTML_TINY_MODE, 'r', $r)
Truth table0%0/2
A
A= 'WebDyne::HTML::Tiny'->new('mode', $WebDyne::Compile::WEBDYNE_HTML_TINY_MODE, 'r', $r)
Aresult
11
00
101 return err('unable to get new WebDyne::HTML::Tiny object');
102  
103  
104 # New self ref
105 #
106 0 my %self=(
107  
108 _r => $r,
109 _CGI => $html_tag_or,
110  
111 );
112  
113  
114 # And return blessed ref
115 #
116 0 return bless(\%self, 'WebDyne');
117  
118 }
119  
120  
121 3 ▶sub compile {
Subroutine compile: called CC=79 SCAR=65.4
Pod undocumented
122  
123  
124 # Compile HTML file into Storable structure
125 #
126 3 my ($self, $param_hr)=@_;
127  
128  
129 # Start timer so we can log how long it takes us to compile a file
130 #
131 3 my $time=($self->{'_time'}=time());
132  
133  
134 # Init class if not yet done
135 #
136 3 ▶ (ref($self))->{_compile_init} ||= do {
Condition66%2/3
ref($self)->{"_compile_init"} ||= do { $self->compile_init or return err() }
l!l&&r!l&&!r
210
MC/DC0%0/2
ref($self)->{"_compile_init"} ||= do { $self->compile_init or return err() }
ref($self)->{"_compile_init"} do { $self->compile_init or return err() }
Truth table66%2/3
A ||= B
A= ref($self)->{"_compile_init"}B= do { $self->compile_init or return err() }
ABresult
1X1
011
000
137 1 ▶ $self->compile_init() || return err()
Condition50%1/2
$self->compile_init || (return err())
l!l
10
MC/DC0%0/1
$self->compile_init || (return err())
$self->compile_init
Truth table50%1/2
A
A= $self->compile_init
Aresult
11
00
138 };
139  
140  
141 # Debug
142 #
143 3 debug('compile %s', Dumper($param_hr));
144  
145  
146 # Get srce and dest
147 #
148 3 my ($html_cn, $dest_cn)=@{$param_hr}{qw(srce dest)};
149  
150  
151 # Need request object ref
152 #
153 3 ▶ my $r=$self->{'_r'} || $self->r() || return err();
Condition40%2/5
$self->{'_r'} || $self->r || (return err())
l!l
30
$self->{"_r"} or $self->r
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->{'_r'} || $self->r || (return err())
$self->{"_r"} $self->r
Truth table33%1/3
A or B
A= $self->{"_r"}B= $self->r
ABresult
1X1
011
000
154  
155  
156 # Open the file
157 #
158 3 ▶ my $html_fh=IO::File->new($html_cn, O_RDONLY) ||
Condition50%1/2
'IO::File'->new($html_cn, 0) || (return err("unable to open file $html_cn, $!"))
l!l
30
MC/DC0%0/1
'IO::File'->new($html_cn, 0) || (return err("unable to open file $html_cn, $!"))
'IO::File'->new($html_cn, 0)
Truth table50%1/2
A
A= 'IO::File'->new($html_cn, 0)
Aresult
11
00
159 return err("unable to open file $html_cn, $!");
160  
161  
162 # Keep trailing __PERL__/__CODE__ bodies out of HTML::Parser. The marker
163 # itself still goes through TreeBuilder so the normal internal perl node is
164 # created, but operators like s/</.../ are not tokenised as HTML.
165 #
166 3 my $perl_sr;
167 {
168 3 local $/;
169 3 my $source=<$html_fh>;
170 3 ▶ if ($source=~/\A(.*?)(^[ \t]*__(?:PERL|CODE)__\b[^\r\n]*(?:\r?\n|\r)?)(.*)\z/sm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source =~ /\A(.*?)(^[ \t]*__(?:PERL|CODE)__\b[^\r\n]*(?:\r?\n|\r)?)(.*)\z/ms) 3 0 3
171 3 my ($html, $marker, $perl)=($1, $2, $3);
172 3 $html.=$marker;
173 3 $perl_sr=\$perl;
174 3 ▶ open(my $html_split_fh, '<', \$html) ||
Branch: 1 branch
BranchTrueFalseTotal
open my $html_split_fh, "<", \$html or return err("unable to open scalar source for $html_cn, $!") 3 0 3
175 return err("unable to open scalar source for $html_cn, $!");
176 3 $html_fh=$html_split_fh;
177 }
178 3 ▶ unless ($perl_sr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($perl_sr) 0 3 3
179 0 ▶ seek($html_fh, 0, 0) ||
Branch: 1 branch
BranchTrueFalseTotal
seek $html_fh, 0, 0 or return err("unable to rewind file $html_cn, $!") 0 0 0
180 return err("unable to rewind file $html_cn, $!");
181 }
182 }
183  
184  
185 # Read over file handle until we get to the first non-comment line (ignores auto added copyright statements). Update - do
186 # this in Treebuilder code now so can account for comments when counting line numbers
187 #
188 3 while (0) {
189 my $pos=tell($html_fh);
190 my $line=<$html_fh>;
191 if ($line=~/^#/) {
192 next;
193 }
194 else {
195 seek($html_fh, $pos, 0);
196 last;
197 }
198 }
199
200
201 # Supply html_tiny object ref to Treebuilder so it can run things like start_html
202 #
203 3 ▶ my $html_tiny_or=$self->html_tiny() ||
Condition50%1/2
$self->html_tiny || (return err('unable to get html_tiny_or ref'))
l!l
30
MC/DC0%0/1
$self->html_tiny || (return err('unable to get html_tiny_or ref'))
$self->html_tiny
Truth table50%1/2
A
A= $self->html_tiny
Aresult
11
00
204 return err('unable to get html_tiny_or ref');
205  
206  
207 # Get new TreeBuilder object. Note api_version flows through to HTML::Parser constructor
208 #
209 3 ▶ my $tree_or=WebDyne::HTML::TreeBuilder->new(
Condition50%1/2
'WebDyne::HTML::TreeBuilder'->new('api_version', 3, 'html_tiny_or', $html_tiny_or, 'r', $r) || (return err('unable to create HTML::TreeBuilder object'))
l!l
30
MC/DC0%0/1
'WebDyne::HTML::TreeBuilder'->new('api_version', 3, 'html_tiny_or', $html_tiny_or, 'r', $r) || (return err('unable to create HTML::TreeBuilder object'))
'WebDyne::HTML::TreeBuilder'->new('api_version', 3, 'html_tiny_or', $html_tiny_or, 'r', $r)
Truth table50%1/2
A
A= 'WebDyne::HTML::TreeBuilder'->new('api_version', 3, 'html_tiny_or', $html_tiny_or, 'r', $r)
Aresult
11
00
210  
211 api_version => 3,
212 html_tiny_or => $html_tiny_or,
213 r => $r
214  
215 ) || return err('unable to create HTML::TreeBuilder object');
216  
217  
218 # Make sure this is off
219 #
220 3 $tree_or->unbroken_text(0);
221  
222  
223 # Tell HTML::TreeBuilder we do *not* want to ignore tags it
224 # considers "unknown". Since we use <PERL> and <BLOCK> tags,
225 # amongst other things, we need these to be in the tree
226 #
227 3 $tree_or->ignore_unknown(0);
228  
229  
230 # Tell it if we also want to see comments, use XML mode
231 #
232 $tree_or->store_comments(exists($param_hr->{'store_comments'})
233 3 ▶ ? $param_hr->{'store_comments'}
Branch: 1 branch
BranchTrueFalseTotal
exists $param_hr->{'store_comments'} ? : 0 3 3
234 : $WEBDYNE_STORE_COMMENTS
235 );
236 3 $tree_or->xml_mode(1); # Older versions on HTML::TreeBuilder
237  
238  
239 # No space compacting ?
240 #
241 $tree_or->ignore_ignorable_whitespace(exists($param_hr->{'ignore_ignorable_whitespace'})
242 3 ▶ ? $param_hr->{'ignore_ignorable_whitespace'}
Branch: 1 branch
BranchTrueFalseTotal
exists $param_hr->{'ignore_ignorable_whitespace'} ? : 0 3 3
243 : $WEBDYNE_COMPILE_IGNORE_WHITESPACE
244 );
245 $tree_or->no_space_compacting(exists($param_hr->{'no_space_compacting'})
246 3 ▶ ? $param_hr->{'no_space_compacting'}
Branch: 1 branch
BranchTrueFalseTotal
exists $param_hr->{'no_space_compacting'} ? : 0 3 3
247 : $WEBDYNE_COMPILE_NO_SPACE_COMPACTING
248 );
249  
250  
251 # Get code ref closure of file to be parsed
252 #
253 3 ▶ my $parse_cr=$tree_or->parse_fh($html_fh) ||
Condition50%1/2
$tree_or->parse_fh($html_fh) || (return err())
l!l
30
MC/DC0%0/1
$tree_or->parse_fh($html_fh) || (return err())
$tree_or->parse_fh($html_fh)
Truth table50%1/2
A
A= $tree_or->parse_fh($html_fh)
Aresult
11
00
254 return err();
255  
256  
257 # Muck around with strictness of P tags
258 #
259 $tree_or->p_strict(
260 exists($param_hr->{'p_strict'})
261 3 ▶ ? $param_hr->{'p_strict'}
Branch: 1 branch
BranchTrueFalseTotal
exists $param_hr->{'p_strict'} ? : 0 3 3
262 : $WEBDYNE_COMPILE_P_STRICT
263 );
264 $tree_or->implicit_body_p_tag(
265 exists($param_hr->{'implicit_body_p_tag'})
266 3 ▶ ? $param_hr->{'implicit_body_p_tag'}
Branch: 1 branch
BranchTrueFalseTotal
exists $param_hr->{'implicit_body_p_tag'} ? : 0 3 3
267 : $WEBDYNE_COMPILE_IMPLICIT_BODY_P_TAG
268 );
269  
270  
271 # Now parse through the file, running eof at end as per HTML::TreeBuilder
272 # man page.
273 #
274 3 $tree_or->parse($parse_cr);
275 3 ▶ if ($perl_sr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_sr) 3 0 3
276 3 ▶ my $html_perl_or=$tree_or->{'_html_perl_or'} ||
Condition50%1/2
$tree_or->{'_html_perl_or'} || (return err('unable to locate __PERL__ node for raw perl source'))
l!l
30
MC/DC0%0/1
$tree_or->{'_html_perl_or'} || (return err('unable to locate __PERL__ node for raw perl source'))
$tree_or->{'_html_perl_or'}
Truth table50%1/2
A
A= $tree_or->{'_html_perl_or'}
Aresult
11
00
277 return err('unable to locate __PERL__ node for raw perl source');
278 3 my $perl="\n".${$perl_sr};
279 3 ▶ $perl.=$/ unless $perl=~/(?:\r?\n|\r)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $perl =~ /(?:\r?\n|\r)$/ 0 3 3
280 3 $html_perl_or->attr('perl', $perl);
281 }
282
283  
284 # Close handler if anything goes wrong below
285 #
286 3 ▶ my $close_cr=sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
287  
288 3 $tree_or->delete;
289 3 undef $tree_or;
290  
291 3 };
292  
293  
294 # Any errors ? Make sure clean-up before throwing error.
295 #
296 3 ▶ if (errstr()) {
Branch: 1 branch
BranchTrueFalseTotal
if (errstr()) 0 3 3
297 0 return err($close_cr->())
298 }
299  
300  
301 # So far so good. Close tree and file
302 #
303 3 $tree_or->eof();
304 3 $html_fh->close();
305
306
307 # Set flag (tagname) if we have seen <api> or <htmx> tags and want to compact
308 # our tree to remove unneccessary <html><head><body> etc. since these
309 # tags will never emit a full html page when used for real. Do here as lost
310 # after elementify
311 #
312 3 my $compact_tag=$tree_or->{'_webdyne_compact'};
313 3 debug("compact_tag: $compact_tag");
314
315  
316 # Elementify
317 #
318 3 ▶ $tree_or->elementify() ||
Branch: 1 branch
BranchTrueFalseTotal
$tree_or->elementify or return &$close_cr() 3 0 3
319 return $close_cr->();
320  
321  
322 # Now start iterating through the treebuilder object, creating
323 # our own array tree structure. Do this in a separate method that
324 # is rentrant as the tree is descended
325 #
326 my %meta=(
327 3 ▶ manifest => $param_hr->{'no_manifest'} ? undef : [$html_cn]
Branch: 1 branch
BranchTrueFalseTotal
$param_hr->{'no_manifest'} ? : 0 3 3
328 );
329 3 ▶ my $data_ar=$self->parse($tree_or, \%meta) || do {
Condition33%1/3
$self->parse($tree_or, \%meta) || do { return err(&$close_cr()) }
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->parse($tree_or, \%meta) || do { return err(&$close_cr()) }
$self->parse($tree_or, \%meta) do { return err(&$close_cr()) }
Truth table33%1/3
A || B
A= $self->parse($tree_or, \%meta)B= do { return err(&$close_cr()) }
ABresult
1X1
011
000
330 0 return err($close_cr->());
331 };
332 3 debug("meta after parse %s", Dumper(\%meta));
333
334
335 # Now destroy the HTML::Treebuilder object, or else mem leak occurs
336 #
337 3 $close_cr->();
338  
339  
340 # Meta block. Add any webdyne meta data to parse tree
341 #
342 3 ▶ my $head_ar=$self->find_node(
Condition50%1/2
$self->find_node({'data_ar', $data_ar, 'tag', 'head'}) || (return err())
l!l
30
MC/DC0%0/1
$self->find_node({'data_ar', $data_ar, 'tag', 'head'}) || (return err())
$self->find_node({'data_ar', $data_ar, 'tag', 'head'})
Truth table50%1/2
A
A= $self->find_node({'data_ar', $data_ar, 'tag', 'head'})
Aresult
11
00
343 {
344  
345 data_ar => $data_ar,
346 tag => 'head',
347  
348 }) || return err();
349 3 ▶ my $meta_ar=$self->find_node(
Condition50%1/2
$self->find_node({'data_ar', $head_ar->[0], 'tag', 'meta', 'all_fg', 1}) || (return err())
l!l
30
MC/DC0%0/1
$self->find_node({'data_ar', $head_ar->[0], 'tag', 'meta', 'all_fg', 1}) || (return err())
$self->find_node({'data_ar', $head_ar->[0], 'tag', 'meta', 'all_fg', 1})
Truth table50%1/2
A
A= $self->find_node({'data_ar', $head_ar->[0], 'tag', 'meta', 'all_fg', 1})
Aresult
11
00
350 {
351  
352 data_ar => $head_ar->[0],
353 tag => 'meta',
354 all_fg => 1,
355  
356 }) || return err();
357 3 debug('meta_ar: %s', Dumper($meta_ar));
358 3 foreach my $tag_ar (@{$meta_ar}) {
359 6 ▶ my $attr_hr=$tag_ar->[WEBDYNE_NODE_ATTR_IX] || next;
Condition50%1/2
$tag_ar->[1] || (next)
l!l
60
MC/DC0%0/1
$tag_ar->[1] || (next)
$tag_ar->[1]
Truth table50%1/2
A
A= $tag_ar->[1]
Aresult
11
00
360 6 debug('meta attr_hr: %s', Dumper($attr_hr));
361 6 $attr_hr=$self->subst_attr(undef, $attr_hr);
362 6 debug('meta attr_hr post subst: %s', Dumper($attr_hr));
363 6 ▶ if ($attr_hr->{'name'}=~/^webdyne$/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attr_hr->{'name'} =~ /^webdyne$/i) { } 0 6 6
elsif (ref $attr_hr->{'content'} eq 'HASH') { } 0 6 6
364 0 my @meta=split(/;/, $attr_hr->{'content'});
365 0 debug('meta %s', Dumper(\@meta));
366 0 foreach my $meta (@meta) {
367 0 my ($name, $value)=split(/[=:]/, $meta, 2);
368 0 ▶ defined($value) || ($value=1);
Branch: 1 branch
BranchTrueFalseTotal
defined $value or $value = 1 0 0 0
369  
370 # Eval any meta attrs like @{}, %{}..
371 0 ▶ my $hr=$self->subst_attr(undef, {$name => $value}) ||
Condition0%0/2
$self->subst_attr(undef, {$name, $value}) || (return err())
l!l
00
MC/DC0%0/1
$self->subst_attr(undef, {$name, $value}) || (return err())
$self->subst_attr(undef, {$name, $value})
Truth table0%0/2
A
A= $self->subst_attr(undef, {$name, $value})
Aresult
11
00
372 return err();
373 0 $meta{$name}=$hr->{$name};
374 0 ▶ if ($name eq 'cache') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "cache") 0 0 0
375 0 ▶ $meta{'static'} ||= 1;
Condition0%0/2
$meta{"static"} ||= 1
l!l
00
MC/DC0%0/1
$meta{"static"} ||= 1
$meta{"static"}
Truth table0%0/2
A
A= $meta{"static"}
Aresult
11
00
376 }
377 }
378  
379 # Do not want anymore
380 $self->delete_node(
381 {
382  
383 0 ▶ data_ar => $data_ar,
Branch: 1 branch
BranchTrueFalseTotal
$self->delete_node({"data_ar", $data_ar, "node_ar", $tag_ar}) or return err() 0 0 0
384 node_ar => $tag_ar
385  
386 }) || return err();
387 }
388 elsif (ref($attr_hr->{'content'}) eq 'HASH') {
389 0 ▶ while (my($meta_key, $meta_value)=each %{$attr_hr->{'content'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$attr_hr{"content"};}) 0 0 0
390 0 ▶ if ($meta_key=~/^webdyne$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta_key =~ /^webdyne$/i) 0 0 0
391 0 my @meta=split(/;/, $meta_value);
392 0 debug('meta %s', Dumper(\@meta));
393 0 foreach my $meta (@meta) {
394 0 my ($name, $value)=split(/[=:]/, $meta, 2);
395 0 ▶ defined($value) || ($value=1);
Branch: 1 branch
BranchTrueFalseTotal
defined $value or $value = 1 0 0 0
396 0 $meta{$name}=$value;
397 0 ▶ if ($name eq 'cache') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "cache") 0 0 0
398 0 ▶ $meta{'static'} ||= 1;
Condition0%0/2
$meta{"static"} ||= 1
l!l
00
MC/DC0%0/1
$meta{"static"} ||= 1
$meta{"static"}
Truth table0%0/2
A
A= $meta{"static"}
Aresult
11
00
399 }
400 }
401 }
402 }
403 }
404 }
405
406
407 # And look for any static or cache tags found in start_html and noted
408 #
409 3 foreach my $attr (qw(static cache handler sse ws require import)) {
410 21 ▶ if (my $value=$html_tiny_or->{"_${attr}"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = $$html_tiny_or{"_$attr"}) 0 21 21
411 0 $meta{$attr}=$value;
412 }
413 }
414 3 debug('final inode meta: %s', Dumper(\%meta));
415
416
417 # If <api> or <htmx) tag used in page compress down to just the <api>/<htmx> nodes and throw
418 # everything else away.
419 #
420 3 ▶ if ($compact_tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compact_tag) 0 3 3
421
422 # Find all the api nodes
423 #
424 0 my $api_ar=$self->find_node({
425 data_ar => $data_ar,
426 tag => $compact_tag,
427 all_fg => 1
428 });
429
430
431 # And make a new data_ar structure to hold it, throwing everything else
432 # in the bin
433 #
434 0 $data_ar=[undef, undef, $api_ar];
435  
436 }
437
438  
439 # Construct final webdyne container
440 #
441 3 ▶ my @container=(keys %meta ? \%meta : undef, $data_ar);
Branch: 1 branch
BranchTrueFalseTotal
keys %meta ? : 3 0 3
442  
443  
444 # Quit if user wants to see tree at this stage (stage0 | opt0)
445 #
446 3 ▶ $param_hr->{'stage0'} && (return \@container);
Branch: 1 branch
BranchTrueFalseTotal
$param_hr->{"stage0"} and return \@container 0 3 3
447  
448  
449 # Store meta information for this instance so that when perl_init (or code running under perl_init)
450 # runs it can access meta data via $self->meta();
451 #
452 3 ▶ $self->{'_meta_hr'}=\%meta if keys %meta;
Branch: 1 branch
BranchTrueFalseTotal
if keys %meta 3 0 3
453 3 ▶ if ((my $perl_ar=$meta{'perl'}) && !$param_hr->{'no_perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $perl_ar = $meta{"perl"} and not $param_hr->{"no_perl"}) 3 0 3
Condition33%1/3
my $perl_ar = $meta{"perl"} and not $param_hr->{"no_perl"}
!ll&&!rl&&r
003
MC/DC0%0/2
my $perl_ar = $meta{"perl"} and not $param_hr->{"no_perl"}
my $perl_ar = $meta{"perl"} not $param_hr->{"no_perl"}
Truth table33%1/3
A and not(B)
A= my $perl_ar = $meta{"perl"}B= not $param_hr->{"no_perl"}
ABresult
0X0
100
111
454  
455 # This is inline __PERL__ perl. Must be executed before filter so any filters added by the __PERL__
456 # block are seen
457 #
458 3 my $perl_debug_ar=$meta{'perl_debug'};
459 3 ▶ $self->perl_init($perl_ar, $perl_debug_ar) || return err();
Branch: 1 branch
BranchTrueFalseTotal
$self->perl_init($perl_ar, $perl_debug_ar) or return err() 3 0 3
460  
461  
462 }
463  
464  
465 # Quit if user wants to see tree at this stage
466 #
467 3 ▶ $param_hr->{'stage1'} && (return \@container);
Branch: 1 branch
BranchTrueFalseTotal
$param_hr->{"stage1"} and return \@container 0 3 3
468  
469  
470 # Filter ?
471 #
472 3 my @filter=@{$meta{'webdynefilter'}};
473 3 ▶ unless (@filter) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@filter) 3 0 3
474 3 ▶ my $filter=$self->{'_filter'} || $r->dir_config('WebDyneFilter');
Condition33%1/3
$self->{'_filter'} || $r->dir_config('WebDyneFilter')
l!l&&r!l&&!r
003
MC/DC0%0/2
$self->{'_filter'} || $r->dir_config('WebDyneFilter')
$self->{'_filter'} $r->dir_config('WebDyneFilter')
Truth table33%1/3
A || B
A= $self->{'_filter'}B= $r->dir_config('WebDyneFilter')
ABresult
1X1
011
000
475 3 ▶ @filter=split(/\s+/, $filter) if $filter;
Branch: 1 branch
BranchTrueFalseTotal
if $filter 0 3 3
476 }
477 3 debug('filter %s', Dumper(\@filter));
478 3 ▶ if ((@filter) && !$param_hr->{'no_filter'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@filter and not $param_hr->{"no_filter"}) 0 3 3
Condition33%1/3
@filter and not $param_hr->{"no_filter"}
!ll&&!rl&&r
300
MC/DC0%0/2
@filter and not $param_hr->{"no_filter"}
@filter not $param_hr->{"no_filter"}
Truth table33%1/3
A and not(B)
A= @filterB= not $param_hr->{"no_filter"}
ABresult
0X0
100
111
479 0 local $SIG{'__DIE__'};
480 0 foreach my $filter (@filter) {
481 0 $filter=~s/::filter$//;
482 0 ▶ eval("require $filter") ||
Branch: 1 branch
BranchTrueFalseTotal
eval "require $filter" or return err("unable to load filter $filter, " . lcfirst($@)) 0 0 0
483 return err("unable to load filter $filter, " . lcfirst($@));
484 0 ▶ UNIVERSAL::can($filter, 'filter') ||
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::can($filter, "filter") or return err("custom filter '${filter}' does not seem to have a 'filter' method to call") 0 0 0
485 return err("custom filter '$filter' does not seem to have a 'filter' method to call");
486 0 $filter.='::filter';
487 0 ▶ $data_ar=$self->$filter($data_ar, \%meta) || return err();
Condition0%0/2
$self->$filter($data_ar, \%meta) || (return err())
l!l
00
MC/DC0%0/1
$self->$filter($data_ar, \%meta) || (return err())
$self->$filter($data_ar, \%meta)
Truth table0%0/2
A
A= $self->$filter($data_ar, \%meta)
Aresult
11
00
488 }
489 }
490  
491  
492 # Quit if user wants to see tree at this stage
493 #
494 3 ▶ $param_hr->{'stage2'} && (return \@container);
Branch: 1 branch
BranchTrueFalseTotal
$param_hr->{"stage2"} and return \@container 0 3 3
495  
496  
497 # Optimise tree, first step
498 #
499 3 ▶ $data_ar=$self->optimise_one($data_ar) || return err();
Condition50%1/2
$self->optimise_one($data_ar) || (return err())
l!l
30
MC/DC0%0/1
$self->optimise_one($data_ar) || (return err())
$self->optimise_one($data_ar)
Truth table50%1/2
A
A= $self->optimise_one($data_ar)
Aresult
11
00
500 3 $container[1]=$data_ar;
501  
502  
503 # Quit if user wants to see tree at this stage (stage3|opt1)
504 #
505 3 ▶ ($param_hr->{'stage3'} || $param_hr->{'opt1'}) && (return \@container);
Branch: 1 branch
BranchTrueFalseTotal
$param_hr->{"stage3"} || $param_hr->{"opt1"} and return \@container 0 3 3
Condition33%1/3
$param_hr->{"stage3"} or $param_hr->{"opt1"}
l!l&&r!l&&!r
003
MC/DC0%0/2
$param_hr->{"stage3"} or $param_hr->{"opt1"}
$param_hr->{"stage3"} $param_hr->{"opt1"}
Truth table33%1/3
A or B
A= $param_hr->{"stage3"}B= $param_hr->{"opt1"}
ABresult
1X1
011
000
506  
507  
508 # Optimise tree, second step
509 #
510 3 ▶ $data_ar=$self->optimise_two($data_ar) || return err();
Condition50%1/2
$self->optimise_two($data_ar) || (return err())
l!l
30
MC/DC0%0/1
$self->optimise_two($data_ar) || (return err())
$self->optimise_two($data_ar)
Truth table50%1/2
A
A= $self->optimise_two($data_ar)
Aresult
11
00
511 3 $container[1]=$data_ar;
512  
513  
514 # Quit if user wants to see tree at this stage (stage4|opt2)
515 #
516 3 ▶ ($param_hr->{'stage4'} || $param_hr->{'opt2'}) && (return \@container);
Branch: 1 branch
BranchTrueFalseTotal
$param_hr->{"stage4"} || $param_hr->{"opt2"} and return \@container 0 3 3
Condition33%1/3
$param_hr->{"stage4"} or $param_hr->{"opt2"}
l!l&&r!l&&!r
003
MC/DC0%0/2
$param_hr->{"stage4"} or $param_hr->{"opt2"}
$param_hr->{"stage4"} $param_hr->{"opt2"}
Truth table33%1/3
A or B
A= $param_hr->{"stage4"}B= $param_hr->{"opt2"}
ABresult
1X1
011
000
517  
518  
519 # Is there any dynamic data ? If not, set meta html flag to indicate
520 # document is complete HTML
521 #
522 3 ▶ unless (grep {ref($_)} @{$data_ar}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {ref $_;} @{$data_ar;}) 0 3 3
523 0 $meta{'html'}=1;
524 }
525  
526  
527 # Construct final webdyne container
528 #
529 3 ▶ @container=(keys %meta ? \%meta : undef, $data_ar);
Branch: 1 branch
BranchTrueFalseTotal
keys %meta ? : 3 0 3
530  
531  
532 # Quit if user wants to final container (stage5|final)
533 #
534 3 ▶ $param_hr->{'stage5'} && (return \@container);
Branch: 1 branch
BranchTrueFalseTotal
$param_hr->{"stage5"} and return \@container 0 3 3
535  
536  
537 # Save compiled object. Can't store code based cache refs, will be
538 # recreated anyway (when reloaded), so delete, save, then restore
539 #
540 3 my $cache_cr;
541 0 ▶ if (ref($meta{'cache'}) eq 'CODE') {$cache_cr=delete $meta{'cache'}}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $meta{"cache"} eq "CODE") 0 3 3
542  
543  
544 # Store to cache file if dest filename given
545 #
546 3 ▶ if ($dest_cn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dest_cn) { } 0 3 3
547 0 debug("attempting to cache to dest $dest_cn");
548 0 local $SIG{'__DIE__'};
549 0 ▶ eval {Storable::lock_store(\@container, $dest_cn)} || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { Storable::lock_store(\@container, $dest_cn) } } or do { $r->log_error("error storing compiled $html_cn to dest $dest_cn, $@ - " . 'please ensure destination directory is writeable.') unless $Package{"warn_write"}++; debug("caching FAILED to $dest_cn") } 0 0 0
550  
551 # This used to be fatal
552 #
553 #return err("error storing compiled $html_cn to dest $dest_cn, $@");
554  
555  
556 # No more, just log warning and continue - no point crashing an otherwise
557 # perfectly good app because we can't write to a directory
558 #
559 $r->log_error(
560 "error storing compiled $html_cn to dest $dest_cn, $@ - " .
561 'please ensure destination directory is writeable.'
562 )
563 0 ▶ unless $Package{'warn_write'}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $Package{"warn_write"}++ 0 0 0
564 0 debug("caching FAILED to $dest_cn");
565  
566 };
567 }
568 else {
569 3 debug('no destination file for compile - not caching');
570 }
571  
572  
573 # Put the cache code ref back again now we have finished storing.
574 #
575 3 ▶ $cache_cr && ($meta{'cache'}=$cache_cr);
Branch: 1 branch
BranchTrueFalseTotal
$cache_cr and $meta{"cache"} = $cache_cr 0 3 3
576  
577  
578 # Work out the page compile time, log
579 #
580 3 my $time_compile=sprintf('%0.4f', time()-$time);
581 $meta{'time_compile_elapsed'}=$time_compile unless
582 3 ▶ $param_hr->{'no_timestamp'};
Branch: 1 branch
BranchTrueFalseTotal
unless $param_hr->{"no_timestamp"} 3 0 3
583 $meta{'time_compile'}=$time unless
584 3 ▶ $param_hr->{'no_timestamp'};
Branch: 1 branch
BranchTrueFalseTotal
unless $param_hr->{"no_timestamp"} 3 0 3
585 3 debug("form $html_cn compile time $time_compile");
586  
587  
588 # Destroy self
589 #
590 3 undef $self;
591  
592  
593 # Done
594 #
595 3 return \@container;
596  
597 }
598  
599  
600 1 ▶sub compile_init {
Subroutine compile_init: called CC=1 SCAR=0.0
Pod undocumented
601  
602  
603 # Used to init package, move ugliness out of handler
604 #
605 1 my $class=shift();
606 1 debug("in compile_init class $class");
607  
608  
609 # Used to do some custom stuff here but now stub. Add anything wanted
610 #
611 #*WebDyne::HTML::Tiny::start_html0=sub {
612 # my ($self, $attr_hr)=@_;
613 # keys %{$attr_hr} || ($attr_hr=$WEBDYNE_HTML_PARAM);
614 # my $html_attr=join(' ', map {qq($_="$attr_hr->{$_}")} keys %{$attr_hr});
615 # return $WEBDYNE_DTD . ($html_attr ? "<html $html_attr>" : '<html>');
616 #};
617  
618 # All done
619 #
620 1 return \undef;
621  
622  
623 }
624  
625  
626 3 ▶sub optimise_one {
Subroutine optimise_one: called CC=5 SCAR=17.5
Pod undocumented
627  
628  
629 # Optimise a data tree
630 #
631 3 my ($self, $data_ar)=@_;
632  
633  
634 # Debug
635 #
636 3 debug('optimise stage one');
637  
638  
639 # Get CGI object and disable shortcut tags (e.g. start_html);
640 #
641 3 ▶ my $html_tiny_or=$self->{'_html_tiny_or'} || $self->html_tiny() ||
Condition40%2/5
$self->{'_html_tiny_or'} || $self->html_tiny || (return err('unable to get CGI object from self ref'))
l!l
30
$self->{"_html_tiny_or"} or $self->html_tiny
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->{'_html_tiny_or'} || $self->html_tiny || (return err('unable to get CGI object from self ref'))
$self->{"_html_tiny_or"} $self->html_tiny
Truth table33%1/3
A or B
A= $self->{"_html_tiny_or"}B= $self->html_tiny
ABresult
1X1
011
000
642 return err("unable to get CGI object from self ref");
643 3 debug("CGI $html_tiny_or");
644 3 $html_tiny_or->shortcut_disable();
645  
646  
647 # Recursive anon sub to do the render
648 #
649 22 ▶ my $compile_cr=sub {
Subroutine __ANON__: called CC=28 SCAR=39.8
650  
651  
652 # Get self ref, node array
653 #
654 22 my ($compile_cr, $data_ar)=@_;
655  
656  
657 # Only do if we have children, if we do a foreach over nonexistent child node
658 # it will spring into existance as empty array ref, which we then have to
659 # wastefully store
660 #
661 22 ▶ if ($data_ar->[WEBDYNE_NODE_CHLD_IX]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_ar->[2]) 14 8 22
662  
663  
664 # Process sub nodes to get child html data
665 #
666 14 foreach my $data_chld_ix (0..$#{$data_ar->[WEBDYNE_NODE_CHLD_IX]}) {
667  
668  
669 # Get data child
670 #
671 23 my $data_chld_ar=$data_ar->[WEBDYNE_NODE_CHLD_IX][$data_chld_ix];
672 23 debug("data_chld_ar $data_chld_ar");
673  
674  
675 # If ref, recursivly run through compile process
676 #
677 23 ▶ ref($data_chld_ar) && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $data_chld_ar and do { my $data_chld_xv = &$compile_cr($compile_cr, $data_chld_ar) || (return err()); if (ref $data_chld_xv eq "SCALAR") { $data_chld_xv = ${$data_chld_xv;}; } ; $data_ar->[2][$data_chld_ix] = $data_chld_xv } 19 4 23
678  
679  
680 # Run through compile sub-process
681 #
682 19 ▶ my $data_chld_xv=$compile_cr->($compile_cr, $data_chld_ar) ||
Condition50%1/2
&$compile_cr($compile_cr, $data_chld_ar) || (return err())
l!l
190
MC/DC0%0/1
&$compile_cr($compile_cr, $data_chld_ar) || (return err())
&$compile_cr($compile_cr, $data_chld_ar)
Truth table50%1/2
A
A= &$compile_cr($compile_cr, $data_chld_ar)
Aresult
11
00
683 return err();
684 19 ▶ if (ref($data_chld_xv) eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data_chld_xv eq "SCALAR") 12 7 19
685 12 $data_chld_xv=${$data_chld_xv}
686 }
687  
688  
689 # Replace in tree
690 #
691 19 $data_ar->[WEBDYNE_NODE_CHLD_IX][$data_chld_ix]=$data_chld_xv;
692  
693 }
694  
695 }
696  
697 }
698  
699  
700 # Get this node tag and attrs
701 #
702 my ($html_tag, $attr_hr)=
703 22 @{$data_ar}[WEBDYNE_NODE_NAME_IX, WEBDYNE_NODE_ATTR_IX];
704 22 debug("tag $html_tag, attr %s", Dumper($attr_hr));
705  
706  
707 # Check to see if any of the attributes will require a subst to be carried out
708 #
709 22 my @subst_oper;
710 my $subst_fg=$data_ar->[WEBDYNE_NODE_SBST_IX] || delete $attr_hr->{'subst'} ||
711 22 ▶ grep {$_=~/([\$@%!+*^])\{(\1?)(.*?)\2\}/ && push(@subst_oper, $1)} values %{$attr_hr};
Condition33%3/9
$data_ar->[3] || delete $attr_hr->{'subst'} || grep({$_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/ and push @subst_oper, $1;} values %{$attr_hr;})
l!l&&r!l&&!r
0022
$data_ar->[3] or delete $attr_hr->{"subst"}
l!l&&r!l&&!r
0022
$_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/ && push(@subst_oper, $1)
!ll&&!rl&&r
1500
MC/DC0%0/3
$data_ar->[3] || delete $attr_hr->{'subst'} || grep({$_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/ and push @subst_oper, $1;} values %{$attr_hr;})
$data_ar->[3] delete $attr_hr->{"subst"} grep({$_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/ and push @subst_oper, $1;} values %{$attr_hr;})
MC/DC0%0/2
$_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/ && push(@subst_oper, $1)
$_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/ push(@subst_oper, $1)
Truth table25%1/4
A or B || C
A= $data_ar->[3]B= delete $attr_hr->{"subst"}C= grep({$_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/ and push @subst_oper, $1;} values %{$attr_hr;})
ABCresult
1XX1
01X1
0011
0000
Truth table33%1/3
A && B
A= $_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/B= push(@subst_oper, $1)
ABresult
0X0
100
111
712  
713  
714 # Do not subst comments
715 #
716 22 ▶ ($html_tag=~/~comment$/) && ($subst_fg=undef);
Branch: 1 branch
BranchTrueFalseTotal
$html_tag =~ /~comment$/ and $subst_fg = undef 0 22 22
717  
718  
719 # If subst_fg present, means we must do a subst on attr vars. Flag
720 #
721 22 ▶ $subst_fg && ($data_ar->[WEBDYNE_NODE_SBST_IX]=1);
Branch: 1 branch
BranchTrueFalseTotal
$subst_fg and $data_ar->[3] = 1 0 22 22
722  
723  
724 # A CGI tag can be marked static, means that we can pre-render it for efficieny
725 #
726 22 my $static_fg=$attr_hr->{'static'};
727 22 debug("tag $html_tag, static_fg: $static_fg, subst_fg: $subst_fg, subst_oper %s", Dumper(\@subst_oper));
728  
729  
730 # If static, but subst requires an eval, we can do now *only* if @ or % tags though,
731 # and some !'s that do not need request object etc. Cannot do on $
732 #
733 22 ▶ if ($static_fg && $subst_fg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($static_fg and $subst_fg) 0 22 22
Condition33%1/3
$static_fg and $subst_fg
!ll&&!rl&&r
2200
MC/DC0%0/2
$static_fg and $subst_fg
$static_fg $subst_fg
Truth table33%1/3
A and B
A= $static_fgB= $subst_fg
ABresult
0X0
100
111
734  
735  
736 # Cannot optimes subst values with ${value}, must do later
737 #
738 0 ▶ (grep {$_ eq '$'} @subst_oper) && return $data_ar;
Branch: 1 branch
BranchTrueFalseTotal
grep {$_ eq "\$";} @subst_oper and return $data_ar 0 0 0
739  
740  
741 # Do it
742 #
743 0 ▶ $attr_hr=$self->WebDyne::subst_attr(undef, $attr_hr) ||
Condition0%0/2
$self->WebDyne::subst_attr(undef, $attr_hr) || (return err())
l!l
00
MC/DC0%0/1
$self->WebDyne::subst_attr(undef, $attr_hr) || (return err())
$self->WebDyne::subst_attr(undef, $attr_hr)
Truth table0%0/2
A
A= $self->WebDyne::subst_attr(undef, $attr_hr)
Aresult
11
00
744 return err();
745  
746 }
747  
748  
749 # If not special WebDyne tag, see if we can render node
750 #
751 22 ▶ if ((!$CGI_TAG_WEBDYNE{$html_tag} && !$CGI_TAG_FORM{$html_tag} && !$subst_fg) || $static_fg) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} || $WebDyne::Compile::CGI_TAG_FORM{$html_tag} || $subst_fg or $static_fg) { } 18 4 22
Condition66%6/9
not $WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} || $WebDyne::Compile::CGI_TAG_FORM{$html_tag} || $subst_fg or $static_fg
l!l&&r!l&&!r
1804
$WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} || $WebDyne::Compile::CGI_TAG_FORM{$html_tag} || $subst_fg
l!l&&r!l&&!r
4018
$WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} or $WebDyne::Compile::CGI_TAG_FORM{$html_tag}
l!l&&r!l&&!r
4018
MC/DC25%1/4
not $WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} || $WebDyne::Compile::CGI_TAG_FORM{$html_tag} || $subst_fg or $static_fg
$WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} $WebDyne::Compile::CGI_TAG_FORM{$html_tag} $subst_fg $static_fg
Truth table28%2/7
not(A or B || C) or D
A= $WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag}B= $WebDyne::Compile::CGI_TAG_FORM{$html_tag}C= $subst_fgD= $static_fg
ABCDresult
000X1
1XX11
01X11
00111
1XX00
01X00
00100
752 #if ((!$CGI_TAG_WEBDYNE{$html_tag} && !$subst_fg) || $static_fg) {
753  
754  
755 # Check all child nodes to see if ref or scalar
756 #
757 18 debug("if 1");
758 my $ref_fv=$data_ar->[WEBDYNE_NODE_CHLD_IX] &&
759 18 ▶ grep {ref($_)} @{$data_ar->[WEBDYNE_NODE_CHLD_IX]};
Condition100%3/3
$data_ar->[2] && grep({ref $_;} @{$$data_ar[2];})
!ll&&!rl&&r
666
MC/DC100%2/2
$data_ar->[2] && grep({ref $_;} @{$$data_ar[2];})
$data_ar->[2] grep({ref $_;} @{$$data_ar[2];})
Truth table100%3/3
A && B
A= $data_ar->[2]B= grep({ref $_;} @{$$data_ar[2];})
ABresult
0X0
100
111
760  
761  
762 # If all scalars (ie no refs found)t, we can simply pre render all child nodes
763 #
764 18 debug("ref_fv: $ref_fv");
765 18 ▶ unless ($ref_fv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ref_fv) 12 6 18
766  
767  
768 # Done with static tag, delete so not rendered
769 #
770 12 delete $attr_hr->{'static'};
771  
772  
773 # Special case. If WebDyne tag and static, render now via WebDyne. Experimental
774 #
775 12 ▶ if ($CGI_TAG_WEBDYNE{$html_tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag}) { } 0 12 12
776  
777  
778 # Render via WebDyne
779 #
780 0 debug("about to render tag $html_tag, attr %s", Dumper($attr_hr));
781 0 ▶ my $html_sr=$self->$html_tag($data_ar, $attr_hr) ||
Condition0%0/2
$self->$html_tag($data_ar, $attr_hr) || (return err())
l!l
00
MC/DC0%0/1
$self->$html_tag($data_ar, $attr_hr) || (return err())
$self->$html_tag($data_ar, $attr_hr)
Truth table0%0/2
A
A= $self->$html_tag($data_ar, $attr_hr)
Aresult
11
00
782 return err();
783 0 debug("html *$html_sr*, *${$html_sr}*");
784 0 return $html_sr;
785  
786  
787 }
788 else {
789 12 debug('not CGI_TAG_WEBDYNE')
790 }
791  
792  
793 # Wrap up in our HTML tag. Do in eval so we can catch errors from invalid tags etc
794 #
795 #
796 12 ▶ my @data_child=$data_ar->[WEBDYNE_NODE_CHLD_IX] ? @{$data_ar->[WEBDYNE_NODE_CHLD_IX]} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$data_ar->[2] ? : 6 6 12
797 12 debug("about to call $html_tag with attr_hr:%s, data_child: %s", Dumper($attr_hr, \@data_child));
798 12 ▶ my $html=eval {
Condition50%1/2
eval { do { $attr_hr = undef unless keys %{$attr_hr;}; if ($html_tiny_or->can($html_tag)) { debug("calling HTML::Tiny->$html_tag directly to render"); $html_tiny_or->$html_tag(grep({$_;} $attr_hr, join(undef, @data_child))); } else { debug("calling HTML::Tiny->tag($html_tag) to render"); $html_tiny_or->tag($html_tag, grep({$_;} $attr_hr, join(undef, @data_child))); } } } || (return errsubst("CGI tag '<$html_tag>': %s", $@ || sprintf("undefined error rendering tag '${html_tag}', attr_hr:%s, data_child:%s", Dumper($attr_hr, \@data_child))))
l!l
120
MC/DC0%0/1
eval { do { $attr_hr = undef unless keys %{$attr_hr;}; if ($html_tiny_or->can($html_tag)) { debug("calling HTML::Tiny->$html_tag directly to render"); $html_tiny_or->$html_tag(grep({$_;} $attr_hr, join(undef, @data_child))); } else { debug("calling HTML::Tiny->tag($html_tag) to render"); $html_tiny_or->tag($html_tag, grep({$_;} $attr_hr, join(undef, @data_child))); } } } || (return errsubst("CGI tag '<$html_tag>': %s", $@ || sprintf("undefined error rendering tag '${html_tag}', attr_hr:%s, data_child:%s", Dumper($attr_hr, \@data_child))))
eval { do { $attr_hr = undef unless keys %{$attr_hr;}; if ($html_tiny_or->can($html_tag)) { debug("calling HTML::Tiny->$html_tag directly to render"); $html_tiny_or->$html_tag(grep({$_;} $attr_hr, join(undef, @data_child))); } else { debug("calling HTML::Tiny->tag($html_tag) to render"); $html_tiny_or->tag($html_tag, grep({$_;} $attr_hr, join(undef, @data_child))); } } }
Truth table50%1/2
A
A= eval { do { $attr_hr = undef unless keys %{$attr_hr;}; if ($html_tiny_or->can($html_tag)) { debug("calling HTML::Tiny->$html_tag directly to render"); $html_tiny_or->$html_tag(grep({$_;} $attr_hr, join(undef, @data_child))); } else { debug("calling HTML::Tiny->tag($html_tag) to render"); $html_tiny_or->tag($html_tag, grep({$_;} $attr_hr, join(undef, @data_child))); } } }
Aresult
11
00
799 12 ▶ $attr_hr=undef unless keys %{$attr_hr};
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$attr_hr;} 6 6 12
800 12 ▶ if ($html_tiny_or->can($html_tag)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html_tiny_or->can($html_tag)) { } 12 0 12
801 12 debug("calling HTML::Tiny->$html_tag directly to render");
802 12 $html_tiny_or->$html_tag(grep {$_} $attr_hr, join(undef, @data_child))
803 }
804 else {
805 0 debug("calling HTML::Tiny->tag($html_tag) to render");
806 0 ▶ $html_tiny_or->tag($html_tag, grep {$_} $attr_hr, join(undef, @data_child))
Condition0%0/3
$@ || sprintf("undefined error rendering tag '${html_tag}', attr_hr:%s, data_child:%s", Dumper($attr_hr, \@data_child))
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || sprintf("undefined error rendering tag '${html_tag}', attr_hr:%s, data_child:%s", Dumper($attr_hr, \@data_child))
$@ sprintf("undefined error rendering tag '${html_tag}', attr_hr:%s, data_child:%s", Dumper($attr_hr, \@data_child))
Truth table0%0/3
A || B
A= $@B= sprintf("undefined error rendering tag '${html_tag}', attr_hr:%s, data_child:%s", Dumper($attr_hr, \@data_child))
ABresult
1X1
011
000
807 }
808  
809 # Older attempts
810 #
811 #$html_tiny_or->$html_tag(grep {$_} $attr_hr || {}, join(undef, @data_child))
812 #$html_tiny_or->$html_tag($attr_hr || {}, join(undef, grep {$_} @data_child))
813 } ||
814
815 # Use errsubst as CGI may have DIEd during eval and be caught by WebDyne SIG handler
816 return errsubst(
817 "CGI tag '<$html_tag>': %s",
818 $@ || sprintf("undefined error rendering tag '$html_tag', attr_hr:%s, data_child:%s", Dumper($attr_hr, \@data_child))
819 );
820  
821  
822 # Debug
823 #
824 #debug("html *$html*");
825  
826  
827 # Done
828 #
829 12 return \$html;
830  
831 }
832  
833  
834 }
835 else {
836 4 debug('fell through node render, no webdyne, subst tags etc.');
837 }
838  
839  
840 # Return current node, perhaps now somewhat optimised
841 #
842 10 $data_ar
843  
844 3 };
845  
846  
847 # Push data block onto stack as error hint
848 #
849 3 push @{$self->{'_data_ar_err'}}, $data_ar;
850
851
852 # Run it
853 #
854 3 ▶ $data_ar=$compile_cr->($compile_cr, $data_ar) || return err();
Condition50%1/2
&$compile_cr($compile_cr, $data_ar) || (return err())
l!l
30
MC/DC0%0/1
&$compile_cr($compile_cr, $data_ar) || (return err())
&$compile_cr($compile_cr, $data_ar)
Truth table50%1/2
A
A= &$compile_cr($compile_cr, $data_ar)
Aresult
11
00
855
856
857 # No error, pop error hint
858 #
859 3 pop @{$self->{'_data_ar_err'}};
860
861
862 # Re-enable shortcuts
863 #
864 3 $html_tiny_or->shortcut_enable();
865  
866  
867 # If scalar ref returned it is all HTML - return as plain scalar
868 #
869 3 ▶ if (ref($data_ar) eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data_ar eq "SCALAR") 0 3 3
870 0 $data_ar=${$data_ar}
871 }
872  
873  
874 # Done
875 #
876 3 return $data_ar;
877  
878 }
879  
880  
881 3 ▶sub optimise_two {
Subroutine optimise_two: called CC=5 SCAR=17.0
Pod undocumented
882  
883  
884 # Optimise a data tree
885 #
886 3 my ($self, $data_ar)=@_;
887  
888  
889 # Debug
890 #
891 3 debug('optimise stage two');
892  
893  
894 # Get CGI object and turn off shortcuts like start_html
895 #
896 3 ▶ my $html_tiny_or=$self->{'_html_tiny_or'} || $self->html_tiny() ||
Condition40%2/5
$self->{'_html_tiny_or'} || $self->html_tiny || (return err('unable to get CGI object from self ref'))
l!l
30
$self->{"_html_tiny_or"} or $self->html_tiny
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->{'_html_tiny_or'} || $self->html_tiny || (return err('unable to get CGI object from self ref'))
$self->{"_html_tiny_or"} $self->html_tiny
Truth table33%1/3
A or B
A= $self->{"_html_tiny_or"}B= $self->html_tiny
ABresult
1X1
011
000
897 return err("unable to get CGI object from self ref");
898 3 $html_tiny_or->shortcut_disable();
899  
900  
901 # Recursive anon sub to do the render
902 #
903 10 ▶ my $compile_cr=sub {
Subroutine __ANON__: called CC=42 SCAR=43.4
904  
905  
906 # Get self ref, node array
907 #
908 10 my ($compile_cr, $data_ar, $data_uppr_ar)=@_;
909  
910  
911 # Only do if we have children, if do a foreach over nonexistent child node
912 # it will spring into existance as empty array ref, which we then have to
913 # wastefully store
914 #
915 10 ▶ if ($data_ar->[WEBDYNE_NODE_CHLD_IX]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_ar->[2]) 8 2 10
916  
917  
918 # Process sub nodes to get child html data
919 #
920 my @data_child_ar=$data_ar->[WEBDYNE_NODE_CHLD_IX]
921 ?
922 8 ▶ @{$data_ar->[WEBDYNE_NODE_CHLD_IX]}
Branch: 1 branch
BranchTrueFalseTotal
$data_ar->[2] ? : 8 0 8
923 : undef;
924 8 foreach my $data_chld_ar (@data_child_ar) {
925  
926  
927 # Debug
928 #
929 #debug("found child node $data_chld_ar");
930  
931  
932 # If ref, run through compile process recursively
933 #
934 11 ▶ ref($data_chld_ar) && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $data_chld_ar and do { $data_ar = &$compile_cr($compile_cr, $data_chld_ar, $data_ar) || (return err()) } 7 4 11
935  
936  
937 # Run through compile sub-process
938 #
939 7 ▶ $data_ar=$compile_cr->($compile_cr, $data_chld_ar, $data_ar) ||
Condition50%1/2
&$compile_cr($compile_cr, $data_chld_ar, $data_ar) || (return err())
l!l
70
MC/DC0%0/1
&$compile_cr($compile_cr, $data_chld_ar, $data_ar) || (return err())
&$compile_cr($compile_cr, $data_chld_ar, $data_ar)
Truth table50%1/2
A
A= &$compile_cr($compile_cr, $data_chld_ar, $data_ar)
Aresult
11
00
940 return err();
941  
942 }
943  
944  
945 }
946  
947 }
948  
949  
950 # Get this tag and attrs
951 #
952 my ($html_tag, $attr_hr)=
953 10 @{$data_ar}[WEBDYNE_NODE_NAME_IX, WEBDYNE_NODE_ATTR_IX];
954 10 debug("tag $html_tag");
955  
956  
957 # Check if this tag attributes will need substitution (eg ${foo});
958 #
959 my $subst_fg=$data_ar->[WEBDYNE_NODE_SBST_IX] || delete $attr_hr->{'subst'} ||
960 10 ▶ grep {$_=~/([\$@%!+*^])\{(\1?)(.*?)\2\}/so} values %{$attr_hr};
Condition33%2/6
$data_ar->[3] || delete $attr_hr->{'subst'} || grep({$_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/so;} values %{$attr_hr;})
l!l&&r!l&&!r
0010
$data_ar->[3] or delete $attr_hr->{"subst"}
l!l&&r!l&&!r
0010
MC/DC0%0/3
$data_ar->[3] || delete $attr_hr->{'subst'} || grep({$_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/so;} values %{$attr_hr;})
$data_ar->[3] delete $attr_hr->{"subst"} grep({$_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/so;} values %{$attr_hr;})
Truth table25%1/4
A or B || C
A= $data_ar->[3]B= delete $attr_hr->{"subst"}C= grep({$_ =~ /([\$\@%!+*^])\{(\1?)(.*?)\2\}/so;} values %{$attr_hr;})
ABCresult
1XX1
01X1
0011
0000
961  
962  
963 # If subst_fg present, means we must do a subst on attr vars. Flag, also get static flag
964 #
965 10 ▶ $subst_fg && ($data_ar->[WEBDYNE_NODE_SBST_IX]=1);
Branch: 1 branch
BranchTrueFalseTotal
$subst_fg and $data_ar->[3] = 1 0 10 10
966 10 my $static_fg=delete $attr_hr->{'static'};
967  
968  
969 # If not special WebDyne tag, and no dynamic params we can render this node into
970 # its final HTML format
971 #
972 10 ▶ if (!$CGI_TAG_WEBDYNE{$html_tag} && !$CGI_TAG_IMPLICIT{$html_tag} && $data_uppr_ar && !$subst_fg) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} || $WebDyne::Compile::CGI_TAG_IMPLICIT{$html_tag} and $data_uppr_ar and not $subst_fg) { } 3 7 10
elsif ($WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} and $data_uppr_ar and $static_fg) { } 0 7 7
elsif (not $data_uppr_ar and $html_tag) { } 3 4 7
elsif (not $data_uppr_ar || $html_tag) { } 0 4 4
Condition77%7/9
not $WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} || $WebDyne::Compile::CGI_TAG_IMPLICIT{$html_tag} and $data_uppr_ar and not $subst_fg
!ll&&!rl&&r
703
not $WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} || $WebDyne::Compile::CGI_TAG_IMPLICIT{$html_tag} and $data_uppr_ar
!ll&&!rl&&r
433
$WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} || $WebDyne::Compile::CGI_TAG_IMPLICIT{$html_tag}
l!l&&r!l&&!r
406
MC/DC50%2/4
not $WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} || $WebDyne::Compile::CGI_TAG_IMPLICIT{$html_tag} and $data_uppr_ar and not $subst_fg
$WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} $WebDyne::Compile::CGI_TAG_IMPLICIT{$html_tag} $data_uppr_ar not $subst_fg
Truth table60%3/5
not(A || B) and C and not(D)
A= $WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag}B= $WebDyne::Compile::CGI_TAG_IMPLICIT{$html_tag}C= $data_uppr_arD= not $subst_fg
ABCDresult
1XXX0
01XX0
000X0
00100
00111
973  
974  
975 # Get nodes into array now, removes risk of iterating over shifting ground
976 #
977 3 debug("compile_cr: if 1");
978 my @data_child_ar=$data_uppr_ar->[WEBDYNE_NODE_CHLD_IX]
979 ?
980 3 ▶ @{$data_uppr_ar->[WEBDYNE_NODE_CHLD_IX]}
Branch: 1 branch
BranchTrueFalseTotal
$data_uppr_ar->[2] ? : 3 0 3
981 : undef;
982  
983  
984 # Get uppr node
985 #
986 3 foreach my $data_chld_ix (0..$#data_child_ar) {
987  
988  
989 # Get node, skip unless ref
990 #
991 6 my $data_chld_ar=$data_child_ar[$data_chld_ix];
992 6 ▶ ref($data_chld_ar) || next;
Branch: 1 branch
BranchTrueFalseTotal
ref $data_chld_ar or next 3 3 6
993  
994  
995 # Debug
996 #
997 #debug("looking at node $data_chld_ix, $data_chld_ar vs $data_ar");
998  
999  
1000 # Skip unless eq us
1001 #
1002 3 ▶ next unless ($data_chld_ar eq $data_ar);
Branch: 1 branch
BranchTrueFalseTotal
unless $data_chld_ar eq $data_ar 0 3 3
1003  
1004  
1005 # Get start and end tag methods
1006 #
1007 3 my ($html_tag_start, $html_tag_end)=
1008 ("start_${html_tag}", "end_${html_tag}");
1009  
1010  
1011 # Translate tags into HTML
1012 #
1013 my ($html_start, $html_end)=map {
1014 3 debug("render tag $_");
1015 6 ▶ eval {
Condition50%1/2
eval { do { $html_tiny_or->$_(grep({$_;} $attr_hr)) } } || (return errsubst("CGI tag '<$_>' error- %s", $@ || "undefined error rendering tag '${_}'"))
l!l
60
MC/DC0%0/1
eval { do { $html_tiny_or->$_(grep({$_;} $attr_hr)) } } || (return errsubst("CGI tag '<$_>' error- %s", $@ || "undefined error rendering tag '${_}'"))
eval { do { $html_tiny_or->$_(grep({$_;} $attr_hr)) } }
Truth table50%1/2
A
A= eval { do { $html_tiny_or->$_(grep({$_;} $attr_hr)) } }
Aresult
11
00
1016 6 ▶ $html_tiny_or->$_(grep {$_} $attr_hr)
Condition0%0/2
$@ || "undefined error rendering tag '${_}'"
l!l
00
MC/DC0%0/1
$@ || "undefined error rendering tag '${_}'"
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
1017 } ||
1018  
1019 # Use errsubst as CGI may have DIEd during eval and be caught by WebDyne SIG handler
1020 return errsubst(
1021 "CGI tag '<$_>' error- %s",
1022 $@ || "undefined error rendering tag '$_'"
1023 );
1024 } ($html_tag_start, $html_tag_end);
1025  
1026  
1027 # Splice start and end tags for this HTML into appropriate place
1028 #
1029 3 splice @{$data_uppr_ar->[WEBDYNE_NODE_CHLD_IX]}, $data_chld_ix, 1, grep {$_}
1030 $html_start,
1031 (WEBDYNE_HTML_NEWLINE && "\n"),
1032 3 @{$data_ar->[WEBDYNE_NODE_CHLD_IX]},
1033 (WEBDYNE_HTML_NEWLINE && "\n"),
1034 $html_end;
1035  
1036 # Done, no need to iterate any more
1037 #
1038 3 last;
1039  
1040  
1041 }
1042  
1043  
1044 # Concatenate all non ref values in the parent. Var to hold results
1045 #
1046 3 my @data_uppr;
1047  
1048  
1049 # Repopulate data child array, as probably changed in above foreach
1050 # block.
1051 #
1052 @data_child_ar=$data_uppr_ar->[WEBDYNE_NODE_CHLD_IX]
1053 ?
1054 3 ▶ @{$data_uppr_ar->[WEBDYNE_NODE_CHLD_IX]}
Branch: 1 branch
BranchTrueFalseTotal
$data_uppr_ar->[2] ? : 3 0 3
1055 : undef;
1056  
1057 #@data_child_ar=@{$data_uppr_ar->[$WEBDYNE_NODE_CHLD_IX]};
1058  
1059  
1060 # Begin concatenation
1061 #
1062 3 foreach my $data_chld_ix (0..$#data_child_ar) {
1063  
1064  
1065 # Get child
1066 #
1067 12 my $data_chld_ar=$data_child_ar[$data_chld_ix];
1068  
1069  
1070 # Can we concatenate with above node
1071 #
1072 12 ▶ if (@data_uppr && !ref($data_chld_ar) && !ref($data_uppr[$#data_uppr])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data_uppr and not ref $data_chld_ar and not ref $data_uppr[$#data_uppr]) { } 3 9 12
Condition100%6/6
@data_uppr and not ref $data_chld_ar and not ref $data_uppr[$#data_uppr]
!ll&&!rl&&r
633
@data_uppr and not ref $data_chld_ar
!ll&&!rl&&r
336
MC/DC100%3/3
@data_uppr and not ref $data_chld_ar and not ref $data_uppr[$#data_uppr]
@data_uppr not ref $data_chld_ar not ref $data_uppr[$#data_uppr]
Truth table100%4/4
A and not(B) and not(C)
A= @data_upprB= not ref $data_chld_arC= not ref $data_uppr[$#data_uppr]
ABCresult
0XX0
10X0
1100
1111
1073  
1074  
1075 # Yes, concatentate
1076 #
1077 3 $data_uppr[$#data_uppr].=$data_chld_ar;
1078  
1079 }
1080 else {
1081  
1082 # No, push onto new data_uppr array
1083 #
1084 9 push @data_uppr, $data_chld_ar;
1085  
1086 }
1087 }
1088  
1089  
1090 # Replace with new optimised array
1091 #
1092 3 $data_uppr_ar->[WEBDYNE_NODE_CHLD_IX]=\@data_uppr;
1093  
1094  
1095 }
1096 ▶ elsif ($CGI_TAG_WEBDYNE{$html_tag} && $data_uppr_ar && $static_fg) {
Condition66%4/6
$WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} and $data_uppr_ar and $static_fg
!ll&&!rl&&r
340
$WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} and $data_uppr_ar
!ll&&!rl&&r
304
MC/DC0%0/3
$WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} and $data_uppr_ar and $static_fg
$WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag} $data_uppr_ar $static_fg
Truth table50%2/4
A and B and C
A= $WebDyne::Compile::CGI_TAG_WEBDYNE{$html_tag}B= $data_uppr_arC= $static_fg
ABCresult
0XX0
10X0
1100
1111
1097  
1098  
1099 # Now render to make HTML and modify the data arrat above us with the rendered code
1100 #
1101 0 debug("compile_cr: if 2");
1102 0 ▶ my $html_sr=$self->render_data_ar(
Condition0%0/2
$self->render_data_ar('data', [$data_ar]) || (return err())
l!l
00
MC/DC0%0/1
$self->render_data_ar('data', [$data_ar]) || (return err())
$self->render_data_ar('data', [$data_ar])
Truth table0%0/2
A
A= $self->render_data_ar('data', [$data_ar])
Aresult
11
00
1103 data => [$data_ar],
1104 ) || return err();
1105 my @data_child_ar=$data_uppr_ar->[WEBDYNE_NODE_CHLD_IX]
1106 ?
1107 0 ▶ @{$data_uppr_ar->[WEBDYNE_NODE_CHLD_IX]}
Branch: 1 branch
BranchTrueFalseTotal
$data_uppr_ar->[2] ? : 0 0 0
1108 : undef;
1109 0 foreach my $ix (0..$#data_child_ar) {
1110 0 ▶ if ($data_uppr_ar->[WEBDYNE_NODE_CHLD_IX][$ix] eq $data_ar) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_uppr_ar->[2][$ix] eq $data_ar) 0 0 0
1111 0 $data_uppr_ar->[WEBDYNE_NODE_CHLD_IX][$ix]=${$html_sr};
1112 0 last;
1113 }
1114 }
1115  
1116  
1117 }
1118 ▶ elsif (!$data_uppr_ar && $html_tag) {
Condition66%2/3
not $data_uppr_ar and $html_tag
!ll&&!rl&&r
403
MC/DC50%1/2
not $data_uppr_ar and $html_tag
not $data_uppr_ar $html_tag
Truth table66%2/3
not(A) and B
A= not $data_uppr_arB= $html_tag
ABresult
0X0
100
111
1119
1120
1121 # Must be at top node, as nothing above us,
1122 # get start and end tag methods
1123 #
1124 3 debug("compile_cr: if 3");
1125 3 my ($html_tag_start, $html_tag_end)=
1126 ("start_${html_tag}", "end_${html_tag}");
1127  
1128  
1129 # Get resulting start and ending HTML
1130 #
1131 my ($html_start, $html_end)=map {
1132 3 debug("render tag $_");
1133 6 ▶ eval {
Condition50%1/2
eval { do { $html_tiny_or->$_(grep({$_;} $attr_hr)) } } || (return errsubst("CGI tag '<$_>': %s", $@ || "undefined error rendering tag '${_}'"))
l!l
60
MC/DC0%0/1
eval { do { $html_tiny_or->$_(grep({$_;} $attr_hr)) } } || (return errsubst("CGI tag '<$_>': %s", $@ || "undefined error rendering tag '${_}'"))
eval { do { $html_tiny_or->$_(grep({$_;} $attr_hr)) } }
Truth table50%1/2
A
A= eval { do { $html_tiny_or->$_(grep({$_;} $attr_hr)) } }
Aresult
11
00
1134 6 ▶ $html_tiny_or->$_(grep {$_} $attr_hr)
Condition0%0/2
$@ || "undefined error rendering tag '${_}'"
l!l
00
MC/DC0%0/1
$@ || "undefined error rendering tag '${_}'"
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
1135 } ||
1136 return errsubst(
1137 "CGI tag '<$_>': %s",
1138 $@ || "undefined error rendering tag '$_'"
1139 );
1140  
1141 #return err("$@" || "no html returned from tag $_")
1142 } ($html_tag_start, $html_tag_end);
1143 my @data_child_ar=$data_ar->[WEBDYNE_NODE_CHLD_IX]
1144 ?
1145 3 ▶ @{$data_ar->[WEBDYNE_NODE_CHLD_IX]}
Branch: 1 branch
BranchTrueFalseTotal
$data_ar->[2] ? : 3 0 3
1146 : undef;
1147  
1148 # Place start and end tags for this HTML into appropriate place
1149 #
1150 3 my @data=( grep {$_}
1151 $html_start,
1152 (WEBDYNE_HTML_NEWLINE && "\n"),
1153 @data_child_ar,
1154 (WEBDYNE_HTML_NEWLINE && "\n"),
1155 $html_end
1156 );
1157  
1158  
1159 # Concatenate all non ref vals
1160 #
1161 3 my @data_new;
1162 3 foreach my $data_chld_ix (0..$#data) {
1163  
1164 15 ▶ if ($data_chld_ix && !ref($data[$data_chld_ix]) && !(ref($data[$data_chld_ix-1]))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_chld_ix and not ref $data[$data_chld_ix] and not ref $data[$data_chld_ix - 1]) { } 6 9 15
Condition100%6/6
$data_chld_ix and not ref $data[$data_chld_ix] and not ref $data[$data_chld_ix - 1]
!ll&&!rl&&r
636
$data_chld_ix and not ref $data[$data_chld_ix]
!ll&&!rl&&r
339
MC/DC100%3/3
$data_chld_ix and not ref $data[$data_chld_ix] and not ref $data[$data_chld_ix - 1]
$data_chld_ix not ref $data[$data_chld_ix] not ref $data[$data_chld_ix - 1]
Truth table100%4/4
A and not(B) and not(C)
A= $data_chld_ixB= not ref $data[$data_chld_ix]C= not ref $data[$data_chld_ix - 1]
ABCresult
0XX0
10X0
1100
1111
1165 6 $data_new[$#data_new].=$data[$data_chld_ix];
1166 }
1167 else {
1168 9 push @data_new, $data[$data_chld_ix]
1169 }
1170  
1171 }
1172  
1173  
1174 # Return completed array
1175 #
1176 3 $data_uppr_ar=\@data_new;
1177  
1178  
1179 }
1180 ▶ elsif (!$data_uppr_ar && !$html_tag) {
Condition33%1/3
$data_uppr_ar || $html_tag
l!l&&r!l&&!r
400
MC/DC0%0/2
$data_uppr_ar || $html_tag
$data_uppr_ar $html_tag
Truth table33%1/3
A || B
A= $data_uppr_arB= $html_tag
ABresult
1X1
011
000
1181
1182
1183 # Special case generated by page with <api> tags, means we're not going to wrap in <html>
1184 #
1185 0 $data_uppr_ar=$data_ar->[WEBDYNE_NODE_CHLD_IX];
1186
1187 }
1188
1189
1190 # Return current node
1191 #
1192 10 return $data_uppr_ar;
1193  
1194  
1195 3 };
1196
1197
1198 # Push data block onto error hint stack in case of compile error
1199 #
1200 3 push @{$self->{'_data_ar_err'}}, $data_ar;
1201  
1202  
1203 # Run it, return whatever it does, allowing for the special case that first stage
1204 # optimisation found no special tags, and precompiled the whole array into a
1205 # single HTML string. In which case return as array ref to allow for correct storage
1206 # and rendering.
1207 #
1208 3 my $ret;
1209 3 ▶ if (ref($data_ar)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data_ar) { } 3 0 3
1210 3 ▶ $ret=$compile_cr->($compile_cr, $data_ar, undef) ||
Condition33%1/3
&$compile_cr($compile_cr, $data_ar, undef) || err()
l!l&&r!l&&!r
300
MC/DC0%0/2
&$compile_cr($compile_cr, $data_ar, undef) || err()
&$compile_cr($compile_cr, $data_ar, undef) err()
Truth table33%1/3
A || B
A= &$compile_cr($compile_cr, $data_ar, undef)B= err()
ABresult
1X1
011
000
1211 err()
1212 }
1213 else {
1214 0 $ret=[$data_ar];
1215 }
1216
1217
1218 # No errors, pop error hint stack
1219 #
1220 3 pop @{$self->{'_data_ar_err'}};
1221
1222  
1223 # Re-enable shortcuts
1224 #
1225 3 $html_tiny_or->shortcut_enable();
1226
1227  
1228 # And return
1229 #
1230 3 return $ret;
1231  
1232 }
1233  
1234  
1235 25 ▶sub parse {
Subroutine parse: called CC=12 SCAR=24.9
Pod undocumented
1236  
1237  
1238 # A recusively called method to parse a HTML::Treebuilder tree. content is an
1239 # array ref of the HTML entity contents, return custom array tree from that
1240 # structure
1241 #
1242 25 my ($self, $html_or, $meta_hr)=@_;
1243 25 my ($line_no, $line_no_tag_end)=@{$html_or}{'_line_no', '_line_no_tag_end'};
1244 25 my $html_fn_sr=\$meta_hr->{'manifest'}[0];
1245 25 debug("parse $self, $html_or line_no $line_no line_no_tag_end $line_no_tag_end");
1246  
1247  
1248 # Create array to hold this data node
1249 #
1250 25 my @data;
1251 25 @data[
1252 WEBDYNE_NODE_NAME_IX, # Tag Name
1253 WEBDYNE_NODE_ATTR_IX, # Attributes
1254 WEBDYNE_NODE_CHLD_IX, # Child nodes
1255 WEBDYNE_NODE_SBST_IX, # Substitution Required
1256 WEBDYNE_NODE_LINE_IX, # Source Line Number
1257 WEBDYNE_NODE_LINE_TAG_END_IX, # What line this tag ends on
1258 WEBDYNE_NODE_SRCE_IX # Source file name
1259 ]=(
1260 #undef, undef, undef, undef, $line_no, $line_no_tag_end, $meta_hr->{'manifest'}[0]
1261 undef, undef, undef, undef, $line_no, $line_no_tag_end, $html_fn_sr
1262 );
1263  
1264  
1265 # Get tag
1266 #
1267 25 my $html_tag=$html_or->tag();
1268  
1269  
1270 # Get tag attr
1271 #
1272 25 ▶ if (my %attr=map {$_ => $html_or->{$_}} (grep {!/^_/} keys %{$html_or})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%attr) = map({$_, $html_or->{$_};} grep({not /^_/;} keys %{$html_or;}))) { } 15 10 25
1273  
1274  
1275 # Save tagm attr into node
1276 #
1277 #@data[$WEBDYNE_NODE_NAME_IX, $WEBDYNE_NODE_ATTR_IX]=($html_tag, \%attr);
1278  
1279  
1280 # Is this the inline perl __PERL__ block ?
1281 #
1282 15 ▶ if ($html_or->{'_code'} && $attr{'perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html_or->{'_code'} and $attr{'perl'}) { } 3 12 15
Condition66%2/3
$html_or->{"_code"} and $attr{"perl"}
!ll&&!rl&&r
1203
MC/DC50%1/2
$html_or->{"_code"} and $attr{"perl"}
$html_or->{"_code"} $attr{"perl"}
Truth table66%2/3
A and B
A= $html_or->{"_code"}B= $attr{"perl"}
ABresult
0X0
100
111
1283 3 push @{$meta_hr->{'perl'}}, \$attr{'perl'};
1284 3 push @{$meta_hr->{'perl_debug'}}, [$line_no, $html_fn_sr];
1285 }
1286 else {
1287 12 @data[WEBDYNE_NODE_NAME_IX, WEBDYNE_NODE_ATTR_IX]=($html_tag, \%attr);
1288 }
1289  
1290 }
1291 else {
1292  
1293  
1294 # No attr, just save tag
1295 #
1296 10 $data[WEBDYNE_NODE_NAME_IX]=$html_tag;
1297  
1298 }
1299  
1300  
1301 # Child nodes
1302 #
1303 25 my @html_child=@{$html_or->content()};
1304  
1305  
1306 # Get child, parse down the tree
1307 #
1308 25 foreach my $html_child_or (@html_child) {
1309  
1310 27 debug("html_child_or $html_child_or");
1311  
1312  
1313 # Ref is a sub-tag, non ref is plain text
1314 #
1315 27 ▶ if (ref($html_child_or)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $html_child_or) { } 22 5 27
1316  
1317  
1318 # Sub tag. Recurse down tree, updating to nearest line number
1319 #
1320 22 $line_no=$html_child_or->{'_line_no'};
1321 22 ▶ my $data_ar=$self->parse($html_child_or, $meta_hr) ||
Condition50%1/2
$self->parse($html_child_or, $meta_hr) || (return err())
l!l
220
MC/DC0%0/1
$self->parse($html_child_or, $meta_hr) || (return err())
$self->parse($html_child_or, $meta_hr)
Truth table50%1/2
A
A= $self->parse($html_child_or, $meta_hr)
Aresult
11
00
1322 return err();
1323  
1324  
1325 # If no node name returned is not an error, just a no-op
1326 #
1327 22 ▶ if ($data_ar->[WEBDYNE_NODE_NAME_IX]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_ar->[0]) 19 3 22
1328 19 push @{$data[WEBDYNE_NODE_CHLD_IX]}, $data_ar;
1329 }
1330  
1331 }
1332 else {
1333  
1334 # Node is just plain text. Used to not insert empty children, but this
1335 # stuffed up <pre> sections that use \n for spacing/formatting. Now we
1336 # are more careful
1337 #
1338 5 ▶ push(@{$data[WEBDYNE_NODE_CHLD_IX]}, $html_child_or)
Branch: 1 branch
BranchTrueFalseTotal
unless $html_child_or =~ /^\s*$/ and $html_tag ne "pre" and $html_tag ne "textarea" and not $WebDyne::Compile::WEBDYNE_COMPILE_NO_SPACE_COMPACTING 4 1 5
Condition66%6/9
$html_child_or =~ /^\s*$/ and $html_tag ne "pre" and $html_tag ne "textarea" and not $WebDyne::Compile::WEBDYNE_COMPILE_NO_SPACE_COMPACTING
!ll&&!rl&&r
401
$html_child_or =~ /^\s*$/ and $html_tag ne "pre" and $html_tag ne "textarea"
!ll&&!rl&&r
401
$html_child_or =~ /^\s*$/ and $html_tag ne "pre"
!ll&&!rl&&r
401
MC/DC25%1/4
$html_child_or =~ /^\s*$/ and $html_tag ne "pre" and $html_tag ne "textarea" and not $WebDyne::Compile::WEBDYNE_COMPILE_NO_SPACE_COMPACTING
$html_child_or =~ /^\s*$/ $html_tag ne "pre" $html_tag ne "textarea" not $WebDyne::Compile::WEBDYNE_COMPILE_NO_SPACE_COMPACTING
Truth table40%2/5
A and B and C and not(D)
A= $html_child_or =~ /^\s*$/B= $html_tag ne "pre"C= $html_tag ne "textarea"D= not $WebDyne::Compile::WEBDYNE_COMPILE_NO_SPACE_COMPACTING
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1339 unless (
1340 $html_child_or=~/^\s*$/
1341 &&
1342 ($html_tag ne 'pre') && ($html_tag ne 'textarea') && !$WEBDYNE_COMPILE_NO_SPACE_COMPACTING
1343 );
1344  
1345 }
1346  
1347 }
1348  
1349  
1350 # All done, return data node
1351 #
1352 25 return \@data;
1353  
1354 }
1355  
1356  
1357 __END__
« lib/WebDyne/Err.pm ↑ Summary lib/WebDyne/HTML/Tiny.pm »