blib/lib/WebDyne/HTML/TreeBuilder.pm

filter: Statementstmt 94.2% 394 / 418 Branchbran 81.8% 108 / 132 Conditioncond 77.9% 53 / 68 MC/DCmcdc 58.5% 24 / 41 Subroutinesub 86.0% 43 / 50 Podpod 25.9% 7 / 27 totaltotal 85.4% 629 / 736 CC 93 SCAR 23.3
CC
93
Cov
90%
end
23.1
tag_parse
22.0
text
13.1
CRAP 10.2
« blib/lib/WebDyne/Session.pm ↑ Summary bin/wdcompile »
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::HTML::TreeBuilder;
14  
15  
16 # Compiler Pragma
17 #
18 30 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 30 ▶use vars qw($VERSION @ISA %CGI_TAG_WEBDYNE %CGI_TAG_FORM %CGI_TAG_IMPLICIT %CGI_TAG_SPECIAL);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 30 ▶no warnings qw(uninitialized redefine once);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23  
24 # WebDyne Modules
25 #
26 30 ▶use WebDyne;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 30 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 30 ▶use WebDyne::HTML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 30 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31  
32 # External Modules. Keep HTML::Entities or nullification of encode/decode
33 # subs will not work below
34 #
35 30 ▶use HTML::TreeBuilder;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 30 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 30 ▶use HTML::Tagset;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 30 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 30 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41  
42 # Inheritance
43 #
44 30 @ISA=qw(HTML::TreeBuilder);
45  
46  
47 # Version information
48 #
49 30 $VERSION='3.029';
50  
51  
52 # Debug load
53 #
54 30 0 && debug("Loading %s version $VERSION", __PACKAGE__);
55  
56  
57 # Form based tags we don't want to compile as their value may change if keeping state
58 #
59 30 %CGI_TAG_FORM=map {$_ => 1} (qw(
60  
61 textfield
62 textarea
63 password_field
64 checkbox
65 checkbox_group
66 radio_group
67 popup_menu
68 scrolling_list
69  
70 ));
71  
72  
73 # Make a hash of our implictly closed tags.
74 #
75 30 %CGI_TAG_IMPLICIT=map {$_ => 1} (keys(%CGI_TAG_FORM), qw(
76  
77 filefield
78 hidden
79 submit
80 reset
81 defaults
82 image_button
83 isindex
84 dump
85 include
86 json
87  
88 ));
89  
90  
91 # Update - get from CGI module, add special dump tag
92 #
93 #%CGI_TAG_IMPLICIT=map {$_ => 1} (
94 #
95 # @{$CGI::EXPORT_TAGS{':form'}},
96 # 'dump'
97 #D#
98 #);
99 #delete @CGI_TAG_IMPLICIT{qw(
100 # button
101 #)};
102  
103  
104 # Get WebDyne tags from main module
105 #
106 30 %CGI_TAG_WEBDYNE=%WebDyne::CGI_TAG_WEBDYNE;
107  
108  
109 # The tags below need to be handled specially at compile time - see the method
110 # associated with each tag below.
111 #
112 #map {$CGI_TAG_SPECIAL{$_}++} qw(perl script style start_html end_html include);
113 30 map {$CGI_TAG_SPECIAL{$_}++} qw(
114 perl
115 script
116 style
117 start_html
118 end_html
119 start_form
120 end_form
121 start_multipart_form
122 end_multipart_form
123 include
124 div
125 api
126 json
127 htmx
128 table
129 );
130  
131  
132 # Nullify Entities encode & decode
133 #
134 30 ▶*HTML::Entities::encode=sub { };
Subroutine __ANON__: not called CC=1 SCAR=0.0
135 30 ▶*HTML::Entities::decode=sub { };
Subroutine __ANON__: called CC=1 SCAR=0.0
136  
137  
138 # Add to islist items in TreeBuilder
139 #
140 30 map {$HTML::Tagset::isList{$_}++} keys %CGI_TAG_WEBDYNE;
141  
142  
143 # Need to tell HTML::TagSet about our special elements.
144 #
145 # Update - used to do this but now done in table() method below
146 #
147 #map {$HTML::Tagset::isTableElement{$_}++} keys %CGI_TAG_WEBDYNE;
148  
149  
150 # Add to valid body elements - means Treebuilder will automatically
151 # create html,head,body sections and include this - for truly lazy
152 # that just create a .psp file with no leading start_html
153 #
154 30 map { $HTML::Tagset::isBodyElement{$_}++ } qw(htmx json dump);
155  
156  
157 # And that we also block <p> tag closures
158 #
159 30 push @HTML::Tagset::p_closure_barriers, keys %CGI_TAG_WEBDYNE;
160  
161  
162 # All done. Positive return
163 #
164 30 1;
165  
166  
167 #==================================================================================================
168  
169  
170 1821 ▶sub new {
Subroutine new: called CC=4 SCAR=17.2
Pod documented
171  
172  
173 # Instantiate new WebDyne::HTML::TreeBuilder object
174 #
175 1821 my ($class, %param)=@_;
176 1821 0 && debug('in %s new(), class: %s, param: %s', __PACKAGE__, (ref($class) || $class), Dumper(\%param));
177 1821 ▶ my $self=$class->SUPER::new(%param) ||
Condition20%1/5
$class->SUPER::new(%param) || (return err('unable to initialize from %s, using ISA: %s', ref $class || $class, Dumper(\@WebDyne::HTML::TreeBuilder::ISA)))
l!l
18210
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/1
$class->SUPER::new(%param) || (return err('unable to initialize from %s, using ISA: %s', ref $class || $class, Dumper(\@WebDyne::HTML::TreeBuilder::ISA)))
$class->SUPER::new(%param)
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table50%1/2
A
A= $class->SUPER::new(%param)
Aresult
11
00
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
178 return err('unable to initialize from %s, using ISA: %s', ref($class) || $class, Dumper(\@ISA));
179
180
181 # We do need a HTML::Tiny object that has been ideally already been instantiated.
182 #
183 $self->{'_html_tiny_or'}=($param{'html_tiny_or'} ||
184 1821 ▶ WebDyne::HTML::Tiny->new(mode => $WEBDYNE_HTML_TINY_MODE, r=>$param{'r'}));
Condition33%1/3
$param{'html_tiny_or'} || 'WebDyne::HTML::Tiny'->new('mode', $WebDyne::HTML::TreeBuilder::WEBDYNE_HTML_TINY_MODE, 'r', $param{'r'})
l!l&&r!l&&!r
182100
MC/DC0%0/2
$param{'html_tiny_or'} || 'WebDyne::HTML::Tiny'->new('mode', $WebDyne::HTML::TreeBuilder::WEBDYNE_HTML_TINY_MODE, 'r', $param{'r'})
$param{'html_tiny_or'} 'WebDyne::HTML::Tiny'->new('mode', $WebDyne::HTML::TreeBuilder::WEBDYNE_HTML_TINY_MODE, 'r', $param{'r'})
Truth table33%1/3
A || B
A= $param{'html_tiny_or'}B= 'WebDyne::HTML::Tiny'->new('mode', $WebDyne::HTML::TreeBuilder::WEBDYNE_HTML_TINY_MODE, 'r', $param{'r'})
ABresult
1X1
011
000
185
186
187 # Done
188 #
189 1821 return $self;
190  
191 }
192  
193  
194 0 ▶sub line_no_debug {
Subroutine line_no_debug: not called CC=1 SCAR=6.9
Pod undocumented
195  
196 0 my $self=shift();
197 0 return sprintf("self $self, line_no: %s, line_no_start: %s, line_no_next: %s", @{$self}{qw(_line_no _line_no_start _line_no_next)});
198
199 }
200  
201  
202 1821 ▶sub parse_fh {
Subroutine parse_fh: called CC=3 SCAR=11.0
Pod undocumented
203  
204  
205 # Get self ref, file handle
206 #
207 1821 my ($tree_or, $html_fh)=@_;
208 1821 0 && debug("parse $html_fh");
209  
210  
211 # Delete any left over wedge segments
212 #
213 1821 delete $tree_or->{'_html_wedge_ar'};
214  
215  
216 # Read over file handle until we get to the first non-comment line (ignores auto added copyright statements)
217 #
218 1821 while (1) {
219 2003 my $pos=tell($html_fh);
220 2003 my $line=<$html_fh>;
221 2003 ▶ if ($line=~/^#/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^#/) { } 182 1821 2003
222 182 ▶ ($tree_or->{'_line_no'} ||= 0)++;
Condition100%2/2
$tree_or->{"_line_no"} ||= 0
l!l
11468
MC/DC100%1/1
$tree_or->{"_line_no"} ||= 0
$tree_or->{"_line_no"}
Truth table100%2/2
A
A= $tree_or->{"_line_no"}
Aresult
11
00
223 182 $tree_or->{'_line_no_next'}=$tree_or->{'_line_no'}+1;
224 182 next;
225 }
226 else {
227 1821 seek($html_fh, $pos, 0);
228 1821 last;
229 }
230 }
231  
232  
233 # Return closure code ref that understands how to count line
234 # numbers and wedge in extra code
235 #
236 22677 ▶ my $parse_cr=sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
237  
238  
239 # Read in lines of HTML, allowing for "wedged" bits, e.g. from start_html
240 #
241 22677 my $line;
242 22677 ▶ my $html=@{$tree_or->{'_html_wedge_ar'}} ? shift @{$tree_or->{'_html_wedge_ar'}} : ($line=<$html_fh>);
Branch: 1 branch
BranchTrueFalseTotal
@{$tree_or->{'_html_wedge_ar'};} ? : 2154 20523 22677
243 22677 ▶ if ($line) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line) 18702 3975 22677
244 18702 0 && debug("line *$line*");
245 18702 0 && debug($tree_or->line_no_debug());
246 18702 my @cr=($line=~/\n/g);
247 18702 ▶ $tree_or->{'_line_no'}=($tree_or->{'_line_no_next'} || 1);
Condition100%2/2
$tree_or->{'_line_no_next'} || 1
l!l
169491753
MC/DC100%1/1
$tree_or->{'_line_no_next'} || 1
$tree_or->{'_line_no_next'}
Truth table100%2/2
A
A= $tree_or->{'_line_no_next'}
Aresult
11
00
248 18702 $tree_or->{'_line_no_next'}=$tree_or->{'_line_no'}+@cr;
249 # Stop auto vivification via hash slice
250 #debug("Line %s, Line_no_next %s, Line_no_start %s cr %s", @{$tree_or}{qw(_line_no _line_no_next _line_no_start)}, scalar @cr);
251 18702 0 && debug("Line %s, Line_no_next %s, Line_no_start %s cr %s", (map {$tree_or->{$_}} qw(_line_no _line_no_next _line_no_start)), scalar @cr);
252 }
253  
254  
255 # To this or last line not processed by HTML::Parser properly (in one chunk) if no CR
256 #
257 22677 ▶ if ($html_fh->eof() && $html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html_fh->eof and $html) 2016 20661 22677
Condition100%3/3
$html_fh->eof and $html
!ll&&!rl&&r
1884018212016
MC/DC100%2/2
$html_fh->eof and $html
$html_fh->eof $html
Truth table100%3/3
A and B
A= $html_fh->eofB= $html
ABresult
0X0
100
111
258 2016 0 && debug("add CR at EOF");
259 2016 ▶ $html.=$/ unless $html=~/(?:\r?\n|\r)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $html =~ /(?:\r?\n|\r)$/ 302 1714 2016
260 }
261
262
263 # Ugly hack to fix @ type attribute names in Alpine and Vue. Need to be done in the Parser properly at
264 # some stage
265 #
266 22677 ▶ if (my $attr_convert=$WEBDYNE_ALPINE_VUE_ATTRIBUTE_HACK_ENABLE) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $attr_convert = $WebDyne::HTML::TreeBuilder::WEBDYNE_ALPINE_VUE_ATTRIBUTE_HACK_ENABLE) 22677 0 22677
267 22677 ▶ if ($html =~ s{
Branch: 1 branch
BranchTrueFalseTotal
if ($html =~ s/ (<\s*[\w:-]+ # match the start of an HTML tag (?:\s+[^>]*?)?) # non-greedy match of attributes \s@([\w\.-]+) # match attribute like @click or @keydown.enter (\s*=\s*["'][^"']*["']) # match = "value" or = 'value' /"$1 ${attr_convert}:$2$3";/egx) { } 30 22647 22677
268 (<\s*[\w:-]+ # match the start of an HTML tag
269 (?:\s+[^>]*?)?) # non-greedy match of attributes
270 \s@([\w\.-]+) # match attribute like @click or @keydown.enter
271 (\s*=\s*["'][^"']*["']) # match = "value" or = 'value'
272 }{
273 30 "$1 ${attr_convert}:$2$3"
274 }egx) { #" # Fake quote to re-enable syntax highlighting
275 30 0 && debug("match on AlpineJS attribute syntax hack, line now: $line");
276 }
277 else {
278 22647 0 && debug('no match on AlpineJS attribute syntax hack')
279 }
280 }
281
282  
283 # Done, return HTML
284 #
285 22677 return $html;
286  
287 1821 };
288 1821 return $parse_cr;
289  
290 }
291  
292  
293 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
294  
295  
296 # Destroy tree, reset any globals
297 #
298 0 my $self=shift();
299 0 0 && debug('delete');
300  
301  
302 # Reset script and line number vars
303 #
304 0 delete $self->{'_html_wedge_ar'};
305  
306  
307 # Run real deal from parent
308 #
309 0 $self->SUPER::delete(@_);
310  
311  
312 }
313  
314  
315 48093 ▶sub tag_parse {
Subroutine tag_parse: called CC=21 SCAR=30.9
Pod undocumented
316  
317  
318 # Get our self ref
319 #
320 48093 my ($self, $method)=(shift, shift);
321  
322  
323 # Get the tag, tag attr
324 #
325 48093 my ($tag, $attr_hr)=@_;
326
327
328 # Get rid of attribute multi-line value if the start with subst chars
329 #
330 48093 foreach my $attr (keys %{$attr_hr}) {
331 14241 my $attr_value=$attr_hr->{$attr};
332 14241 ▶ if ($attr_value=~/([\$@%!+*^])\{(\1?)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_value =~ /([\$\@%!+*^])\{(\1?)/) 1461 12780 14241
333 # Get rid of cr/lf
334 1461 ▶ if ($attr_value=~s/\s*[\r\n]+\s*/ /g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_value =~ s/\s*[\r\n]+\s*/ /g) 45 1416 1461
335 45 $attr_hr->{$attr}=$attr_value;
336 }
337 }
338 }
339 #map { $attr_hr->{$_}=($attr_hr->{$_}=~s/\s*[\r\n]+\s*/ /gr) } keys %{$attr_hr};
340  
341  
342 # Debug. Amended to stop autovivification
343 #
344 #debug("tag_parse $method, tag: *%s*, line_no: %s, line_no_start: %s, attr_hr:%s ", $tag, @{$self}{qw(_line_no _line_no_start)}, Dumper($attr_hr));
345 48093 0 && debug("tag_parse $method, tag: *%s*, line_no: %s, line_no_start: %s, attr_hr:%s ", $tag, (map {$self->{$_}} qw(_line_no _line_no_start)), Dumper($attr_hr));
346  
347  
348 # Get the parent tag
349 #
350 48093 my $pos;
351 my $tag_parent=(
352 $pos=$self->{'_pos'} || $self
353 48093 ▶ )->{'_tag'};
Condition66%2/3
$self->{'_pos'} || $self
l!l&&r!l&&!r
34740133530
MC/DC0%0/2
$self->{'_pos'} || $self
$self->{'_pos'} $self
Truth table66%2/3
A || B
A= $self->{'_pos'}B= $self
ABresult
1X1
011
000
354 48093 0 && debug("tag $tag, tag_parent $tag_parent");
355
356
357 # Is chomp detected ?
358 #
359 48093 ▶ if (delete $attr_hr->{'chomp'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $attr_hr->{"chomp"}) 45 48048 48093
360
361 # Yes, flag for later processing
362 #
363 45 0 && debug('chomp attribute detected, setting flag');
364 45 $self->{'_chomp'}++;
365
366 }
367  
368  
369 # Var to hold returned html element object ref
370 #
371 48093 my $html_or;
372  
373  
374 # If it is an below an implicit parent tag close that tag now.
375 #
376 #if ($CGI_TAG_IMPLICIT{$tag_parent} || $tag_parent=~/^start_/i || $tag_parent=~/^end_/i) {
377 48093 ▶ if ($CGI_TAG_IMPLICIT{$tag_parent} || ($tag_parent=~/^(?:start_|end_)/i)) {
Branch: 7 branches
BranchTrueFalseTotal
if ($WebDyne::HTML::TreeBuilder::CGI_TAG_IMPLICIT{$tag_parent} or $tag_parent =~ /^(?:start_|end_)/i) { } 330 47763 48093
elsif ($WebDyne::HTML::TreeBuilder::CGI_TAG_WEBDYNE{$tag_parent} and $tag eq 'head') { } 15 47748 47763
elsif ($WebDyne::HTML::TreeBuilder::CGI_TAG_WEBDYNE{$tag_parent} and $tag eq 'body') { } 15 47733 47748
elsif ($WebDyne::HTML::TreeBuilder::CGI_TAG_SPECIAL{$tag} and $method ne 'SUPER::text') { } 4606 43127 47733
elsif (() = $tag =~ /^(start_|end_)(.*)/i and $method ne 'SUPER::text') { } 0 43127 43127
elsif ($WebDyne::HTML::TreeBuilder::CGI_TAG_IMPLICIT{$tag_parent}) { } 0 43127 43127
elsif ($WebDyne::HTML::TreeBuilder::CGI_TAG_WEBDYNE{$tag_parent}) { } 3173 39954 43127
Condition66%2/3
$WebDyne::HTML::TreeBuilder::CGI_TAG_IMPLICIT{$tag_parent} or $tag_parent =~ /^(?:start_|end_)/i
l!l&&r!l&&!r
330047763
MC/DC50%1/2
$WebDyne::HTML::TreeBuilder::CGI_TAG_IMPLICIT{$tag_parent} or $tag_parent =~ /^(?:start_|end_)/i
$WebDyne::HTML::TreeBuilder::CGI_TAG_IMPLICIT{$tag_parent} $tag_parent =~ /^(?:start_|end_)/i
Truth table66%2/3
A or B
A= $WebDyne::HTML::TreeBuilder::CGI_TAG_IMPLICIT{$tag_parent}B= $tag_parent =~ /^(?:start_|end_)/i
ABresult
1X1
011
000
378  
379 # End implicit parent if it was an implicit tag
380 #
381 330 0 && debug("ending implicit parent tag $tag_parent");
382 330 $self->end($tag_parent);
383 330 $html_or=$self->$method(@_);
384  
385 }
386
387
388 # Special case where <perl/block/etc> wraps <head> or <body> tags. HTML::TreeBuilder assumes
389 # head is always under html - we have to hack.
390 #
391 ▶ elsif ($CGI_TAG_WEBDYNE{$tag_parent} && ($tag eq 'head')) {
Condition100%3/3
$WebDyne::HTML::TreeBuilder::CGI_TAG_WEBDYNE{$tag_parent} and $tag eq "head"
!ll&&!rl&&r
44333341515
MC/DC100%2/2
$WebDyne::HTML::TreeBuilder::CGI_TAG_WEBDYNE{$tag_parent} and $tag eq "head"
$WebDyne::HTML::TreeBuilder::CGI_TAG_WEBDYNE{$tag_parent} $tag eq "head"
Truth table100%3/3
A and B
A= $WebDyne::HTML::TreeBuilder::CGI_TAG_WEBDYNE{$tag_parent}B= $tag eq "head"
ABresult
0X0
100
111
392  
393 # Debug and modify tree
394 #
395 15 0 && debug("found $tag_parent above $tag, modifying tree");
396 15 $self->{'_head'}->preinsert($pos);
397 15 $self->{'_head'}->detach();
398 15 $pos->push_content($self->{'_head'});
399 15 $html_or=$self->$method(@_);
400  
401 }
402  
403  
404 # Same for body tag as above
405 #
406 ▶ elsif ($CGI_TAG_WEBDYNE{$tag_parent} && ($tag eq 'body')) {
Condition100%3/3
$WebDyne::HTML::TreeBuilder::CGI_TAG_WEBDYNE{$tag_parent} and $tag eq "body"
!ll&&!rl&&r
44333340015
MC/DC100%2/2
$WebDyne::HTML::TreeBuilder::CGI_TAG_WEBDYNE{$tag_parent} and $tag eq "body"
$WebDyne::HTML::TreeBuilder::CGI_TAG_WEBDYNE{$tag_parent} $tag eq "body"
Truth table100%3/3
A and B
A= $WebDyne::HTML::TreeBuilder::CGI_TAG_WEBDYNE{$tag_parent}B= $tag eq "body"
ABresult
0X0
100
111
407  
408 15 0 && debug("found $tag_parent above $tag, modifying tree");
409 15 $self->{'_body'}->preinsert($pos);
410 15 $self->{'_body'}->detach();
411 15 $pos->push_content($self->{'_body'});
412 15 $html_or=$self->$method(@_);
413  
414 }
415  
416  
417 # If it is an custom webdyne tag, massage with methods below
418 # before processing
419 #
420 ▶ elsif ($CGI_TAG_SPECIAL{$tag} && ($method ne 'SUPER::text')) {
Condition100%3/3
$WebDyne::HTML::TreeBuilder::CGI_TAG_SPECIAL{$tag} and $method ne "SUPER::text"
!ll&&!rl&&r
43097304606
MC/DC100%2/2
$WebDyne::HTML::TreeBuilder::CGI_TAG_SPECIAL{$tag} and $method ne "SUPER::text"
$WebDyne::HTML::TreeBuilder::CGI_TAG_SPECIAL{$tag} $method ne "SUPER::text"
Truth table100%3/3
A and B
A= $WebDyne::HTML::TreeBuilder::CGI_TAG_SPECIAL{$tag}B= $method ne "SUPER::text"
ABresult
0X0
100
111
421  
422  
423 # Yes, is WebDyne tag
424 #
425 4606 0 && debug("webdyne tag_special ($tag) dispatch");
426 4606 $html_or=$self->$tag($method, $tag, $attr_hr);
427  
428 }
429  
430  
431 ▶ elsif ((my ($modifier, $tag_actual)=($tag=~/^(start_|end_)(.*)/i)) && ($method ne 'SUPER::text')) {
Condition66%2/3
() = $tag =~ /^(start_|end_)(.*)/i and $method ne "SUPER::text"
!ll&&!rl&&r
43097300
MC/DC0%0/2
() = $tag =~ /^(start_|end_)(.*)/i and $method ne "SUPER::text"
() = $tag =~ /^(start_|end_)(.*)/i $method ne "SUPER::text"
Truth table66%2/3
A and B
A= () = $tag =~ /^(start_|end_)(.*)/iB= $method ne "SUPER::text"
ABresult
0X0
100
111
432  
433  
434 # Yes, is WebDyne tag
435 #
436 0 0 && debug("webdyne tag start|end ($tag) dispatch, method $method");
437 #if ($modifier=~/end_/) {
438 # debug('end tag so changing method to SUPER::end');
439 # $method='SUPER::end'
440 #}
441  
442 0 $html_or=$self->tag_parse($method, $tag_actual, $attr_hr);
443  
444 }
445  
446  
447 # If it is an custom CGI tag that we need to close implicityly
448 #
449 #elsif ($CGI_TAG_IMPLICIT{$tag_parent} || $tag=~/^start_/i || $tag=~/^end_/) {
450 elsif ($CGI_TAG_IMPLICIT{$tag_parent}) {
451  
452  
453 # Yes, is CGI tag
454 #
455 0 0 && debug("webdyne tag_implicit ($tag) dispatch");
456 0 $html_or=$self->$method(@_);
457 0 $self->end($tag)
458  
459 }
460  
461  
462 # If its parent was a custom webdyne tag, the turn off implicitness
463 # before processing
464 #
465 elsif ($CGI_TAG_WEBDYNE{$tag_parent}) {
466  
467  
468 # Turn off implicitness here to stop us from being moved
469 # around in the parse tree if we are under a table or some
470 # such
471 #
472 3173 0 && debug('turning off implicit tags');
473 3173 $self->implicit_tags(0);
474  
475  
476 # Run the WebDyne tag method.
477 #
478 3173 0 && debug("webdyne tag_parent ($tag_parent) dispatch");
479 3173 $html_or=$self->$tag_parent($method, $tag, $attr_hr);
480  
481  
482 # Turn implicitness back on again
483 #
484 3173 0 && debug('turning on implicit tags');
485 3173 $self->implicit_tags(1);
486  
487  
488 }
489 else {
490  
491  
492 # Pass onto our base class for further processing
493 #
494 39954 0 && debug("base class method $method, %s", Dumper(\@_));
495 39954 $html_or=$self->$method(@_);
496  
497  
498 }
499
500
501 # Do we have a HTML::Element object ?
502 #
503 48093 ▶ if ((my $ref=ref($html_or)) eq 'HTML::Element') {
Branch: 2 branches
BranchTrueFalseTotal
if ((my $ref = ref $html_or) eq 'HTML::Element') { } 16956 31137 48093
elsif ($ref and $ref ne 'WebDyne::HTML::TreeBuilder') { } 0 31137 31137
504
505 # Yes
506 #
507 16956 0 && debug("parse returned $ref object, tag: %s, inserting line no", $html_or->tag());
508 16956 @{$html_or}{'_line_no', '_line_no_tag_end'}=@{$self}{qw(_line_no_start _line_no)};
509
510
511 }
512 ▶ elsif ($ref && ($ref ne 'WebDyne::HTML::TreeBuilder')) {
Condition66%2/3
$ref and $ref ne "WebDyne::HTML::TreeBuilder"
!ll&&!rl&&r
2733138060
MC/DC0%0/2
$ref and $ref ne "WebDyne::HTML::TreeBuilder"
$ref $ref ne "WebDyne::HTML::TreeBuilder"
Truth table66%2/3
A and B
A= $refB= $ref ne "WebDyne::HTML::TreeBuilder"
ABresult
0X0
100
111
513
514 # That's weird ..
515 #
516 0 return err("parse returned $ref object, expected 'WebDyne::HTML::Element'");
517
518 }
519 else {
520
521 # Text
522 #
523 31137 0 && debug('parse returned text (scalar) object');
524
525 }
526  
527  
528 # Returm object ref
529 #
530 48093 $html_or;
531  
532  
533 }
534  
535  
536 1093 ▶sub block {
Subroutine block: called CC=1 SCAR=0.0
Pod undocumented
537  
538  
539 # No special handling needed, just log for debugging purposes
540 #
541 1093 my ($self, $method)=(shift, shift);
542 1093 0 && debug("block self $self, method $method, *%s* text_block_tag %s", join('*', @_), $self->_text_block_tag());
543 1093 $self->$method(@_);
544  
545 }
546  
547  
548 240 ▶sub script {
Subroutine script: called CC=3 SCAR=11.0
Pod undocumented
549  
550 240 my ($self, $method, $tag, $attr_hr, @param)=@_;
551 30 ▶ no warnings 'qw';
Subroutine BEGIN: called CC=1 SCAR=0.0
552 240 0 && debug("$self script, attr: %s", Dumper($attr_hr));
553 240 my $script_or=$self->$method($tag, $attr_hr, @param);
554 240 ▶ if ($attr_hr->{'type'} eq 'application/perl') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_hr->{'type'} eq 'application/perl') { } 15 225 240
555  
556 15 my $perl_or=HTML::Element->new('perl', inline => 1);
557 15 push @{$self->{'_script_stack'}}, [$script_or, 'perl', $perl_or];
558 15 0 && debug('perl script !');
559  
560 }
561 else {
562  
563 225 push @{$self->{'_script_stack'}}, undef;
564 225 ▶ $self->_text_block_tag('script') unless $self->_text_block_tag();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_text_block_tag 225 0 225
565 }
566  
567 #$self->$method($tag, $attr_hr, @param);
568 240 return $script_or;
569  
570 }
571  
572  
573 0 ▶sub json0 {
Subroutine json0: not called CC=2 SCAR=17.9
Pod undocumented
574  
575  
576 # No special handling needed, just log for debugging purposes
577 #
578 0 my ($self, $method, @param)=@_;
579 0 ▶ $self->_text_block_tag('json') unless $self->_text_block_tag();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_text_block_tag 0 0 0
580 0 0 && debug("self $self, tag: json, method: $method text_block_tag %s", $self->_text_block_tag());
581 0 return $self->$method(@param);
582  
583 }
584  
585  
586 92 ▶sub table {
Subroutine table: called CC=3 SCAR=13.0
Pod undocumented
587  
588  
589 # Modify HTML::Tagset to allow perl/block/htmx tags within a table tag, then pull them out
590 # when the table tag closes.
591 #
592 92 my ($self, $method, $tag, @param)=@_;
593 92 0 && debug("self $self, tag: $tag, method: $method");
594 92 ▶ if ($method eq 'SUPER::start') {
Branch: 2 branches
BranchTrueFalseTotal
if ($method eq 'SUPER::start') { } 92 0 92
elsif ($method eq 'SUPER::end') { } 0 0 0
595 92 map { $HTML::Tagset::isTableElement{$_}=1 } qw(perl block htmx)
596 }
597 elsif ($method eq 'SUPER::end') {
598 0 map { delete $HTML::Tagset::isTableElement{$_} } qw(perl block htmx)
599 }
600 92 return $self->$method($tag, @param);
601
602 }
603  
604  
605 108 ▶sub htmx {
Subroutine htmx: called CC=5 SCAR=16.1
Pod undocumented
606  
607  
608 # Handle normally but set flag showing we are an <htmx> page, will optimise differently
609 #
610 108 my ($self, $method, $tag, $attr_hr, @param)=@_;
611 108 0 && debug("self $self, tag: htmx, method: $method, param: %s", Dumper($attr_hr));
612 108 ▶ $self->{'_webdyne_compact'}=$tag if ($attr_hr->{'compact'} || $attr_hr->{'bare'});
Branch: 1 branch
BranchTrueFalseTotal
if $attr_hr->{"compact"} or $attr_hr->{"bare"} 30 78 108
Condition100%3/3
$attr_hr->{"compact"} or $attr_hr->{"bare"}
l!l&&r!l&&!r
151578
MC/DC100%2/2
$attr_hr->{"compact"} or $attr_hr->{"bare"}
$attr_hr->{"compact"} $attr_hr->{"bare"}
Truth table100%3/3
A or B
A= $attr_hr->{"compact"}B= $attr_hr->{"bare"}
ABresult
1X1
011
000
613 108 ▶ if (delete $attr_hr->{'perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $attr_hr->{'perl'}) { } 15 93 108
614 15 my $html_perl_or=$self->$method($tag, $attr_hr);
615 15 $self->_html_perl_or($html_perl_or);
616 15 ▶ $self->_text_block_tag($tag) unless $self->_text_block_tag();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_text_block_tag 15 0 15
617 15 return $html_perl_or;
618 }
619 else {
620 93 return $self->$method($tag, $attr_hr, @param);
621 }
622  
623 }
624  
625  
626 34 ▶sub api {
Subroutine api: called CC=3 SCAR=11.0
Pod undocumented
627  
628  
629 # Handle normally but set flag showing we are an <api> page, will optimise differently
630 #
631 34 my ($self, $method, $tag, $attr_hr, @param)=@_;
632 34 0 && debug("self $self, tag: api, method: $method");
633 34 $self->{'_webdyne_compact'}=$tag;
634 34 ▶ if (delete $attr_hr->{'perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $attr_hr->{'perl'}) { } 16 18 34
635 16 my $html_perl_or=$self->$method($tag, $attr_hr);
636 16 $self->_html_perl_or($html_perl_or);
637 16 ▶ $self->_text_block_tag($tag) unless $self->_text_block_tag();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_text_block_tag 16 0 16
638 16 return $html_perl_or;
639 }
640 else {
641 18 return $self->$method($tag, $attr_hr, @param);
642 }
643  
644 }
645  
646  
647 180 ▶sub json {
Subroutine json: called CC=3 SCAR=11.0
Pod undocumented
648  
649  
650 # No special handling needed, just log for debugging purposes
651 #
652 180 my ($self, $method, $tag, $attr_hr, @param)=@_;
653 180 0 && debug("self $self, tag: api, method: $method");
654 180 ▶ if (delete $attr_hr->{'perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $attr_hr->{'perl'}) { } 15 165 180
655 15 my $html_perl_or=$self->$method($tag, $attr_hr);
656 15 $self->_html_perl_or($html_perl_or);
657 15 ▶ $self->_text_block_tag($tag) unless $self->_text_block_tag();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_text_block_tag 15 0 15
658 15 return $html_perl_or;
659 }
660 else {
661 165 return $self->$method($tag, $attr_hr, @param);
662 }
663  
664 }
665  
666  
667 2 ▶sub style {
Subroutine style: called CC=2 SCAR=7.0
Pod undocumented
668  
669 2 my ($self, $method)=(shift, shift);
670 2 0 && debug('style');
671 2 ▶ $self->_text_block_tag('style') unless $self->_text_block_tag();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_text_block_tag 2 0 2
672 2 return $self->$method(@_);
673  
674 }
675  
676  
677 3305 ▶sub perl {
Subroutine perl: called CC=5 SCAR=16.1
Pod undocumented
678  
679  
680 # Special handling of perl tag
681 #
682 3305 my ($self, $method, $tag, $attr_hr)=@_;
683 3305 0 && debug("tag: *$tag* method: $method");
684  
685  
686 # Call SUPER method, check if inline
687 #
688 3305 my $html_perl_or=$self->$method($tag, $attr_hr);
689 3305 my $inline;
690 3305 ▶ if ($tag eq 'perl') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "perl") 1288 2017 3305
691 1288 ▶ unless (grep {exists $attr_hr->{$_}} qw(package method handler)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {exists $attr_hr->{$_};} "package", "method", "handler") 226 1062 1288
692 226 $html_perl_or->attr(inline => ++$inline);
693 226 0 && debug("inline: $inline");
694 }
695 }
696 3305 ▶ if ($inline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inline) { } 226 3079 3305
697  
698 # Inline tag, set global var to this element so any extra text can be
699 # added here
700 #
701 226 $self->_html_perl_or($html_perl_or);
702 226 ▶ $self->_text_block_tag($tag) unless $self->_text_block_tag();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_text_block_tag 226 0 226
703  
704  
705 # And return it
706 #
707 226 return $html_perl_or;
708  
709 }
710 else {
711  
712  
713 # Not inline, just return object
714 #
715 3079 return $html_perl_or;
716  
717 }
718  
719  
720 }
721  
722  
723 422 ▶sub process {
Subroutine process: called CC=1 SCAR=0.0
Pod documented
724  
725 # Rough and ready process handler, try to handle perl code in <? .. ?>. Not sure if I really
726 # want to support this yet ...
727 #
728 422 my ($self, $text)=@_;
729 422 0 && debug("process $text");
730
731 # Create perl HTMl::Object
732 #
733 422 my $html_or=HTML::Element->new('perl', inline => 1, perl => $text);
734 422 0 && debug("insert line_no: %s into object ref $html_or", $self->{'_line_no'});
735 422 @{$html_or}{'_line_no', '_line_no_tag_end'}=@{$self}{qw(_line_no _line_no)};
736 422 return $self->tag_parse('SUPER::text', $html_or)
737  
738 }
739  
740  
741 20507 ▶sub start {
Subroutine start: called CC=3 SCAR=11.0
Pod documented
742  
743  
744 # Ugly, make sure if in perl or script tag, whatever we see counts
745 # as text
746 #
747 20507 my ($self, $tag)=(shift, shift);
748 20507 my $text=$_[2];
749 20507 ▶ ref($tag) || ($tag=lc($tag));
Branch: 1 branch
BranchTrueFalseTotal
ref $tag or $tag = lc $tag 0 20507 20507
750 20507 0 && debug("$self start tag '$tag' line_no: %s, %s", $self->{'_line_no'}, Dumper(\@_));
751
752 20507 my $html_or;
753 20507 ▶ if ($self->_text_block_tag()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_text_block_tag) { } 15 20492 20507
754 15 $html_or=$self->text($text)
755 }
756 else {
757 20492 my @cr=($text=~/\n/g);
758 20492 $self->{'_line_no_start'}=$self->{'_line_no'}-@cr;
759 # Amend to stop autovivification
760 #debug("tag $tag line_no: %s, line_no_start: %s", @{$self}{qw(_line_no _line_no_start)});
761 20492 0 && debug("tag $tag line_no: %s, line_no_start: %s", (map {$self->{$_}} qw(_line_no _line_no_start)));
762 20492 $html_or=$self->tag_parse('SUPER::start', $tag, @_);
763  
764 }
765 20507 $html_or;
766  
767 }
768  
769  
770 14363 ▶sub end {
Subroutine end: called CC=23 SCAR=31.4
Pod documented
771  
772  
773 # Ugly special case conditions, ensure end tag between perl or script
774 # blocks are treated as text
775 #
776 14363 my ($self, $tag)=(shift, shift);
777 14363 ▶ ref($tag) || ($tag=lc($tag));
Branch: 1 branch
BranchTrueFalseTotal
ref $tag or $tag = lc $tag 3479 10884 14363
778 14363 0 && debug("$self end tag: %s,%s text_block_tag: %s, line_no: %s", Dumper($tag, \@_), $self->_text_block_tag(), $self->{'_line_no'});
779 14363 0 && debug($self->line_no_debug());
780 #debug('self: %s', Dumper($self));
781
782
783 # Var to hold HTML::Element ref if returned, but most methods don't seem to return a HTML ref, just an integer ?
784 #
785 14363 my $ret;
786  
787  
788 # Div tag gets handles specially as start tag might have been a webdyne tag aliases into a div tag (see div tag for more details)
789 #
790 14363 ▶ if ($tag eq 'div') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag eq 'div') { } 436 13927 14363
elsif ($tag eq 'script') { } 225 13702 13927
791  
792 # Hit on div, check
793 #
794 436 0 && debug("hit on div tag: $tag");
795  
796  
797 # Can we pop an array ref off div_stack ? If so means was webdyne tag
798 #
799 #if (my $div_ar=pop(@div_stack)) {
800 436 ▶ if (my $div_ar=pop(@{$self->{'_div_stack'}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $div_ar = pop @{$$self{'_div_stack'};}) { } 270 166 436
801  
802  
803 # Yes, separate out to components stored by div subroutine
804 #
805 270 my ($div_or, $webdyne_tag, $webdyne_tag_or)=@{$div_ar};
806 270 0 && debug("popped div tag: $div_or, %s, about to end webdyne tag: $webdyne_tag (%s)", $div_or->tag(), $webdyne_tag_or->tag());
807  
808  
809 # Set the Text_fg to whatever the webdyne tag was (e.g. perl, etc), that way they will see a match and
810 # turn off text mode. NOTE: Not sure this works ?
811 #
812 270 ▶ $self->_text_block_tag($webdyne_tag_or->tag()) if $self->_text_block_tag();
Branch: 1 branch
BranchTrueFalseTotal
if $self->_text_block_tag 90 180 270
813 270 0 && debug("text_block_tag now %s, ending $webdyne_tag", $self->_text_block_tag());
814 270 ▶ $self->pos()->{'_line_no_tag_end'}=$self->{'_line_no'} if (ref($self->pos()) eq 'HTML::Element');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->pos eq "HTML::Element" 270 0 270
815 270 $self->SUPER::end($webdyne_tag, @_);
816  
817 # Now end the original div tag
818 #
819 270 0 && debug("ending $tag now");
820 270 ▶ $self->pos()->{'_line_no_tag_end'}=$self->{'_line_no'} if (ref($self->pos()) eq 'HTML::Element');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->pos eq "HTML::Element" 270 0 270
821 270 $ret=$self->SUPER::end($tag, @_);
822  
823  
824 # Can now unset text flag. See NOTE above, need to check this
825 #
826 270 $self->_text_block_tag(undef);
827  
828  
829 # Now replace div tag with webdyne output unless a wrap attribute exists or class etc. given - in which
830 # case the output will be wrapped in that tag and any class, style or id tags presevered
831 #
832 270 my @div_attr_name=grep {$div_or->attr($_)} qw(class style id);
833 270 ▶ if ((my $tag=$div_or->attr('wrap')) || @div_attr_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tag = $div_or->attr('wrap') or @div_attr_name) { } 30 240 270
Condition100%3/3
my $tag = $div_or->attr("wrap") or @div_attr_name
l!l&&r!l&&!r
1515240
MC/DC100%2/2
my $tag = $div_or->attr("wrap") or @div_attr_name
my $tag = $div_or->attr("wrap") @div_attr_name
Truth table100%3/3
A or B
A= my $tag = $div_or->attr("wrap")B= @div_attr_name
ABresult
1X1
011
000
834  
835 # Want to wrap output in another tag or use <div> if class etc. given but no tag
836 #
837 30 ▶ $tag ||= 'div';
Condition100%2/2
$tag ||= "div"
l!l
1515
MC/DC100%1/1
$tag ||= "div"
$tag
Truth table100%2/2
A
A= $tag
Aresult
11
00
838 30 $webdyne_tag_or->push_content($div_or->detach_content());
839 my %tag_attr=(
840 30 map {$_ => $div_or->attr($_)}
841 @div_attr_name
842 );
843 30 0 && debug("tag: $tag, tag_attr: %s", Dumper(\%tag_attr));
844 30 my $tag_or=HTML::Element->new($tag, %tag_attr);
845 30 $tag_or->push_content($webdyne_tag_or);
846 30 $div_or->replace_with($tag_or);
847  
848 }
849 else {
850 240 $webdyne_tag_or->push_content($div_or->detach_content());
851 240 $div_or->replace_with($webdyne_tag_or);
852 }
853 270 return $ret;
854  
855 }
856 else {
857  
858  
859 # Vanilla div tag, nothing to do
860 #
861 166 0 && debug('undef pop off div stack');
862 166 ▶ $self->pos()->{'_line_no_tag_end'}=$self->{'_line_no'} if (ref($self->pos()) eq 'HTML::Element');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->pos eq "HTML::Element" 166 0 166
863 166 return $ret=$self->SUPER::end($tag, @_);
864 }
865 }
866 elsif ($tag eq 'script') {
867  
868  
869 # Script tag, presumably of type application/perl
870 #
871 225 0 && debug('hit on script tag');
872  
873  
874 # Can we pop an array ref off script_stack ? If so means was webdyne tag
875 #
876 225 ▶ if (my $script_ar=pop(@{$self->{'_script_stack'}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $script_ar = pop @{$$self{'_script_stack'};}) { } 15 210 225
877  
878  
879 # Get vars from array ref
880 #
881 15 my ($script_or, $perl_tag, $perl_tag_or)=@{$script_ar};
882 15 0 && debug("popped script tag: $script_or, %s, about to end perl tag: $perl_tag (%s)", $script_or->tag(), $perl_tag_or->tag());
883  
884  
885 # End perl tag
886 #
887 15 0 && debug("end $perl_tag now");
888 15 ▶ $self->_text_block_tag($perl_tag_or->tag()) if $self->_text_block_tag();
Branch: 1 branch
BranchTrueFalseTotal
if $self->_text_block_tag 0 15 15
889 15 0 && debug("text_block_tag now %s, ending $perl_tag", $self->_text_block_tag());
890 15 $self->SUPER::end($perl_tag, @_);
891  
892  
893 # End script tag
894 #
895 15 0 && debug("end $tag now");
896 15 ▶ $self->pos()->{'_line_no_tag_end'}=$self->{'_line_no'} if (ref($self->pos()) eq 'HTML::Element');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->pos eq "HTML::Element" 15 0 15
897 15 $self->SUPER::end($tag, @_);
898 15 $self->_text_block_tag(undef);
899  
900  
901 # Re-arrange tree
902 #
903 15 0 && debug('script content %s', Dumper($script_or->content_list));
904  
905 #$perl_tag_or->push_content($script_or->detach_content());
906 15 $perl_tag_or->attr('perl', $script_or->detach_content());
907 15 $script_or->replace_with($perl_tag_or);
908 15 return 1;
909  
910 }
911 elsif (0) {
912  
913 0 && debug('null script stack pop, ignoring');
914 $self->_text_block_tag(undef);
915 return $ret=$self->SUPER::end($tag, @_);
916 }
917 }
918  
919  
920 13912 ▶ if ($self->_text_block_tag() && ($tag eq $self->_text_block_tag())) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_text_block_tag and $tag eq $self->_text_block_tag) { } 379 13533 13912
elsif ($self->_text_block_tag) { } 45 13488 13533
elsif (not $_[0] and delete $self->{'_end_ignore'}) { } 105 13383 13488
Condition100%3/3
$self->_text_block_tag and $tag eq $self->_text_block_tag
!ll&&!rl&&r
1348845379
MC/DC100%2/2
$self->_text_block_tag and $tag eq $self->_text_block_tag
$self->_text_block_tag $tag eq $self->_text_block_tag
Truth table100%3/3
A and B
A= $self->_text_block_tagB= $tag eq $self->_text_block_tag
ABresult
0X0
100
111
921 379 0 && debug("match on tag $tag to text_block_tag %s, clearing text_block_tag", $self->_text_block_tag());
922 379 $self->_text_block_tag(undef);
923 379 ▶ $self->pos()->{'_line_no_tag_end'}=$self->{'_line_no'} if (ref($self->pos()) eq 'HTML::Element');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->pos eq "HTML::Element" 379 0 379
924 379 $ret=$self->SUPER::end($tag, @_)
925 }
926 elsif ($self->_text_block_tag()) {
927 45 0 && debug('text segment via text_block_tag %s, passing to text handler', $self->_text_block_tag());
928 45 ▶ $self->pos()->{'_line_no_tag_end'}=$self->{'_line_no'} if (ref($self->pos()) eq 'HTML::Element');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->pos eq "HTML::Element" 45 0 45
929 45 $ret=$self->text($_[0])
930 }
931 ▶ elsif (!$_[0] && delete($self->{'_end_ignore'})) {
Condition100%3/3
not $_[0] and delete $self->{"_end_ignore"}
!ll&&!rl&&r
94653918105
MC/DC100%2/2
not $_[0] and delete $self->{"_end_ignore"}
not $_[0] delete $self->{"_end_ignore"}
Truth table100%3/3
not(A) and B
A= not $_[0]B= delete $self->{"_end_ignore"}
ABresult
0X0
100
111
932 # In this case $_[0] is the actual text of the end tag from the document. If the parser is signalling and end of a tag
933 # but $_[0] is empty it means it is an implicit close. We might want to ignore it, especially if it is triggered by a
934 # <div data-webdyne-perl> type tag.
935 105 0 && debug("attempt to close tag: $tag with active _div_stack, ignoring");
936 105 $ret=undef;
937 }
938 else {
939 13383 0 && debug("normal tag end: $tag, %s", $self->pos()->tag());
940 13383 ▶ $self->pos()->{'_line_no_tag_end'}=$self->{'_line_no'} if (ref($self->pos()) eq 'HTML::Element');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->pos eq "HTML::Element" 13281 102 13383
941 13383 $ret=$self->SUPER::end($tag, @_)
942 }
943
944
945 # Done, return
946 #
947 13912 0 && debug("end ret $ret");
948 13912 return $ret;
949  
950  
951 }
952  
953  
954 # Reminder to self. Keep this in, or implicit CGI tags will not be closed
955 # if text block follows implicit CGI tag immediately
956 #
957 28770 ▶sub text {
Subroutine text: called CC=13 SCAR=25.7
Pod documented
958  
959  
960 # get self ref, text we will process
961 #
962 28770 my ($self, $text)=@_;
963 28770 0 && debug('text *%s*, text_block_tag %s, pos: %s', $text, $self->_text_block_tag(), $self->{'_pos'});
964
965
966 # Are we chomping text ?
967 #
968 28770 ▶ if (delete $self->{'_chomp'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $self->{"_chomp"}) 45 28725 28770
969
970 # Yes. It's actually includes a "pre-chomp" as newline will be at start of the string
971 #
972 45 0 && debug('chomp flag detected, chomping text');
973 45 $text=~s/^\n//;
974  
975 }
976  
977  
978 # Ignore empty text. UPDATE - don't ignore or you will mangle CR in <pre> sections, especially if they contain tags
979 # like <span> in the <pre> section. Process and keep them inline. See also fact that trailing and leading CR's are
980 # converted to space characters by HTML::Parser as per convention.
981 #
982 # Leave this here as a reminder.
983 #
984 #return if ($text =~ /^\r?\n?$/);
985  
986  
987 # Are we in an inline perl block ?
988 #
989 #if ($self->_text_block_tag() eq 'perl') {
990 28770 ▶ if (grep { $self->_text_block_tag() eq $_ } qw(perl htmx api json)) {
Branch: 3 branches
BranchTrueFalseTotal
if (grep {$self->_text_block_tag eq $_;} 'perl', 'htmx', 'api', 'json') { } 1203 27567 28770
elsif ($text =~ /^\W*__CODE__/ or $text =~ /^\W*__PERL__/) { } 658 26909 27567
elsif ($text =~ /^\W*__END__/) { } 0 26909 26909
991  
992  
993 # Yes. We have inline perl code, not text. Just add to perl attribute, which
994 # is treated specially when rendering
995 #
996 1203 0 && debug('in <perl> tag, appending text to <perl> block');
997 1203 my $html_perl_or=$self->_html_perl_or();
998 1203 $html_perl_or->{'perl'}.=$text;
999 1203 $html_perl_or->{'_line_no_tag_end'}=$self->{'_line_no'};
1000  
1001  
1002 }
1003  
1004 # Used to do this so __PERL__ block would only count if at end of file.
1005 #elsif (($text=~/^\W*__CODE__/ || $text=~/^\W*__PERL__/) && !$self->{'_pos'}) {
1006 ▶ elsif (($text=~/^\W*__CODE__/ || $text=~/^\W*__PERL__/)) {
Condition66%2/3
$text =~ /^\W*__CODE__/ or $text =~ /^\W*__PERL__/
l!l&&r!l&&!r
065826909
MC/DC50%1/2
$text =~ /^\W*__CODE__/ or $text =~ /^\W*__PERL__/
$text =~ /^\W*__CODE__/ $text =~ /^\W*__PERL__/
Truth table66%2/3
A or B
A= $text =~ /^\W*__CODE__/B= $text =~ /^\W*__PERL__/
ABresult
1X1
011
000
1007  
1008  
1009 # Close off any HTML
1010 #
1011 658 ▶ delete $self->{'_pos'} if $self->{'_pos'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_pos"} 481 177 658
1012  
1013  
1014 # Perl code fragment. Will be last thing we do, as __PERL__ must be at the
1015 # bottom of the file.
1016 #
1017 658 0 && debug('found __PERL__ tag');
1018 658 $self->_text_block_tag('perl');
1019 658 $self->implicit(0);
1020  
1021 658 my $html_perl_or;
1022 658 $self->push_content($self->_html_perl_or($html_perl_or=HTML::Element->new('perl', inline => 1)));
1023 # Amended to stop autovivification
1024 #
1025 #debug('insert line_no: %s into object ref: %s', @{$self}{qw(_line_no _html_perl_or)});
1026 658 0 && debug('insert line_no: %s into object ref: %s', (map {$self->{$_}} qw(_line_no _html_perl_or)));
1027 658 @{$html_perl_or}{qw(_line_no _line_no_tag_end)}=@{$self}{qw(_line_no _line_no)};
1028 658 $html_perl_or->{'_code'}++;
1029
1030  
1031 }
1032 elsif ($text=~/^\W*__END__/) {
1033  
1034  
1035 # End of file
1036 #
1037 0 0 && debug('found __END__ tag, running eof');
1038 0 $self->eof();
1039  
1040 }
1041 else {
1042  
1043 # Normal text, process by parent class after handling any subst flags in code
1044 #
1045 26909 ▶ if ($text=~/([\$!+\^*]+)\{([\$!+]?)(.*?)\2\}/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /([\$!+\^*]+)\{([\$!+]?)(.*?)\2\}/s) { } 647 26262 26909
1046  
1047 # Meeds subst. Get rid of cr's at start and end of text after a <perl> tag, stuffs up formatting in <pre> sections
1048 #
1049 # Amend to stop autovivification
1050 #
1051 #debug("found subst tag line_no_start: %s, line_no: %s, text '$text', script_stack: %s, %s", @{$self}{qw(_line_no_start _line_no _script_stack)}, Dumper($self->{'_script_stack'}));
1052 647 0 && debug("found subst tag line_no_start: %s, line_no: %s, text '$text', script_stack: %s, %s", (map {$self->{$_}} qw(_line_no_start _line_no _script_stack)), Dumper($self->{'_script_stack'}));
1053  
1054 #my @cr=($text=~/\n/g);
1055 #if (my $html_or=$self->{'_pos'}) {
1056 # debug("parent %s", $html_or->tag());
1057 # if (($html_or->tag() eq 'perl') && !$html_or->attr('inline')) {
1058 # debug('hit !');
1059 #
1060 # # Why did I comment this out ?
1061 # #
1062 # #$text=~s/^\n//;
1063 # #$text=~s/\n$//;
1064 # }
1065 #}
1066
1067 # If in <script> block we probably don't want to be running subst over strings we find because ${varname} is valid Javascript
1068 # syntax and we shouldn't reallt ever need to subs in a script block (user can pass params to script). Nevertheless we'll give
1069 # them a subst option if they want
1070 #
1071 647 my $html_or=$self->{'_pos'};
1072 647 my %attr=$html_or->all_external_attr();
1073
1074
1075 # Gets a bit ugly for <script> tags. If <script> is Javascript *dont* run subst over it unless the user insists.
1076 #
1077 # First - are we inside a script tag. Easiest way is to see if in script_stack
1078 #
1079 647 ▶ if (@{$self->{'_script_stack'}} && (!$attr{'type'} || $WEBDYNE_SCRIPT_TYPE_EXECUTABLE_HR->{$attr{'type'}}) && !$attr{'subst'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$self->{'_script_stack'};} and !$attr{'type'} || $$WebDyne::HTML::TreeBuilder::WEBDYNE_SCRIPT_TYPE_EXECUTABLE_HR{$attr{'type'}} and not $attr{'subst'}) { } 60 587 647
elsif ($attr{'nosubst'}) { } 15 572 587
Condition88%8/9
@{$self->{"_script_stack"};} and !$attr{"type"} || $$WebDyne::HTML::TreeBuilder::WEBDYNE_SCRIPT_TYPE_EXECUTABLE_HR{$attr{"type"}} and not $attr{"subst"}
!ll&&!rl&&r
587060
@{$self->{"_script_stack"};} and !$attr{"type"} || $$WebDyne::HTML::TreeBuilder::WEBDYNE_SCRIPT_TYPE_EXECUTABLE_HR{$attr{"type"}}
!ll&&!rl&&r
5573060
not $attr{"type"} or $$WebDyne::HTML::TreeBuilder::WEBDYNE_SCRIPT_TYPE_EXECUTABLE_HR{$attr{"type"}}
l!l&&r!l&&!r
154530
MC/DC75%3/4
@{$self->{"_script_stack"};} and !$attr{"type"} || $$WebDyne::HTML::TreeBuilder::WEBDYNE_SCRIPT_TYPE_EXECUTABLE_HR{$attr{"type"}} and not $attr{"subst"}
@{$self->{"_script_stack"};} not $attr{"type"} $$WebDyne::HTML::TreeBuilder::WEBDYNE_SCRIPT_TYPE_EXECUTABLE_HR{$attr{"type"}} not $attr{"subst"}
Truth table66%4/6
A and not(B) or C and not(D)
A= @{$self->{"_script_stack"};}B= not $attr{"type"}C= $$WebDyne::HTML::TreeBuilder::WEBDYNE_SCRIPT_TYPE_EXECUTABLE_HR{$attr{"type"}}D= not $attr{"subst"}
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
1080 #if (@{$self->{'_script_stack'}} && !$attr{'subst'}) {
1081 60 0 && debug("script_stack present, bypass susbt: parent %s, attr: %s", $html_or->tag(), Dumper(\%attr));
1082 60 $self->tag_parse('SUPER::text', $text)
1083
1084 }
1085 elsif ($attr{'nosubst'}) {
1086 15 0 && debug('nosubst attr found in attr: %s', Dumper(\%attr));
1087 15 $self->tag_parse('SUPER::text', $text)
1088 }
1089 else {
1090 572 my $html_subst_or=HTML::Element->new('subst');
1091 # Amend to stop autovivification
1092 #debug("insert line_no: %s, line_no_tag_end: %s into object ref $html_subst_or for text $text", @{$self}{qw(_line_no_start _line_no)});
1093 572 0 && debug("insert line_no: %s, line_no_tag_end: %s into object ref $html_subst_or for text $text", (map {$self->{$_}} qw(_line_no_start _line_no)));
1094 572 @{$html_subst_or}{'_line_no', '_line_no_tag_end'}=@{$self}{qw(_line_no _line_no)};
1095 572 $html_subst_or->push_content($text);
1096 572 $self->tag_parse('SUPER::text', $html_subst_or)
1097 }
1098 }
1099 else {
1100  
1101 # No subst, process as normal
1102 #
1103 26262 0 && debug('processing as normal text');
1104 26262 $self->tag_parse('SUPER::text', $text)
1105 }
1106  
1107 }
1108  
1109  
1110 # Return self ref. Not really sure if this is what we should really return, but
1111 # seems to work
1112 #
1113 28770 $self;
1114  
1115 }
1116  
1117  
1118 272 ▶sub comment {
Subroutine comment: called CC=1 SCAR=0.0
Pod documented
1119  
1120 # Handle comments in HTML. Get HTML::Element ref
1121 #
1122 272 my $self=shift();
1123 272 my $html_or=$self->SUPER::comment(@_);
1124 272 0 && debug("$self html_or: $html_or comment: %s", Dumper(\@_));
1125  
1126  
1127 # Change tag to 'comment' from '~comment' so we can call comment render sub in WebDyne::HTML::Tidy (can't call sub starting with ~ in perl)
1128 #
1129 #$self->tag('comment'); # No longer needed, make ~comment sub work in WebDyne::HTML::Tiny
1130 272 0 && debug("insert line_no: %s into object ref $self", $self->{'_line_no'});
1131 272 @{$html_or}{qw(_line_no _line_no_tag_end)}=@{$self}{qw(_line_no_start _line_no)};
1132 272 return $html_or
1133  
1134 }
1135  
1136  
1137 2154 ▶sub start_html {
Subroutine start_html: called CC=1 SCAR=0.0
Pod undocumented
1138  
1139  
1140 # Handle this specially, inject into parser after rendering
1141 #
1142 2154 my ($self, $method, $tag, $attr_hr)=@_;
1143 2154 0 && debug("self: $self, method: $method, tag: $tag, attr_hr: %s", Dumper($attr_hr));
1144 2154 push @{$self->{'_html_wedge_ar'}}, (my $html=$self->{'_html_tiny_or'}->$tag($attr_hr));
1145 2154 return $self;
1146  
1147 }
1148  
1149  
1150 229 ▶sub end_html {
Subroutine end_html: called CC=1 SCAR=0.0
Pod undocumented
1151 229 &start_html(@_);
1152 }
1153  
1154  
1155 150 ▶sub start_form {
Subroutine start_form: called CC=1 SCAR=0.0
Pod undocumented
1156 150 &start_html(@_);
1157 }
1158  
1159  
1160 165 ▶sub end_form {
Subroutine end_form: called CC=1 SCAR=0.0
Pod undocumented
1161 165 &start_html(@_);
1162 }
1163  
1164  
1165 45 ▶sub start_multipart_form {
Subroutine start_multipart_form: called CC=1 SCAR=0.0
Pod undocumented
1166 45 &start_html(@_);
1167 }
1168  
1169  
1170 15 ▶sub end_multipart_form {
Subroutine end_multipart_form: called CC=1 SCAR=0.0
Pod undocumented
1171 15 &start_html(@_);
1172 }
1173  
1174  
1175 120 ▶sub include {
Subroutine include: called CC=1 SCAR=0.0
Pod undocumented
1176  
1177  
1178 # No special handling needed, just log for debugging purposes
1179 #
1180 120 my ($self, $method)=(shift, shift);
1181 120 0 && debug("block self $self, method $method, @_ text_block_tag %s", $self->_text_block_tag());
1182 120 $self->$method(@_);
1183  
1184  
1185 }
1186  
1187  
1188 451 ▶sub div {
Subroutine div: called CC=5 SCAR=16.1
Pod undocumented
1189  
1190  
1191 # Handle div tag specially, looking if they hold any webdyne aliases
1192 #
1193 451 my ($self, $method, $tag, $attr_hr, @param)=@_;
1194 451 0 && debug("$self in $tag, method:$method attr:%s", Dumper($attr_hr));
1195  
1196  
1197 # Get the div tag HTML::Element ref. Note now do this later in (if) blocks because it triggeres
1198 # auto-close if implicit tags like <p>, which we want to flag and stop happening if it's a webdyne
1199 # flag
1200 #
1201 #my $div_or=$self->$method($tag, $attr_hr, @param) ||
1202 # return err('unable to get HTML::Element ref for div tag: $tag, attr:%s', Dumper($attr_hr));
1203  
1204  
1205 # Do we have a pseudo webdyne command aliased in a div tag with a "data-webdyne" attributre (usually to keep a HTML editor happy
1206 # because it doesn't know anything about native webdyne tags
1207 #
1208 451 ▶ if (my @tag=grep {/^data-webdyne-/} keys %{$attr_hr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@tag) = grep({/^data-webdyne-/;} keys %{$attr_hr;})) { } 270 181 451
1209
1210
1211 # Set end_ignore flag to ignore parser trying to auto-close <p> etc. when we run this tag
1212 #
1213 270 $self->{'_end_ignore'}++;
1214 270 ▶ my $div_or=$self->$method($tag, $attr_hr, @param) ||
Condition50%1/2
$self->$method($tag, $attr_hr, @param) || (return err('unable to get HTML::Element ref for div tag: $tag, attr:%s', Dumper($attr_hr)))
l!l
2700
MC/DC0%0/1
$self->$method($tag, $attr_hr, @param) || (return err('unable to get HTML::Element ref for div tag: $tag, attr:%s', Dumper($attr_hr)))
$self->$method($tag, $attr_hr, @param)
Truth table50%1/2
A
A= $self->$method($tag, $attr_hr, @param)
Aresult
11
00
1215 return err('unable to get HTML::Element ref for div tag: $tag, attr:%s', Dumper($attr_hr));
1216  
1217  
1218 # Yes, we have one, get it
1219 #
1220 270 my $webdyne_tag=$tag[0];
1221  
1222  
1223 # And delete it from attribute list so it doesn't pollute, strip off data-webdyne lead
1224 #
1225 270 delete $attr_hr->{$webdyne_tag};
1226 270 $webdyne_tag=~s/^data-webdyne-//;
1227 270 0 && debug("found webdyne tag $webdyne_tag in div");
1228  
1229 # Convert to a start tag for HTML Tiny
1230 #
1231 270 my $html_tiny_tag="start_${webdyne_tag}";
1232  
1233  
1234 # Var to hold HTML::Element version of tag
1235 #
1236 270 0 && debug("generating $html_tiny_tag");
1237 270 ▶ my $webdyne_tag_or=$self->tag_parse('SUPER::start', $webdyne_tag, $attr_hr, @param) ||
Condition50%1/2
$self->tag_parse('SUPER::start', $webdyne_tag, $attr_hr, @param) || (return err("unable to create HTML::Element ref for tag:$webdyne_tag, attr_hr:%s", Dumper($attr_hr)))
l!l
2700
MC/DC0%0/1
$self->tag_parse('SUPER::start', $webdyne_tag, $attr_hr, @param) || (return err("unable to create HTML::Element ref for tag:$webdyne_tag, attr_hr:%s", Dumper($attr_hr)))
$self->tag_parse('SUPER::start', $webdyne_tag, $attr_hr, @param)
Truth table50%1/2
A
A= $self->tag_parse('SUPER::start', $webdyne_tag, $attr_hr, @param)
Aresult
11
00
1238 return err("unable to create HTML::Element ref for tag:$webdyne_tag, attr_hr:%s", Dumper($attr_hr));
1239  
1240  
1241 # Now push onto div stack and return div HTML::Element ref
1242 #
1243 270 push @{$self->{'_div_stack'}}, [$div_or, $webdyne_tag, $webdyne_tag_or];
1244 270 return $div_or;
1245  
1246 }
1247 else {
1248  
1249 # Normal div tag, push undef onto stack to denote vanilla
1250 #
1251 181 0 && debug('hit on vanilla div tag');
1252 181 ▶ my $div_or=$self->$method($tag, $attr_hr, @param) ||
Condition50%1/2
$self->$method($tag, $attr_hr, @param) || (return err('unable to get HTML::Element ref for div tag: $tag, attr:%s', Dumper($attr_hr)))
l!l
1810
MC/DC0%0/1
$self->$method($tag, $attr_hr, @param) || (return err('unable to get HTML::Element ref for div tag: $tag, attr:%s', Dumper($attr_hr)))
$self->$method($tag, $attr_hr, @param)
Truth table50%1/2
A
A= $self->$method($tag, $attr_hr, @param)
Aresult
11
00
1253 return err('unable to get HTML::Element ref for div tag: $tag, attr:%s', Dumper($attr_hr));
1254 181 push @{$self->{'_div_stack'}}, undef;
1255 181 return $div_or;
1256  
1257 }
1258  
1259 }
1260  
1261  
1262 # Getter setter. Not used for line numbers yet, prep for future cleanup
1263 #
1264 168284 ▶sub _get_set {
Subroutine _get_set: called CC=2 SCAR=6.9
1265  
1266 168284 my ($key, $self, $value)=@_;
1267 168284 0 && debug("$self, key: $key, value: $value, store: %s", ($self->{$key} || '<none>'));
1268 168284 ▶ return (@_==3) ? $self->{$key}=$value : $self->{$key}
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 ? : 2841 165443 168284
1269
1270 }
1271  
1272 0 ▶map { eval("sub $_ { &_get_set($_, \@_) }") } qw(_text_block_tag _line_no _line_no_next _line_no_start _html_perl_or);
Subroutine _html_perl_or: called CC=1 SCAR=0.8
Subroutine _line_no: not called CC=1 SCAR=0.8
Subroutine _line_no_next: not called CC=1 SCAR=0.8
Subroutine _line_no_start: not called CC=1 SCAR=0.8
Subroutine _text_block_tag: called CC=1 SCAR=0.8
1273  
1274  
1275 # Done
1276 #
1277 30 1;
1278 __END__
« blib/lib/WebDyne/Session.pm ↑ Summary bin/wdcompile »