lib/WebDyne.pm

filter: Statementstmt 39.4% 586 / 1485 Branchbran 22.9% 137 / 598 Conditioncond 16.3% 91 / 558 MC/DCmcdc 1.3% 4 / 307 Subroutinesub 48.0% 62 / 129 Podpod 0.0% 0 / 63 totaltotal 28.0% 880 / 3140 CC 536 SCAR 66.3
CC
536
Cov
31%
handler
3518.3
include
1406.0
subrequest
462.0
CRAP 759.7
↑ Summary blib/lib/WebDyne/Err.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;
14  
15  
16 # Pragma
17 #
18 3 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use vars qw($VERSION $AUTHORITY $VERSION_GIT_SHA %CGI_TAG_WEBDYNE @ISA $AUTOLOAD @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶no warnings qw(uninitialized redefine once qw);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use overload;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24  
25 # WebDyne constants, base modules
26 #
27 3 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶use WebDyne::CGI::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 ▶use WebDyne::HTML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32  
33 # External Modules
34 #
35 3 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 3 ▶use HTTP::Status qw(:constants is_success is_error is_redirect);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 3 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 3 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶use File::Spec::Unix;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 3 ▶use HTML::Entities qw(decode_entities encode_entities);
Subroutine BEGIN: called CC=1 SCAR=0.0
43 3 ▶use CGI::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 3 ▶use Cwd qw(fastcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 3 ▶use Sub::Util qw(set_subname);
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47  
48 # Data::Dumper config for debugging
49 #
50 3 local $Data::Dumper::Indent=1;
51 3 local $Data::Dumper::Sortkeys=1;
52 3 local $Data::Dumper::Terse=1;
53  
54  
55 # Inherit from the Compile module, not loaded until needed though.
56 #
57 3 @ISA=qw(WebDyne::Compile);
58  
59  
60 # Export a couple of convenience methods for scripts
61 #
62 3 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
63 3 @EXPORT_OK = qw(html html_sr);
64  
65  
66 # Version information
67 #
68 3 $AUTHORITY='cpan:ASPEER';
69 3 $VERSION='3.027';
70 3 ▶chomp($VERSION_GIT_SHA=do { local (@ARGV, $/) = ($_=__FILE__.'.sha'); <> if -f $_ });
Branch: 1 branch
BranchTrueFalseTotal
if -f $_ 3 0 3
71  
72  
73 # Debug load
74 #
75 3 debug("%s loaded, version $VERSION", __PACKAGE__);
76  
77  
78 # Shortcut error handler, save using ISA;
79 #
80 3 require WebDyne::Err;
81 3 ▶*err_html=\&WebDyne::Err::err_html || *err_html;
Condition33%1/3
\&WebDyne::Err::err_html || *err_html
l!l&&r!l&&!r
300
MC/DC0%0/2
\&WebDyne::Err::err_html || *err_html
\&WebDyne::Err::err_html *err_html
Truth table33%1/3
A || B
A= \&WebDyne::Err::err_htmlB= *err_html
ABresult
1X1
011
000
82 3 ▶*err_eval=\&WebDyne::Err::err_eval || *err_eval;
Condition33%1/3
\&WebDyne::Err::err_eval || *err_eval
l!l&&r!l&&!r
300
MC/DC0%0/2
\&WebDyne::Err::err_eval || *err_eval
\&WebDyne::Err::err_eval *err_eval
Truth table33%1/3
A || B
A= \&WebDyne::Err::err_evalB= *err_eval
ABresult
1X1
011
000
83  
84  
85 # Our webdyne "special" tags
86 #
87 3 %CGI_TAG_WEBDYNE=map {$_ => 1} (
88  
89 'block',
90 'perl',
91 'subst',
92 'dump',
93 'json',
94 'api',
95 'include',
96 'htmx'
97  
98 );
99  
100  
101 # Var to hold package wide hash, for data shared across package
102 #
103 3 our %Package;
104  
105  
106 # Do some class wide initialisation
107 #
108 3 &init();
109  
110  
111 # Eval safe not effective - die if turned on
112 #
113 3 if (WEBDYNE_EVAL_SAFE) {die "WEBDYNE_EVAL_SAFE disabled in this version\n"}
114  
115  
116 # All done. Positive return
117 #
118 3 1;
119  
120  
121 #==================================================================================================
122  
123  
124 # Packace init, attempt to load optional Time::HiRes, Devel::Confess modules
125 #
126 BEGIN {
127 3 ▶ eval {require Time::HiRes; Time::HiRes->import('time')};
Subroutine BEGIN: called CC=1 SCAR=0.0
128 3 eval {require Devel::Confess; Devel::Confess->import(qw(no_warnings))};
129 }
130  
131  
132  
133 # Convenience method for script usage, not used when called from mod_perl or PSGI - they call
134 # handler method below. Return scalar ref for efficiency here
135 #
136 sub html_sr {
137  
138  
139 # Supplied with class and options hash. Options can be supplied as hash ref
140 # or hash, convert.
141 #
142 8 ▶ my ($fn, $opt_hr, @param)=@_;
Subroutine html_sr: called CC=13 SCAR=26.6
Pod undocumented
143 8 ▶ if (ref($fn)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $fn) { } 1 7 8
elsif (ref $opt_hr ne 'HASH') { } 3 4 7
144 1 $opt_hr=$fn
145 }
146 elsif (ref($opt_hr) ne 'HASH') {
147 3 ▶ $opt_hr={ $opt_hr, @param } if $opt_hr;
Branch: 1 branch
BranchTrueFalseTotal
if $opt_hr 1 2 3
148 }
149 8 ▶ $opt_hr->{'filename'}=$fn unless ref($fn);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fn 7 1 8
150  
151  
152 # Capture handler output
153 #
154 8 my $html;
155 8 ▶ my $html_fh=$opt_hr->{'outfile'} || do {
Condition66%2/3
$opt_hr->{'outfile'} || do { require IO::String; 'IO::String'->new($html) }
l!l&&r!l&&!r
260
MC/DC0%0/2
$opt_hr->{'outfile'} || do { require IO::String; 'IO::String'->new($html) }
$opt_hr->{'outfile'} do { require IO::String; 'IO::String'->new($html) }
Truth table66%2/3
A || B
A= $opt_hr->{'outfile'}B= do { require IO::String; 'IO::String'->new($html) }
ABresult
1X1
011
000
156 6 require IO::String; IO::String->new($html);
157 };
158 8 $opt_hr->{'select'}=$html_fh;
159
160
161 # Need to setup a fake request handler if initiated via script
162 #
163 8 require WebDyne::Request::Fake;
164 8 ▶ my $r=$opt_hr->{'r'} || WebDyne::Request::Fake->new(%{$opt_hr}) ||
Condition40%2/5
$opt_hr->{'r'} || 'WebDyne::Request::Fake'->new(%{$opt_hr;}) || (return err())
l!l
80
$opt_hr->{"r"} or "WebDyne::Request::Fake"->new(%{$opt_hr;})
l!l&&r!l&&!r
080
MC/DC0%0/2
$opt_hr->{'r'} || 'WebDyne::Request::Fake'->new(%{$opt_hr;}) || (return err())
$opt_hr->{"r"} "WebDyne::Request::Fake"->new(%{$opt_hr;})
Truth table33%1/3
A or B
A= $opt_hr->{"r"}B= "WebDyne::Request::Fake"->new(%{$opt_hr;})
ABresult
1X1
011
000
165 return err();
166  
167  
168 # Get handler
169 #
170 8 my $handler=$opt_hr->{'handler'};
171 8 ▶ if ($handler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) 0 8 8
172 0 ▶ eval("require $handler") ||
Branch: 1 branch
BranchTrueFalseTotal
eval "require $handler" or return err("unable to load handler $handler, $@") 0 0 0
173 return err("unable to load handler $handler, $@");
174 }
175 8 ▶ $handler ||= (__PACKAGE__);
Condition50%1/2
$handler ||= __PACKAGE__
l!l
08
MC/DC0%0/1
$handler ||= __PACKAGE__
$handler
Truth table50%1/2
A
A= $handler
Aresult
11
00
176
177
178 # Run
179 #
180 8 ▶ defined($handler->handler(grep {$_} $r, $opt_hr->{'param'})) || return err();
Branch: 1 branch
BranchTrueFalseTotal
defined $handler->handler(grep({$_;} $r, $opt_hr->{"param"})) or return err() 0 8 8
181  
182  
183 # Manual cleanup
184 #
185 8 $r->DESTROY();
186
187  
188 # Returm
189 #
190 8 ▶ if (ref($html_fh) eq 'IO::String') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $html_fh eq 'IO::String') { } 6 2 8
191 6 $html_fh->close();
192 6 return \$html;
193 }
194 else {
195 2 return \undef;
196 }
197  
198 }
199  
200  
201 # Or scalar
202 #
203 6 ▶sub html { return ${&html_sr(@_)} };
Subroutine html: called CC=1 SCAR=0.0
Pod undocumented
204  
205  
206 # Main handler for mod_perl and PSGI
207 #
208 sub handler : method { # no subsort
209  
210  
211 # Get self ref/class, request ref
212 #
213 9 ▶ my ($self, $r, $param_hr)=@_;
Subroutine handler: called CC=114 SCAR=81.7
Pod undocumented
214 9 debug("handler called with self: $self, r: $r, MP2: $MP2, param: %s", Dumper($param_hr));
215
216
217 # Update r if needed
218 #
219 9 ▶ if (ref($r)=~/^Apache/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($r) =~ /^Apache/) 0 9 9
220 0 debug("converting r: $r to WebDyne::Request::Apache module");
221 0 require WebDyne::Request::Apache;
222 0 my %opt=map { do { (my $k=lc($_))=~s/^webdyne_request_//i; ($k=>$ENV{$_}) } } (grep {/^WEBDYNE_REQUEST_/} keys %ENV);
223 0 $r=WebDyne::Request::Apache->new($r, %opt);
224 0 debug("r now: $r");
225 }
226  
227  
228 # Start timer so we can optionally keep stats on how long handler takes to run
229 #
230 9 my $time=($self->{'_time'}=time());
231  
232  
233 # Work out class and correct self ref
234 #
235 9 ▶ my $class=ref($self) || do {
Condition33%1/3
ref $self || do { my(%self) = ('_time', $time, '_r', $r, %{delete $self->{'_self'};}); $self = bless(\%self, $self); ref $self }
l!l&&r!l&&!r
090
MC/DC0%0/2
ref $self || do { my(%self) = ('_time', $time, '_r', $r, %{delete $self->{'_self'};}); $self = bless(\%self, $self); ref $self }
ref $self do { my(%self) = ('_time', $time, '_r', $r, %{delete $self->{'_self'};}); $self = bless(\%self, $self); ref $self }
Truth table33%1/3
A || B
A= ref $selfB= do { my(%self) = ('_time', $time, '_r', $r, %{delete $self->{'_self'};}); $self = bless(\%self, $self); ref $self }
ABresult
1X1
011
000
236  
237  
238 # Need new self ref, as self is actually class. Do inline so quicker than -> new
239 #
240 my %self=(
241  
242 _time => $time,
243 _r => $r,
244 9 %{delete $self->{'_self'}},
245  
246 );
247 9 $self=bless \%self, $self;
248 9 ref($self);
249  
250  
251 };
252  
253  
254 # Setup error handlers
255 #
256 9 local $SIG{'__DIE__'} =\&handler_die;
257 9 local $SIG{'__WARN__'}=\&handler_warn;
258
259  
260 # Debug
261 #
262 9 debug(
263 "in WebDyne::handler, class: $class, self: $self, r: $r (%s), param_hr: %s", Dumper($r, $param_hr));
264  
265  
266 # Skip all processing if header request only
267 #
268 9 ▶ if ($r->header_only()) {return &head_request($r)}
Branch: 1 branch
BranchTrueFalseTotal
if ($r->header_only) 0 9 9
269  
270  
271 # Debug
272 #
273 debug(
274 9 "enter handler, r: $r, location: %s, file: %s, param: %s",
275 $r->location(), $r->filename(), Dumper($param_hr));
276  
277  
278 # Get full path, mtime of source file, check file exists
279 #
280 9 ▶ my $srce_pn=$r->filename() || do {
Condition33%1/3
$r->filename || do { debug('could not find file, returning'); return $WebDyne::MP2 ? &Apache::DECLINED : $r->status(404) }
l!l&&r!l&&!r
900
MC/DC0%0/2
$r->filename || do { debug('could not find file, returning'); return $WebDyne::MP2 ? &Apache::DECLINED : $r->status(404) }
$r->filename do { debug('could not find file, returning'); return $WebDyne::MP2 ? &Apache::DECLINED : $r->status(404) }
Truth table33%1/3
A || B
A= $r->filenameB= do { debug('could not find file, returning'); return $WebDyne::MP2 ? &Apache::DECLINED : $r->status(404) }
ABresult
1X1
011
000
281
282 # Couldn't find file in request, decline
283 #
284 0 debug('could not find file, returning');
285 0 ▶ return $MP2 ? &Apache::DECLINED : $r->status(HTTP_NOT_FOUND);
Branch: 1 branch
BranchTrueFalseTotal
$WebDyne::MP2 ? : 0 0 0
286 };
287
288
289 # Get source file mtime. Be careful as mtime may be 0 on some virtual file
290 # systems
291 #
292 9 my $srce_mtime;
293 9 ▶ $srce_mtime=(stat(_))[9] if (-f $srce_pn);
Branch: 1 branch
BranchTrueFalseTotal
if -f $srce_pn 8 1 9
294 9 ▶ defined($srce_mtime) || do {
Branch: 1 branch
BranchTrueFalseTotal
defined $srce_mtime or do { debug("srce_mtime for file '${srce_pn}' not found, could not stat !"); return $WebDyne::MP2 ? &Apache::DECLINED : $r->status(404) } 1 8 9
295  
296 # Found file but couldn't stat or similar issue
297 #
298 1 debug("srce_mtime for file '$srce_pn' not found, could not stat !");
299 1 ▶ return $MP2 ? &Apache::DECLINED : $r->status(HTTP_NOT_FOUND);
Branch: 1 branch
BranchTrueFalseTotal
$WebDyne::MP2 ? : 0 1 1
300 # return &Apache::DECLINED;
301  
302 };
303 8 debug("srce_pn: $srce_pn, srce_mtime (real): $srce_mtime");
304  
305  
306 # Used to use inode as unique identifier for file in cache, but that
307 # did not take into account the fact that the same file may have diff
308 # Apache locations (and thus WebDyne::Chain) handlers for the same
309 # physical file. So we now use an md5 hash of handler, location and
310 # file name, but the var name is still "inode";
311 #
312 RENDER_BEGIN:
313 my $srce_inode=(
314 8 ▶ $self->{'_inode'} ||= md5_hex(ref($self), $r->location, $srce_pn)
Condition40%2/5
$self->{"_inode"} ||= md5_hex(ref $self, $r->location, $srce_pn) || (return $self->err_html("could not get md5 for file $srce_pn, $!"))
l!l&&r!l&&!r
080
md5_hex(ref $self, $r->location, $srce_pn) || (return $self->err_html("could not get md5 for file $srce_pn, $!"))
l!l
80
MC/DC0%0/2
$self->{"_inode"} ||= md5_hex(ref $self, $r->location, $srce_pn) || (return $self->err_html("could not get md5 for file $srce_pn, $!"))
$self->{"_inode"} md5_hex(ref $self, $r->location, $srce_pn)
Truth table33%1/3
A ||= B
A= $self->{"_inode"}B= md5_hex(ref $self, $r->location, $srce_pn)
ABresult
1X1
011
000
315 ||
316 return $self->err_html("could not get md5 for file $srce_pn, $!"));
317 8 debug("srce_inode: $srce_inode");
318  
319  
320 # Var to hold pointer to cached metadata area, so we are not constantly
321 # dereferencing $Package{'_cache'}{$srce_inode};
322 #
323 my $cache_inode_hr=(
324 8 ▶ $Package{'_cache'}{$srce_inode} ||= {
Condition75%3/4
($WebDyne::Package{'_cache'}{$srce_inode} ||= {'data', undef, 'mtime', undef, 'nrun', undef, 'lrun', undef}) || (return $self->err_html('unable to initialize cache_inode_hr ref'))
l!l
80
$WebDyne::Package{"_cache"}{$srce_inode} ||= {"data", undef, "mtime", undef, "nrun", undef, "lrun", undef}
l!l
53
MC/DC0%0/1
($WebDyne::Package{'_cache'}{$srce_inode} ||= {'data', undef, 'mtime', undef, 'nrun', undef, 'lrun', undef}) || (return $self->err_html('unable to initialize cache_inode_hr ref'))
($WebDyne::Package{'_cache'}{$srce_inode} ||= {'data', undef, 'mtime', undef, 'nrun', undef, 'lrun', undef})
MC/DC100%1/1
$WebDyne::Package{"_cache"}{$srce_inode} ||= {"data", undef, "mtime", undef, "nrun", undef, "lrun", undef}
$WebDyne::Package{"_cache"}{$srce_inode}
Truth table50%1/2
A
A= ($WebDyne::Package{'_cache'}{$srce_inode} ||= {'data', undef, 'mtime', undef, 'nrun', undef, 'lrun', undef})
Aresult
11
00
Truth table100%2/2
A
A= $WebDyne::Package{"_cache"}{$srce_inode}
Aresult
11
00
325  
326 data => undef, # holds compiled representation of html/psp file
327 mtime => undef, # last modified time of the Storable disk cache file
328 nrun => undef, # number of times this page run by this mod_perl child
329 lrun => undef, # last run time of this page by this mod_perl child
330  
331 # Created if needed
332 #
333 # meta => undef, # page meta data, held in meta section or supplied by add-on modules
334 # eval_cr => undef, # where anonymous sub's representing eval'd perl code within this page are held
335 # perl_init => undef, # flags that perl code in __PERL__ block has been init'd (run once at page load)
336  
337 }) || return $self->err_html('unable to initialize cache_inode_hr ref');
338  
339  
340 # Get "effective" source mtime, as may be a combination of things including
341 # template (eg menu) mtime. Here so can be subclassed by other handler like
342 # menu systems
343 #
344 8 debug("about to call source_mtime, self: $self");
345 $srce_mtime=${
346 8 ▶ $self->source_mtime($srce_mtime) || return $self->err_html()}
Branch: 1 branch
BranchTrueFalseTotal
$self->source_mtime($srce_mtime) or return $self->err_html 0 8 8
Condition33%1/3
${$self->source_mtime($srce_mtime) or return $self->err_html;} || $srce_mtime
l!l&&r!l&&!r
080
MC/DC0%0/2
${$self->source_mtime($srce_mtime) or return $self->err_html;} || $srce_mtime
${$self->source_mtime($srce_mtime) or return $self->err_html;} $srce_mtime
Truth table33%1/3
A || B
A= ${$self->source_mtime($srce_mtime) or return $self->err_html;}B= $srce_mtime
ABresult
1X1
011
000
347 || $srce_mtime;
348 8 debug("srce_pn: $srce_pn, srce_mtime (computed): $srce_mtime");
349  
350  
351 # Need to stat cache file mtime in case another process has updated it (ie via self->cache_compile(1)) call,
352 # which will make our memory cache stale. Would like to not have to do this stat one day, perhaps via shmem
353 # or similar check
354 #
355 # Only do if cache directory defined
356 #
357 8 my ($cache_pn, $cache_mtime);
358 8 if (WEBDYNE_CACHE_DN) {
359 debug("webdyne_cache_dn: $WEBDYNE_CACHE_DN");
360 $cache_pn=File::Spec->catfile(WEBDYNE_CACHE_DN, $srce_inode);
361  
362 # Cache stat policy:
363 # 0 = always stat, preserving historical freshness behaviour.
364 # >0 = reuse the last stat result until the TTL expires.
365 # <0 = reuse the last stat result for the life of this process.
366 #
367 # The combined test below is intentionally a little dense so both TTL
368 # and process-lifetime caching go through the same cached-result path.
369 # That avoids split logic in this hot request path; for negative TTL we
370 # also avoid calling time() once a stat result has been cached.
371 #
372 my $cache_stat_ttl=WEBDYNE_CACHE_STAT_TTL;
373 if (
374 $cache_stat_ttl
375 && $cache_inode_hr->{'cache_stat_set'}
376 && (
377 ($cache_stat_ttl < 0)
378 || ((time() - $cache_inode_hr->{'cache_stat_time'}) < $cache_stat_ttl)
379 )
380 ) {
381 $cache_mtime=$cache_inode_hr->{'cache_stat_mtime'};
382 }
383 else {
384 $cache_mtime=(stat(_))[9] if -f $cache_pn;
385 if ($cache_stat_ttl) {
386 $cache_inode_hr->{'cache_stat_set'}=1;
387 $cache_inode_hr->{'cache_stat_time'}=time() if ($cache_stat_ttl > 0);
388 $cache_inode_hr->{'cache_stat_mtime'}=$cache_mtime;
389 }
390 }
391 debug("webdyne_cache file: $cache_pn, cache_mtime: $cache_mtime");
392 }
393 else {
394 8 debug('no webdyne_cache_dn');
395 }
396 #die if ($param_hr->{'count'}==2);
397  
398  
399 # Test if compile/reload needed
400 #
401 8 my $cache_inode_mtime=$cache_inode_hr->{'mtime'};
402 8 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_compile'} or not defined $cache_inode_hr->{'data'} or not defined $cache_inode_mtime or $cache_inode_mtime < $srce_mtime or defined $cache_mtime and $cache_mtime > $cache_inode_mtime) { } 3 5 8
Condition60%9/15
$self->{"_compile"} or not defined $cache_inode_hr->{"data"} or not defined $cache_inode_mtime or $cache_inode_mtime < $srce_mtime or defined $cache_mtime and $cache_mtime > $cache_inode_mtime
l!l&&r!l&&!r
305
$self->{"_compile"} or not defined $cache_inode_hr->{"data"} or not defined $cache_inode_mtime or $cache_inode_mtime < $srce_mtime
l!l&&r!l&&!r
305
$self->{"_compile"} or not defined $cache_inode_hr->{"data"} or not defined $cache_inode_mtime
l!l&&r!l&&!r
305
$self->{"_compile"} or not defined $cache_inode_hr->{"data"}
l!l&&r!l&&!r
035
defined $cache_mtime and $cache_mtime > $cache_inode_mtime
!ll&&!rl&&r
500
MC/DC16%1/6
$self->{"_compile"} or not defined $cache_inode_hr->{"data"} or not defined $cache_inode_mtime or $cache_inode_mtime < $srce_mtime or defined $cache_mtime and $cache_mtime > $cache_inode_mtime
$self->{"_compile"} not defined $cache_inode_hr->{"data"} not defined $cache_inode_mtime $cache_inode_mtime < $srce_mtime defined $cache_mtime $cache_mtime > $cache_inode_mtime
Truth table28%2/7
A or not(B) or not(C) or D or E and F
A= $self->{"_compile"}B= not defined $cache_inode_hr->{"data"}C= not defined $cache_inode_mtimeD= $cache_inode_mtime < $srce_mtimeE= defined $cache_mtimeF= $cache_mtime > $cache_inode_mtime
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
0000111
00000X0
0000100
403 WEBDYNE_RELOAD
404 || $self->{'_compile'}
405 || !defined($cache_inode_hr->{'data'})
406 || !defined($cache_inode_mtime)
407 || ($cache_inode_mtime < $srce_mtime)
408 || (
409 defined($cache_mtime)
410 && ($cache_mtime > $cache_inode_mtime)
411 )
412 ) {
413  
414  
415 # Debug
416 #
417 debug(
418 "compile/reload needed _compile: %s, cache_inode_hr mtime: %s, srce_mtime: $srce_mtime, WEBDYNE::RELOAD: $WEBDYNE_RELOAD",
419 3 $self->{'_compile'}, $cache_inode_hr->{'mtime'});
420  
421  
422 # use Module::Reload to reload modules
423 #
424 3 if (WEBDYNE_RELOAD) {
425 local $SIG{'__DIE__'};
426 unless ($INC{'Module/Reload.pm'}) {
427 debug('loading Module::Reload');
428 eval {require Module::Reload};
429 return $self->err_html('unable to load Module::Reload - is it installed ?') if $@;
430 }
431 debug('running Module::Reload->check');
432 $Module::Reload::Debug=1;
433 Module::Reload->check();
434  
435 #delete $Package{'_cache'}{$srce_inode};
436 }
437  
438  
439 # Null out cache_inode to clear any flags
440 #
441 3 foreach my $key (keys %{$cache_inode_hr}) {
442 12 debug("nulling out cache_inode_hr key: $key");
443 12 $cache_inode_hr->{$key}=undef;
444 }
445  
446  
447 # Try to clear/reset package name space if possible
448 #
449 eval {
450 3 require Symbol;
451 3 &Symbol::delete_package("WebDyne::${srce_inode}");
452 3 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Symbol; &Symbol::delete_package("WebDyne::$srce_inode") } } or do { eval { do { () } } if $@; my $stash_hr = *{"WebDyne::${srce_inode}::";}{"HASH"}; foreach $_ (keys %{$stash_hr;}) { undef *{"WebDyne::${srce_inode}::$_";}; } ; %{$stash_hr;} = (); delete *main::WebDyne::{"HASH"}->{$srce_inode} } 3 0 3
453 3 ▶ eval {} if $@; #clear $@ after error above
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
454 3 my $stash_hr=*{"WebDyne::${srce_inode}::"}{HASH};
455 3 foreach (keys %{$stash_hr}) {
456 0 undef *{"WebDyne::${srce_inode}::${_}"};
457 }
458 3 %{$stash_hr}=();
459 3 delete *WebDyne::{'HASH'}->{$srce_inode};
460 };
461  
462  
463 # Debug
464 #
465 3 debug("srce_pn: $srce_pn, cache_pn: $cache_pn, mtime: $cache_mtime");
466  
467  
468 3 my $container_ar;
469 3 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_compile'} or not defined $cache_mtime or $cache_mtime < $srce_mtime) { } 3 0 3
Condition33%2/6
$self->{"_compile"} or not defined $cache_mtime or $cache_mtime < $srce_mtime
l!l&&r!l&&!r
300
$self->{"_compile"} or not defined $cache_mtime
l!l&&r!l&&!r
030
MC/DC0%0/3
$self->{"_compile"} or not defined $cache_mtime or $cache_mtime < $srce_mtime
$self->{"_compile"} not defined $cache_mtime $cache_mtime < $srce_mtime
Truth table25%1/4
A or not(B) or C
A= $self->{"_compile"}B= not defined $cache_mtimeC= $cache_mtime < $srce_mtime
ABCresult
1XX1
01X1
0011
0000
470 $self->{'_compile'}
471 || !defined($cache_mtime)
472 || ($cache_mtime < $srce_mtime)
473 ) {
474  
475 # Debug
476 #
477 3 debug("compiling srce: $srce_pn, dest: $cache_pn");
478  
479  
480 # Recompile from source
481 #
482 3 ▶ eval {require WebDyne::Compile}
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require WebDyne::Compile } } or return $self->err_html(errsubst("unable to load WebDyne:Compile, %s", $@ || "undefined error")) 0 3 3
Condition0%0/2
$@ || 'undefined error'
l!l
00
MC/DC0%0/1
$@ || 'undefined error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
483 || return $self->err_html(
484 errsubst('unable to load WebDyne:Compile, %s', $@ || 'undefined error'));
485  
486  
487 # Source newer than compiled version, must recompile file
488 #
489 3 ▶ $container_ar=$self->compile(
Condition50%1/2
$self->compile({'srce', $srce_pn, 'dest', $cache_pn}) || (return $self->err_html)
l!l
30
MC/DC0%0/1
$self->compile({'srce', $srce_pn, 'dest', $cache_pn}) || (return $self->err_html)
$self->compile({'srce', $srce_pn, 'dest', $cache_pn})
Truth table50%1/2
A
A= $self->compile({'srce', $srce_pn, 'dest', $cache_pn})
Aresult
11
00
490 {
491  
492 srce => $srce_pn,
493 dest => $cache_pn,
494  
495 }) || return $self->err_html();
496  
497  
498 # Check for any unhandled errors during compile
499 #
500 3 ▶ errstr() && return $self->err_html();
Branch: 1 branch
BranchTrueFalseTotal
errstr() and return $self->err_html 0 3 3
501  
502  
503 # Update mtime flag, or use current time if we were not able to read
504 # cache file (probably because temp dir was not writable - which would
505 # generated a warning in the logs from the Compile module, so no point
506 # making a fuss about it here anymore.
507 #
508 3 ▶ $cache_mtime=(stat($cache_pn))[9] if $cache_pn; # ||
Branch: 1 branch
BranchTrueFalseTotal
if $cache_pn 0 3 3
509 #return $self->err_html("could not stat cache file '$cache_pn'");
510 3 ▶ $cache_inode_hr->{'mtime'}=defined($cache_mtime) ? $cache_mtime : time();
Branch: 1 branch
BranchTrueFalseTotal
defined $cache_mtime ? : 0 3 3
511 3 my $cache_stat_ttl=WEBDYNE_CACHE_STAT_TTL;
512 3 ▶ if ($cache_stat_ttl && $cache_pn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_stat_ttl and $cache_pn) 0 3 3
Condition33%1/3
$cache_stat_ttl and $cache_pn
!ll&&!rl&&r
300
MC/DC0%0/2
$cache_stat_ttl and $cache_pn
$cache_stat_ttl $cache_pn
Truth table33%1/3
A and B
A= $cache_stat_ttlB= $cache_pn
ABresult
0X0
100
111
513 0 $cache_inode_hr->{'cache_stat_set'}=1;
514 0 ▶ $cache_inode_hr->{'cache_stat_time'}=time() if ($cache_stat_ttl > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $cache_stat_ttl > 0 0 0 0
515 0 $cache_inode_hr->{'cache_stat_mtime'}=$cache_mtime;
516 }
517  
518  
519 }
520 else {
521  
522 # Debug
523 #
524 0 debug("loading from disk cache");
525  
526  
527 # Load from storeable file
528 #
529 0 ▶ $container_ar=Storable::lock_retrieve($cache_pn) ||
Condition0%0/2
Storable::lock_retrieve($cache_pn) || (return $self->err_html("Storable error when retreiveing cached file: '${cache_pn}', $!"))
l!l
00
MC/DC0%0/1
Storable::lock_retrieve($cache_pn) || (return $self->err_html("Storable error when retreiveing cached file: '${cache_pn}', $!"))
Storable::lock_retrieve($cache_pn)
Truth table0%0/2
A
A= Storable::lock_retrieve($cache_pn)
Aresult
11
00
530 return $self->err_html("Storable error when retreiveing cached file: '$cache_pn', $!");
531  
532  
533 # Update mtime flag
534 #
535 0 $cache_inode_hr->{'mtime'}=$cache_mtime;
536  
537  
538 # Re-run perl-init for this node. Not done above because handled in compile if needed
539 #
540 0 ▶ if (my $meta_hr=$container_ar->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meta_hr = $container_ar->[0]) 0 0 0
541 0 ▶ if (my $perl_ar=$meta_hr->{'perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $perl_ar = $meta_hr->{"perl"}) 0 0 0
542 0 ▶ my $perl_debug_ar=$meta_hr->{'perl_debug'} ||
Condition0%0/2
$meta_hr->{'perl_debug'} || (return err('unable to load perl_debug array reference'))
l!l
00
MC/DC0%0/1
$meta_hr->{'perl_debug'} || (return err('unable to load perl_debug array reference'))
$meta_hr->{'perl_debug'}
Truth table0%0/2
A
A= $meta_hr->{'perl_debug'}
Aresult
11
00
543 return err('unable to load perl_debug array reference');
544 0 ▶ $self->perl_init($perl_ar, $perl_debug_ar) || return $self->err_html();
Branch: 1 branch
BranchTrueFalseTotal
$self->perl_init($perl_ar, $perl_debug_ar) or return $self->err_html 0 0 0
545 }
546 }
547 }
548  
549  
550 # Done, install into memory cache
551 #
552 3 ▶ if (my $meta_hr=$container_ar->[0] and $cache_inode_hr->{'meta'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $meta_hr = $container_ar->[0] and $cache_inode_hr->{'meta'}) { } 0 3 3
elsif ($meta_hr) { } 3 0 3
Condition33%1/3
my $meta_hr = $container_ar->[0] and $cache_inode_hr->{"meta"}
!ll&&!rl&&r
030
MC/DC0%0/2
my $meta_hr = $container_ar->[0] and $cache_inode_hr->{"meta"}
my $meta_hr = $container_ar->[0] $cache_inode_hr->{"meta"}
Truth table33%1/3
A and B
A= my $meta_hr = $container_ar->[0]B= $cache_inode_hr->{"meta"}
ABresult
0X0
100
111
553  
554 # Need to merge meta info
555 #
556 0 ▶ foreach (keys %{$meta_hr}) {$cache_inode_hr->{'meta'}{$_} ||= $meta_hr->{$_}}
Condition0%0/3
$cache_inode_hr->{"meta"}{$_} ||= $meta_hr->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$cache_inode_hr->{"meta"}{$_} ||= $meta_hr->{$_}
$cache_inode_hr->{"meta"}{$_} $meta_hr->{$_}
Truth table0%0/3
A ||= B
A= $cache_inode_hr->{"meta"}{$_}B= $meta_hr->{$_}
ABresult
1X1
011
000
557  
558 }
559 elsif ($meta_hr) {
560  
561 # No merge - just use from container
562 #
563 3 $cache_inode_hr->{'meta'}=$meta_hr;
564  
565 }
566 3 $cache_inode_hr->{'data'}=$container_ar->[1];
567  
568 # Corner case. Delete _CGI if WEBDYNE_CGI_EXPAND_PARAM set to force re-read of
569 # CGI params in case was set in <perl> section - which means would not be seen
570 # early enough. Will only happen after first compile, so no major performance
571 # impact on CGI object recreation
572 #
573 # Update: Re-init rather than delete or WebDyne::State worn't work
574 #
575 # delete $self->{'_CGI'} if $WEBDYNE_CGI_PARAM_EXPAND;
576 #
577
578 # More problems with this. Caused CGI params to disappear when cache subroutine from WebDyne::Cache
579 # triggered loop. Do I need to do it anymore ? Commenting out but retaining for ref
580 #
581 ##if ((my $cgi_or=$self->{'_CGI'}) && WEBDYNE_CGI_PARAM_EXPAND) {
582 ## $cgi_or->delete_all(); # Added this after cache code issues so don't get two instances of param. Keep and eye for problems with WebDyne::State
583 ## $cgi_or->_initialize();
584 ##}
585  
586  
587 }
588 else {
589  
590 5 debug('no compile or disk cache fetch needed - getting from memory cache');
591  
592 }
593  
594  
595 # Separate meta and actual data into separate vars for ease of use
596 #
597 8 my ($meta_hr, $data_ar)=@{$cache_inode_hr}{qw(meta data)};
598 8 debug('meta_hr %s, ', Dumper($meta_hr));
599  
600 # Load page-declared dependencies before dispatching async handlers
601 #
602 8 ▶ if (my $require_fn=$meta_hr->{'require'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $require_fn = $meta_hr->{"require"}) 0 8 8
603 0 local @INC=(@INC, $self->cwd());
604 0 ▶ $self->eval_require($require_fn, $meta_hr) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->eval_require($require_fn, $meta_hr) or return err() 0 0 0
605 return err();
606 }
607
608
609 # Custom handler ?
610 #
611 8 ▶ if (my $handler_ar=$meta_hr->{'handler'} || $r->dir_config('WebDyneHandler')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler_ar = $meta_hr->{"handler"} || $r->dir_config("WebDyneHandler")) 0 8 8
Condition33%1/3
$meta_hr->{'handler'} || $r->dir_config('WebDyneHandler')
l!l&&r!l&&!r
008
MC/DC0%0/2
$meta_hr->{'handler'} || $r->dir_config('WebDyneHandler')
$meta_hr->{'handler'} $r->dir_config('WebDyneHandler')
Truth table33%1/3
A || B
A= $meta_hr->{'handler'}B= $r->dir_config('WebDyneHandler')
ABresult
1X1
011
000
612 0 debug('handler_ar: %s, dir_config: %s', Dumper(\$handler_ar, $r->dir_config('WebDyneHandler')));
613 0 ▶ my ($handler, $handler_param_hr)=ref($handler_ar) ? @{$handler_ar} : $handler_ar;
Branch: 1 branch
BranchTrueFalseTotal
ref $handler_ar ? : 0 0 0
614 0 ▶ if (ref($self) ne $handler) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne $handler) 0 0 0
615 0 debug("passing to custom handler '$handler', param %s", Dumper($handler_param_hr));
616 0 ▶ unless ($Package{'_handler_load'}{$handler}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($WebDyne::Package{"_handler_load"}{$handler}) 0 0 0
617 0 debug("need to load handler '$handler' - trying");
618 0 (my $handler_fn=$handler)=~s/::/\//g;
619 0 $handler_fn.='.pm';
620 0 ▶ eval {require $handler_fn} ||
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $handler_fn } } or return $self->err_html("unable to load custom handler '${handler}', $@") 0 0 0
621 return $self->err_html("unable to load custom handler '$handler', $@");
622 0 ▶ UNIVERSAL::can($handler, 'handler') ||
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::can($handler, "handler") or return $self->err_html("custom handler '${handler}' does not seem to have a 'handler' method to call") 0 0 0
623 return $self->err_html("custom handler '$handler' does not seem to have a 'handler' method to call");
624 0 debug('loaded OK');
625 0 $Package{'_handler_load'}{$handler}++;
626 }
627 0 my %handler_param_hr=(%{$param_hr}, %{$handler_param_hr}, meta => $meta_hr);
628 0 bless $self, $handler;
629  
630 # Force recalc of inode in next handler so recompile done
631 0 delete $self->{'_inode'};
632  
633 # Add meta-data. Something inefficient here, why supplying as handler param and
634 # self attrib ? If don't do it Fake/FastCGI request handler breaks but Apache does
635 # not ?
636 0 $self->{'_meta_hr'}=$meta_hr;
637 0 return &{"${handler}::handler"}($self, $r, \%handler_param_hr);
638 }
639 }
640  
641  
642 # SSE ?
643 #
644 8 if (WEBDYNE_PAGI && ($r->{'scope'}->{'type'} eq 'sse') && (my $sse=($self->{'_sse'} || $meta_hr->{'sse'}))) {
645 my $sse_cr=&eval_cr($srce_inode, \"&${sse}");
646 my $cgi_or=$self->{'_CGI'} || $self->CGI();
647 my $param_hr=$cgi_or->Vars();
648 0 ▶ $r->custom_response(HTTP_CONTINUE, sub { $sse_cr->($self, $param_hr) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
649 return HTTP_CONTINUE
650 }
651  
652  
653 # WebSockets under PAGI ?
654 #
655 8 if (
656 WEBDYNE_PAGI
657 && ($r->{'scope'}->{'type'} =~ /^(?:ws|websocket)$/)
658 && (my $ws=($self->{'_ws'} || $meta_hr->{'ws'}))
659 ) {
660 my $ws_cr=&eval_cr($srce_inode, \"&${ws}");
661 my $cgi_or=$self->{'_CGI'} || $self->CGI();
662 my $param_hr=$cgi_or->Vars();
663 0 ▶ $r->custom_response(HTTP_CONTINUE, sub { $ws_cr->($self, $param_hr) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
664 return HTTP_CONTINUE
665 }
666  
667  
668 # Contain cache code ?
669 #
670 8 ▶ if ((my $cache=($self->{'_cache'} || $meta_hr->{'cache'})) && !$self->{'_cache_run_fg'}++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cache = $self->{'_cache'} || $meta_hr->{'cache'} and not $self->{'_cache_run_fg'}++) { } 0 8 8
Condition33%2/6
my $cache = $self->{"_cache"} || $meta_hr->{"cache"} and not $self->{"_cache_run_fg"}++
!ll&&!rl&&r
800
$self->{'_cache'} || $meta_hr->{'cache'}
l!l&&r!l&&!r
008
MC/DC0%0/3
my $cache = $self->{"_cache"} || $meta_hr->{"cache"} and not $self->{"_cache_run_fg"}++
$self->{'_cache'} $meta_hr->{'cache'} not $self->{"_cache_run_fg"}++
Truth table20%1/5
A || B and not(C)
A= $self->{'_cache'}B= $meta_hr->{'cache'}C= not $self->{"_cache_run_fg"}++
ABCresult
00X0
1X00
0100
1X11
0111
671 0 debug("found cache routine $cache, adding to inode $srce_inode");
672 0 my $cache_inode;
673 0 my $eval_cr=$Package{'_eval_cr'}{'!'};
674 0 ▶ if (ref($cache) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cache eq 'CODE') { } 0 0 0
675 0 debug('CODE cache ref type');
676 0 my %param=(
677 cache_cr => $cache,
678 srce_inode => $srce_inode
679 );
680
681 # Use to take return of cache code as inode but not obvious. Now force user to run $self->inode(<something>) in cache
682 # code to set. Keep here as reminder though.
683 #
684 #$cache_inode=${
685
686 # OK - what does this do ? It calls the cache code ref in the document via the eval_cr code execution
687 # routine which is supplied as follows
688 #
689 # $_[0] = self (instance) ref
690 # $_[1] = r (request ref)
691 # $_[2] = CGI (CGI ref)
692 # $_[3] = \%param above
693 #
694 # And we are executing code '$_[3]->{'cache_cr'}->($_[0], $_[3]->{'srce_inode'}', so
695 # $cache->($self, $srce_inode)
696 #
697 # Change mind - back to not supplying r, CGI as standard. User can request
698 #
699 ##$eval_cr->($self, undef, \%param, q[$_[3]->{'cache_cr'}->($_[0], $_[3]->{'srce_inode'})], 0) ||
700 #
701 # Before we added r,CGI as params for eval_cr it looked like this
702 #
703 #$eval_cr->($self, undef, \%param, q[$_[1]->{'cache_cr'}->($_[0], $_[1]->{'srce_inode'})], 0) ||
704 0 ▶ $eval_cr->($self, undef, \%param, q[$_[1]->{'cache_cr'}->($_[0], $_[1]->{'srce_inode'})], 0) ||
Branch: 1 branch
BranchTrueFalseTotal
&$eval_cr($self, undef, \%param, "\$_[1]->{'cache_cr'}->(\$_[0], \$_[1]->{'srce_inode'})", 0) or return $self->err_html(errsubst("error in cache code: %s", errstr() || $@ || "no inode returned")) 0 0 0
Condition0%0/5
errstr() || $@ || 'no inode returned'
l!l
00
errstr() or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
errstr() || $@ || 'no inode returned'
errstr() $@
Truth table0%0/3
A or B
A= errstr()B= $@
ABresult
1X1
011
000
705 return $self->err_html(
706 errsubst(
707 'error in cache code: %s', errstr() || $@ || 'no inode returned'
708 ));
709 #}
710 }
711 else {
712
713 # See above. Same rationale
714 #
715 #$cache_inode=${
716 0 debug('non-CODE cache type');
717 0 ▶ $eval_cr->($self, undef, $srce_inode, $cache, 0) ||
Branch: 1 branch
BranchTrueFalseTotal
&$eval_cr($self, undef, $srce_inode, $cache, 0) or return $self->err_html(errsubst("error in cache code: %s", errstr() || $@ || "no inode returned")) 0 0 0
Condition0%0/5
errstr() || $@ || 'no inode returned'
l!l
00
errstr() or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
errstr() || $@ || 'no inode returned'
errstr() $@
Truth table0%0/3
A or B
A= errstr()B= $@
ABresult
1X1
011
000
718 return $self->err_html(
719 errsubst(
720 'error in cache code: %s', errstr() || $@ || 'no inode returned'
721 ));
722 #}
723 }
724 #$cache_inode=$cache_inode ? md5_hex($srce_inode, $cache_inode) : $self->{'_inode'};
725 0 $cache_inode=$self->{'_inode'};
726  
727 # Will probably make inodes with algorithm below some day so we can implement a "maxfiles type limit on
728 # the number of cache files generated. Not today though ..
729 #
730 #$cache_inode=$cache_inode ? $srce_inode .'_'. md5_hex($cache_inode) : $self->{'_inode'};
731 0 debug("cache inode $cache_inode, compile %s", $self->{'_compile'});
732  
733 0 ▶ if (($cache_inode ne $srce_inode) || $self->{'_compile'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_inode ne $srce_inode or $self->{'_compile'}) { } 0 0 0
Condition0%0/3
$cache_inode ne $srce_inode or $self->{"_compile"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$cache_inode ne $srce_inode or $self->{"_compile"}
$cache_inode ne $srce_inode $self->{"_compile"}
Truth table0%0/3
A or B
A= $cache_inode ne $srce_inodeB= $self->{"_compile"}
ABresult
1X1
011
000
734  
735 # Using a cache file, different inode.
736 #
737 0 ▶ debug("goto RENDER_BEGIN, inode node was $srce_inode, now $cache_inode, _compile: %s", $self->{'_compile'} || 0 );
Condition0%0/2
$self->{'_compile'} || 0
l!l
00
MC/DC0%0/1
$self->{'_compile'} || 0
$self->{'_compile'}
Truth table0%0/2
A
A= $self->{'_compile'}
Aresult
11
00
738 0 goto RENDER_BEGIN;
739 #return &handler($self,$r,$param_hr); #should work instead of goto for pendants
740  
741 }
742 else {
743
744 # Same inode, nothing to do.
745 #
746 0 debug('inode not changed, proceeding');
747
748 }
749  
750 }
751 else {
752
753 # No cache code to run
754 #
755 8 debug('not running cache code');
756
757 }
758
759
760 # Is it plain HTML which can be/is pre-rendered and stored on disk ? Note to self, leave here - should
761 # run after any cache code is run, as that may change inode.
762 #
763 8 my $html_sr;
764 8 ▶ if ($self->{'_static'} || ($meta_hr && ($meta_hr->{'html'} || $meta_hr->{'static'}))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_static'} or $meta_hr and $meta_hr->{'html'} || $meta_hr->{'static'}) { } 0 8 8
Condition33%3/9
$self->{"_static"} or $meta_hr and $meta_hr->{"html"} || $meta_hr->{"static"}
l!l&&r!l&&!r
008
$meta_hr and $meta_hr->{"html"} || $meta_hr->{"static"}
!ll&&!rl&&r
080
$meta_hr->{"html"} or $meta_hr->{"static"}
l!l&&r!l&&!r
008
MC/DC0%0/4
$self->{"_static"} or $meta_hr and $meta_hr->{"html"} || $meta_hr->{"static"}
$self->{"_static"} $meta_hr $meta_hr->{"html"} $meta_hr->{"static"}
Truth table20%1/5
A or B and C or D
A= $self->{"_static"}B= $meta_hrC= $meta_hr->{"html"}D= $meta_hr->{"static"}
ABCDresult
1XXX1
011X1
01011
00XX0
01000
765
766
767 # It's flagged static, passed first hurdle. We might need to save away - but only if we're not a
768 # child handler. $r->main() gives undef if we *are* the main request handler.
769 #
770 # Remove test for main child handler but keep as reminder
771 #
772 #if (! $r->main()) {
773  
774 # We are the main request handler. So process
775 #
776 0 debug("static flag detected, in main handler, looking for cache_pn: $cache_pn");
777 0 ▶ my $fn=$cache_pn ? "${cache_pn}.html" : undef;
Branch: 1 branch
BranchTrueFalseTotal
$cache_pn ? : 0 0 0
778 0 my $html_mtime;
779 0 ▶ if ($fn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fn) 0 0 0
780  
781 # Same stat policy as the compiled disk cache above. Keep this as
782 # a single cached-result test so the TTL and never-check modes use
783 # the same path, and so negative TTL avoids both stat() and time().
784 #
785 0 my $cache_stat_ttl=WEBDYNE_CACHE_STAT_TTL;
786 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_stat_ttl and $cache_inode_hr->{'html_stat_set'} and $cache_stat_ttl < 0 || &WebDyne::time() - $cache_inode_hr->{'html_stat_time'} < $cache_stat_ttl) { } 0 0 0
Condition0%0/9
$cache_stat_ttl and $cache_inode_hr->{"html_stat_set"} and $cache_stat_ttl < 0 || &WebDyne::time() - $cache_inode_hr->{"html_stat_time"} < $cache_stat_ttl
!ll&&!rl&&r
000
$cache_stat_ttl and $cache_inode_hr->{"html_stat_set"}
!ll&&!rl&&r
000
$cache_stat_ttl < 0 or &WebDyne::time() - $cache_inode_hr->{"html_stat_time"} < $cache_stat_ttl
l!l&&r!l&&!r
000
MC/DC0%0/4
$cache_stat_ttl and $cache_inode_hr->{"html_stat_set"} and $cache_stat_ttl < 0 || &WebDyne::time() - $cache_inode_hr->{"html_stat_time"} < $cache_stat_ttl
$cache_stat_ttl $cache_inode_hr->{"html_stat_set"} $cache_stat_ttl < 0 &WebDyne::time() - $cache_inode_hr->{"html_stat_time"} < $cache_stat_ttl
Truth table0%0/5
A and B and C or D
A= $cache_stat_ttlB= $cache_inode_hr->{"html_stat_set"}C= $cache_stat_ttl < 0D= &WebDyne::time() - $cache_inode_hr->{"html_stat_time"} < $cache_stat_ttl
ABCDresult
0XXX0
10XX0
11000
111X1
11011
787 $cache_stat_ttl
788 && $cache_inode_hr->{'html_stat_set'}
789 && (
790 ($cache_stat_ttl < 0)
791 || ((time() - $cache_inode_hr->{'html_stat_time'}) < $cache_stat_ttl)
792 )
793 ) {
794 0 $html_mtime=$cache_inode_hr->{'html_stat_mtime'};
795 }
796 else {
797 0 ▶ $html_mtime=((-f $fn) && (stat(_))[9]);
Condition0%0/3
-f $fn && (stat _)[9]
!ll&&!rl&&r
000
MC/DC0%0/2
-f $fn && (stat _)[9]
-f $fn (stat _)[9]
Truth table0%0/3
A && B
A= -f $fnB= (stat _)[9]
ABresult
0X0
100
111
798 0 ▶ if ($cache_stat_ttl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_stat_ttl) 0 0 0
799 0 $cache_inode_hr->{'html_stat_set'}=1;
800 0 ▶ $cache_inode_hr->{'html_stat_time'}=time() if ($cache_stat_ttl > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $cache_stat_ttl > 0 0 0 0
801 0 $cache_inode_hr->{'html_stat_mtime'}=$html_mtime;
802 }
803 }
804 }
805 0 ▶ if ($fn && $html_mtime && ($html_mtime >= $srce_mtime) && !$self->{'_compile'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fn and $html_mtime and $html_mtime >= $srce_mtime and not $self->{'_compile'}) { } 0 0 0
elsif ($cache_pn) { } 0 0 0
Condition0%0/9
$fn and $html_mtime and $html_mtime >= $srce_mtime and not $self->{"_compile"}
!ll&&!rl&&r
000
$fn and $html_mtime and $html_mtime >= $srce_mtime
!ll&&!rl&&r
000
$fn and $html_mtime
!ll&&!rl&&r
000
MC/DC0%0/4
$fn and $html_mtime and $html_mtime >= $srce_mtime and not $self->{"_compile"}
$fn $html_mtime $html_mtime >= $srce_mtime not $self->{"_compile"}
Truth table0%0/5
A and B and C and not(D)
A= $fnB= $html_mtimeC= $html_mtime >= $srce_mtimeD= not $self->{"_compile"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
806  
807 # Cache file exists, and is not stale, and user/cache code does not want a recompile. Tell Apache or FCGI
808 # to serve it up directly.
809 #
810 0 debug("returning pre-rendered file ${cache_pn}.html");
811 0 ▶ unless($MOD_PERL && !$MP2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WebDyne::MOD_PERL and not $WebDyne::MP2) { } 0 0 0
Condition0%0/3
$WebDyne::MOD_PERL and not $WebDyne::MP2
!ll&&!rl&&r
000
MC/DC0%0/2
$WebDyne::MOD_PERL and not $WebDyne::MP2
$WebDyne::MOD_PERL not $WebDyne::MP2
Truth table0%0/3
A and not(B)
A= $WebDyne::MOD_PERLB= not $WebDyne::MP2
ABresult
0X0
100
111
812 #if ($MP2 || $ENV{'FCGI_ROLE'} || $ENV{'psgi.version'}) {
813  
814 # Do this way for mod_perl2, FCGI. Note to self need r->output_filter or
815 # Apache 2 seems to add junk characters at end of output
816 #
817 0 debug('using MP2 or FCGI_ROLE path');
818 0 ▶ my $r_child=$r->lookup_file($fn, $r->output_filters) ||
Condition0%0/2
$r->lookup_file($fn, $r->output_filters) || (return err())
l!l
00
MC/DC0%0/1
$r->lookup_file($fn, $r->output_filters) || (return err())
$r->lookup_file($fn, $r->output_filters)
Truth table0%0/2
A
A= $r->lookup_file($fn, $r->output_filters)
Aresult
11
00
819 return err();
820 0 debug("r_child: $r_child, self: $self");
821 0 $r_child->handler('default-handler');
822 0 $r_child->content_type(WEBDYNE_CONTENT_TYPE_HTML);
823  
824 # Apache bug ? Need to set content type on r also
825 0 $r->content_type(WEBDYNE_CONTENT_TYPE_HTML);
826 0 debug("set content type to: $WEBDYNE_CONTENT_TYPE_HTML, running");
827 #return $r_child->run($self);
828 0 return $r_child->run();
829  
830  
831 }
832 else {
833  
834 # This way for older versions of Apache, other request handlers
835 #
836 0 debug('using legacy path');
837 0 $r->filename($fn);
838 0 $r->handler('default-handler');
839 0 $r->content_type(WEBDYNE_CONTENT_TYPE_HTML);
840 0 ▶ return $MP2 ? &Apache::DECLINED : $r->status(HTTP_NOT_FOUND);;
Branch: 1 branch
BranchTrueFalseTotal
$WebDyne::MP2 ? : 0 0 0
841 }
842 }
843 elsif ($cache_pn) {
844  
845 # Cache file defined, but out of date of non-existant. Register callback handler to write HTML output
846 # after render complete
847 #
848 0 debug("storing inode: %s to disk file: ${cache_pn}.html, cache html %s", $self->{'_inode'}, \$data_ar->[0]);
849 my $cr=set_subname('cache_disk_writeback_anon', sub {
850 &cache_html(
851 0 ▶ "${cache_pn}.html", ($meta_hr->{'static'} || $self->{'_static'}) ? $html_sr : \$data_ar->[0])
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
$meta_hr->{'static'} || $self->{'_static'} ? : 0 0 0
Condition0%0/3
$meta_hr->{"static"} or $self->{"_static"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$meta_hr->{"static"} or $self->{"_static"}
$meta_hr->{"static"} $self->{"_static"}
Truth table0%0/3
A or B
A= $meta_hr->{"static"}B= $self->{"_static"}
ABresult
1X1
011
000
852 0 });
853 0 ▶ $MP2 ? $r->pool->cleanup_register($cr) : $r->register_cleanup($cr);
Branch: 1 branch
BranchTrueFalseTotal
$WebDyne::MP2 ? : 0 0 0
854 }
855 else {
856  
857 # No cache directory, store in memory cache. Each apache process will get a different version, but will
858 # at least still be only compiled once for each version.
859 #
860 0 debug('storing to memory cache html %s', \$data_ar->[0]);
861 my $cr=set_subname('cache_mem_writeback_anon', sub {
862 $cache_inode_hr->{'data'}=[
863 0 ▶ ($meta_hr->{'static'} || $self->{'_static'}) ? ${$html_sr} : $data_ar->[0]]
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
$meta_hr->{'static'} || $self->{'_static'} ? : 0 0 0
Condition0%0/3
$meta_hr->{"static"} or $self->{"_static"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$meta_hr->{"static"} or $self->{"_static"}
$meta_hr->{"static"} $self->{"_static"}
Truth table0%0/3
A or B
A= $meta_hr->{"static"}B= $self->{"_static"}
ABresult
1X1
011
000
864 0 });
865 0 ▶ $MP2 ? $r->pool->cleanup_register($cr) : $r->register_cleanup($cr);
Branch: 1 branch
BranchTrueFalseTotal
$WebDyne::MP2 ? : 0 0 0
866 }
867  
868 #}
869 #else {
870 # debug('in child handler, not saving');
871 #}
872  
873 }
874 else {
875
876 8 debug('not static code, not saving to cache or serving');
877
878 }
879 #die if ($param_hr->{'count'}==2);
880  
881  
882 # Debug
883 #
884 8 debug('about to render');
885  
886  
887 # Set default content type to text/html, can be overridden by render code if needed
888 #
889 8 $r->content_type(WEBDYNE_CONTENT_TYPE_HTML);
890  
891  
892 # Redirect 'print' function to our own routine for later output
893 #
894 8 ▶ my $select=($self->{'_select'} ||= CORE::select());
Condition33%1/3
$self->{"_select"} ||= CORE::select
l!l&&r!l&&!r
080
MC/DC0%0/2
$self->{"_select"} ||= CORE::select
$self->{"_select"} CORE::select
Truth table33%1/3
A ||= B
A= $self->{"_select"}B= CORE::select
ABresult
1X1
011
000
895 8 debug("select handle is currently $select, changing to *WEBDYNE");
896 8 ▶ tie(*WEBDYNE, 'WebDyne::TieHandle', $self) ||
Branch: 1 branch
BranchTrueFalseTotal
tie *WEBDYNE, "WebDyne::TieHandle", $self or return $self->err_html("unable to tie output to 'WebDyne::TieHandle', $!") 0 8 8
897 return $self->err_html("unable to tie output to 'WebDyne::TieHandle', $!");
898 8 ▶ CORE::select WEBDYNE if $select;
Branch: 1 branch
BranchTrueFalseTotal
if $select 8 0 8
899  
900  
901 # Get the actual html. The main event - convert data_ar to html
902 #
903 8 ▶ $html_sr=$self->render_data_ar(data => $data_ar, param => $param_hr) || do {
Condition33%1/3
$self->render_data_ar('data', $data_ar, 'param', $param_hr) || do { RENDER_ERROR: debug("render error $r, select $select"); debug("selecting back to $select for error"); CORE::select $select if $select; untie *WEBDYNE; return $self->err_html }
l!l&&r!l&&!r
600
MC/DC0%0/2
$self->render_data_ar('data', $data_ar, 'param', $param_hr) || do { RENDER_ERROR: debug("render error $r, select $select"); debug("selecting back to $select for error"); CORE::select $select if $select; untie *WEBDYNE; return $self->err_html }
$self->render_data_ar('data', $data_ar, 'param', $param_hr) do { RENDER_ERROR: debug("render error $r, select $select"); debug("selecting back to $select for error"); CORE::select $select if $select; untie *WEBDYNE; return $self->err_html }
Truth table33%1/3
A || B
A= $self->render_data_ar('data', $data_ar, 'param', $param_hr)B= do { RENDER_ERROR: debug("render error $r, select $select"); debug("selecting back to $select for error"); CORE::select $select if $select; untie *WEBDYNE; return $self->err_html }
ABresult
1X1
011
000
904  
905  
906 # Our render routine returned an error. Debug
907 #
908 0 RENDER_ERROR:
909 debug("render error $r, select $select");
910  
911  
912 # Return error
913 #
914 0 debug("selecting back to $select for error");
915 0 ▶ CORE::select $select if $select;
Branch: 1 branch
BranchTrueFalseTotal
if $select 0 0 0
916 0 untie *WEBDYNE;
917 0 return $self->err_html();
918  
919  
920 };
921  
922  
923 # Done with STDOUT redirect
924 #
925 6 debug("selecting back to $select");
926 6 ▶ CORE::select $select if $select;
Branch: 1 branch
BranchTrueFalseTotal
if $select 6 0 6
927 6 untie *WEBDYNE;
928  
929  
930 # Check for any unhandled errors during render - render may have returned OK, but
931 # maybe an error occurred along the way that was not passed back ..
932 #
933 6 debug('errstr after render %s', errstr());
934 6 ▶ errstr() && return $self->err_html();
Branch: 1 branch
BranchTrueFalseTotal
errstr() and return $self->err_html 0 6 6
935 6 ▶ &CGI::Simple::cgi_error() && return $self->err_html(&CGI::Simple::cgi_error());
Branch: 1 branch
BranchTrueFalseTotal
&CGI::Simple::cgi_error() and return $self->err_html(&CGI::Simple::cgi_error()) 0 6 6
936  
937  
938 # Check for any blocks that user wanted rendered but were
939 # not present anywhere
940 #
941 #if ($WEBDYNE_DELAYED_BLOCK_RENDER && (my $block_param_hr=delete $self->{'_block_param'})) {
942 6 ▶ if (my $block_param_hr=delete $self->{'_block_param'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $block_param_hr = delete $self->{"_block_param"}) 0 6 6
943 0 my @block_error;
944 0 foreach my $block_name (keys %{$block_param_hr}) {
945 0 ▶ unless (exists $self->{'_block_render'}{$block_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_block_render"}{$block_name}) 0 0 0
946 0 push @block_error, $block_name;
947 }
948 }
949 0 ▶ if (@block_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (@block_error) 0 0 0
950 0 debug('found un-rendered blocks %s', Dumper(\@block_error));
951 return $self->err_html(
952 0 err('unable to locate block(s) %s for render', join(', ', map {"'$_'"} @block_error)))
953 }
954 }
955  
956  
957 # If no error, status must be ok unless otherwise set
958 #
959 6 ▶ $r->status(HTTP_OK) unless $r->status();
Branch: 1 branch
BranchTrueFalseTotal
unless $r->status 0 6 6
960 6 debug('r status set, %s', $r->status());
961
962
963 # Tidy ? Run under eval in case module not installed/working, considerd non-fatal. Note
964 # use of folding contstant and variable - lets it be turned on in wdrender via folding
965 # constant, then toggled off by options if not wanted
966 #
967 #
968 6 if (WEBDYNE_HTML_TIDY && $param_hr->{'tidy'}) {
969 eval {
970 require HTML::Tidy5;
971 my $html=HTML::Tidy5->new($WEBDYNE_HTML_TIDY_CONFIG_HR)->clean(${$html_sr});
972 $html_sr=\$html;
973 };
974 $@ && eval {};
975 }
976  
977  
978 # Formulate header, calc length of return.
979 #
980 # Modify to remove error checking - WebDyne::FakeRequest does not supply
981 # hash ref, so error generated. No real need to check
982 #
983 6 my $header_out_hr=$r->headers_out(); # || return err();
984 my %header_out=(
985  
986 6 'Content-Length' => length ${$html_sr},
987 #($meta_hr->{'no_cache'} || $WEBDYNE_NO_CACHE) && (
988 # 'Cache-Control' => 'no-cache',
989 # 'Pragma' => 'no-cache',
990 # 'Expires' => '-5'
991 # )
992 6 %{$WEBDYNE_HTTP_HEADER}
993  
994 );
995 6 debug('header_out_hr: %s', Dumper($header_out_hr));
996 6 foreach (keys %header_out) {$r->headers_out($_ => $header_out{$_})}
997  
998  
999 # Debug
1000 #
1001 6 debug("sending header: $r");
1002  
1003  
1004 # Send header
1005 #
1006 6 ▶ $r->send_http_header() if !$MP2;
Branch: 1 branch
BranchTrueFalseTotal
unless $WebDyne::MP2 6 0 6
1007  
1008  
1009 # Print. Commented out version only seems to work in Apache 1/mod_perl1
1010 #
1011 #$r->print($html_sr);
1012 6 ▶ $MP2 ? $r->print(${$html_sr}) : $r->print($html_sr);
Branch: 1 branch
BranchTrueFalseTotal
$WebDyne::MP2 ? : 0 6 6
1013  
1014  
1015 # Work out the form render time, log
1016 #
1017 8 RENDER_COMPLETE:
1018 my $time_render=sprintf('%0.4f', time()-$time);
1019 8 debug("form $srce_pn render time $time_render");
1020  
1021  
1022 # Do we need to do house cleaning on cache after this run ? If so
1023 # add a perl handler to do it after we finish
1024 #
1025 8 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($r eq ($r->main || $r) and not +(my $nrun = ++$WebDyne::Package{'_nrun'}) % 256) { } 0 8 8
Condition33%2/6
$r eq ($r->main || $r) and not +(my $nrun = ++$WebDyne::Package{"_nrun"}) % 256
!ll&&!rl&&r
080
$r->main || $r
l!l&&r!l&&!r
080
MC/DC0%0/2
$r eq ($r->main || $r) and not +(my $nrun = ++$WebDyne::Package{"_nrun"}) % 256
$r eq ($r->main || $r) not +(my $nrun = ++$WebDyne::Package{"_nrun"}) % 256
MC/DC0%0/2
$r->main || $r
$r->main $r
Truth table33%1/3
A and not(B)
A= $r eq ($r->main || $r)B= not +(my $nrun = ++$WebDyne::Package{"_nrun"}) % 256
ABresult
0X0
100
111
Truth table33%1/3
A || B
A= $r->mainB= $r
ABresult
1X1
011
000
1026 WEBDYNE_CACHE_CHECK_FREQ
1027 &&
1028 ($r eq ($r->main() || $r)) &&
1029 !((my $nrun=++$Package{'_nrun'}) % WEBDYNE_CACHE_CHECK_FREQ)
1030 ) {
1031  
1032  
1033 # Debug
1034 #
1035 0 debug("run $nrun times, scheduling cache clean");
1036  
1037  
1038 # Yes, we need to clean cache after finished
1039 #
1040 0 ▶ my $cr=set_subname('cache_clean_anon', sub {&cache_clean($Package{'_cache'})});
Subroutine __ANON__: not called CC=1 SCAR=6.9
1041 0 ▶ $MP2 ? $r->pool->cleanup_register($cr) : $r->register_cleanup($cr);
Branch: 1 branch
BranchTrueFalseTotal
$WebDyne::MP2 ? : 0 0 0
1042  
1043  
1044 # Used to be sub { $self->cache_clean() }, but for some reason this
1045 # made httpd peg at 100% CPU usage after cleanup. Removing $self ref
1046 # fixed.
1047 #
1048  
1049  
1050 }
1051 elsif (WEBDYNE_CACHE_CHECK_FREQ) {
1052  
1053 # Only bother to update counters if we are checking cache periodically
1054 #
1055  
1056  
1057 # Update cache script frequency used, time used indicators, nrun=number
1058 # of runs, lrun=last run time
1059 #
1060 8 $cache_inode_hr->{'nrun'}++;
1061 8 $cache_inode_hr->{'lrun'}=time();
1062  
1063 }
1064 else {
1065  
1066  
1067 # Debug
1068 #
1069 debug("run $nrun times, no cache check needed");
1070  
1071 }
1072  
1073  
1074 # Debug exit
1075 #
1076 8 debug("handler $r exit status %s, leaving with Apache::OK", $r->status); #, Dumper($self));
1077  
1078  
1079 # Complete
1080 #
1081 8 ▶ HANDLER_COMPLETE:
Branch: 1 branch
BranchTrueFalseTotal
$WebDyne::MP2 ? : 0 8 8
1082 return $MP2 ? &Apache::OK : HTTP_OK;
1083  
1084  
1085 }
1086  
1087  
1088 sub handler_die {
1089  
1090  
1091 # Die signal handler
1092 #
1093 0 ▶ debug('in __DIE__ sig handler, $^S: %s: message: %s, caller %s', $^S, $_[0], join(',', (caller(0))[0..3]));
Subroutine handler_die: not called CC=5 SCAR=34.0
Pod undocumented
1094
1095
1096 # Avoid recursion
1097 #
1098 0 local $SIG{__DIE__};
1099
1100
1101 # Go back through call stack looking for eval errors
1102 #
1103 0 my $i=0;
1104 0 my @eval_nest;
1105 my $eval_nest;
1106 0 ▶ while (my @caller=caller($i++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@caller) = caller $i++) 0 0 0
1107 0 ▶ if ($caller[3] eq '(eval)') {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller[3] eq "(eval)") 0 0 0
1108 0 push @eval_nest, [@caller[0..3]];
1109 #push @eval_nest, \@caller;
1110 0 $eval_nest++;
1111 }
1112 }
1113 0 debug("eval_nest: $eval_nest, eval_nest_ar: %s", Dumper(\@eval_nest));
1114
1115
1116 # Don't error out if not a WebDyne error (i.e. if eval{} block was in module called from
1117 # user code
1118 #
1119 #if ($eval_nest[0][0]!~/^WebDyne::/) {
1120 0 ▶ if ($eval_nest[0][0] !~ /^WebDyne(?:::|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($eval_nest[0][0] =~ /^WebDyne(?:::|$)/) 0 0 0
1121
1122 # Not us, clear eval stack
1123 #
1124 0 debug('eval_nest: %sdid not match WebDyne module, clearning eval error', $eval_nest[0][0] );
1125 0 eval {};
1126 0 return;
1127
1128 }
1129
1130
1131 # If operating under eval and withing a WebDyne::<inode> block call CORE::die;
1132 #
1133 #foreach my $eval_nest_ar (@{$eval_nest}) {
1134 # if ($eval_nest_ar->[0]=~/^WebDyne::[a-f0-9]{32}$/) {
1135 # debug("die with WebDyne::<inode> eval detected, calling CORE::die");
1136 # CORE::die(\@_);
1137 # }
1138 #}
1139
1140  
1141 # Updated to *NOT* throw error if in eval block (i.e. if $@ is set). Stops error handler being called
1142 # if non WebDyne module has eval code which triggers non WebDyne AUTOLOAD block. Might need to be more
1143 # sophisticated and look at traceback for Autoload::AUTOLOAD but another day
1144 0 ▶ return err(@_) unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
1145  
1146 }
1147  
1148  
1149 sub handler_warn {
1150  
1151 # Warn signal handler
1152 #
1153 0 ▶ debug('in __WARN__ sig handler, caller %s', join(',', (caller(0))[0..3]));
Subroutine handler_warn: not called CC=2 SCAR=17.9
Pod undocumented
1154 0 ▶ goto &handler_die if $WEBDYNE_WARNINGS_FATAL;
Branch: 1 branch
BranchTrueFalseTotal
if $WebDyne::WEBDYNE_WARNINGS_FATAL 0 0 0
1155 0 return err(@_)
1156  
1157 }
1158
1159  
1160 sub init {
1161  
1162  
1163 # Clear Package cache and start from scratch
1164 #
1165 4 ▶ undef %Package;
Subroutine init: called CC=15 SCAR=46.6
Pod undocumented
1166  
1167  
1168 # Try to load correct modules depending on Apache ver, taking special care
1169 # with constants. This mess will disappear if we only support MP2
1170 #
1171 4 ▶ if ($MP2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($WebDyne::MP2) { } 0 4 4
elsif ($ENV{'MOD_PERL'}) { } 0 4 4
1172  
1173 0 local $SIG{'__DIE__'};
1174 eval {
1175 #require Apache2;
1176 0 require Apache::Log;
1177 0 require Apache::Response;
1178 0 require Apache::SubRequest;
1179 0 require Apache::Const; Apache::Const->import(-compile => qw(OK DECLINED));
1180 0 require APR::Table;
1181 0 require APR::Pool;
1182 0 ▶ } || eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Apache::Log; require Apache::Response; require Apache::SubRequest; require Apache::Const; "Apache::Const"->import("-compile", ("OK", "DECLINED")); require APR::Table; require APR::Pool } } or eval { do { require Apache2::Log; require Apache2::Response; require Apache2::SubRequest; require Apache2::Const; "Apache2::Const"->import("-compile", ("OK", "DECLINED")); require Apache2::RequestRec; require Apache2::RequestUtil; require Apache2::RequestIO; require APR::Table; require APR::Pool } } 0 0 0
1183 0 require Apache2::Log;
1184 0 require Apache2::Response;
1185 0 require Apache2::SubRequest;
1186 0 require Apache2::Const; Apache2::Const->import(-compile => qw(OK DECLINED));
1187 0 require Apache2::RequestRec;
1188 0 require Apache2::RequestUtil;
1189 0 require Apache2::RequestIO;
1190 0 require APR::Table;
1191 0 require APR::Pool;
1192 };
1193 0 ▶ eval {} if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1194 0 ▶ unless (UNIVERSAL::can('Apache', 'OK')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::can("Apache", "OK")) 0 0 0
1195 0 ▶ if (UNIVERSAL::can('Apache2::Const', 'OK')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::can('Apache2::Const', 'OK')) { } 0 0 0
elsif (UNIVERSAL::can('Apache::Const', 'OK')) { } 0 0 0
1196 0 *Apache::OK=\&Apache2::Const::OK;
1197 0 *Apache::DECLINED=\&Apache2::Const::DECLINED;
1198 }
1199 elsif (UNIVERSAL::can('Apache::Const', 'OK')) {
1200 0 *Apache::OK=\&Apache::Const::OK;
1201 0 *Apache::DECLINED=\&Apache::Const::DECLINED;
1202 }
1203 else {
1204 0 ▶ *Apache::OK=sub {0}
Subroutine __ANON__: not called CC=1 SCAR=6.9
1205 0 ▶ unless defined &Apache::OK;
Branch: 1 branch
BranchTrueFalseTotal
unless defined &Apache::OK 0 0 0
1206 0 ▶ *Apache::DECLINED=sub {-1}
Subroutine __ANON__: not called CC=1 SCAR=6.9
1207 0 ▶ unless defined &Apache::DECLINED;
Branch: 1 branch
BranchTrueFalseTotal
unless defined &Apache::DECLINED 0 0 0
1208 }
1209 }
1210 }
1211 elsif ($ENV{'MOD_PERL'}) {
1212  
1213 0 local $SIG{'__DIE__'};
1214 eval {
1215 0 require Apache::Constants; Apache::Constants->import(qw(OK DECLINED));
1216 0 *Apache::OK=\&Apache::Constants::OK;
1217 0 *Apache::DECLINED=\&Apache::Constants::DECLINED;
1218 0 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Apache::Constants; "Apache::Constants"->import("OK", "DECLINED"); *Apache::OK = \&Apache::Constants::OK; *Apache::DECLINED = \&Apache::Constants::DECLINED } } or do { *Apache::OK = sub { 0; } } 0 0 0
1219 0 ▶ *Apache::OK=sub {0}
Subroutine __ANON__: not called CC=1 SCAR=6.9
1220 0 };
1221 0 ▶ eval {} if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1222 }
1223 else {
1224  
1225 4 ▶ *Apache::OK=sub {0};
Subroutine __ANON__: not called CC=1 SCAR=1.2
1226 4 ▶ *Apache::DECLINED=sub {-1};
Subroutine __ANON__: not called CC=1 SCAR=1.2
1227  
1228 }
1229  
1230  
1231 # If set, delete all old cache files at startup
1232 #
1233 4 ▶ if (WEBDYNE_STARTUP_CACHE_FLUSH && (-d WEBDYNE_CACHE_DN)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "") 0 4 4
1234 0 my @file_cn=glob(File::Spec->catfile(WEBDYNE_CACHE_DN, '*'));
1235 0 foreach my $fn (grep {/\w{32}(\.html)?$/} @file_cn) {
1236 0 unlink $fn; #don't error here if problems, user will never see it
1237 }
1238 }
1239  
1240  
1241 # Make all errors non-fatal
1242 #
1243 4 errnofatal(1);
1244  
1245  
1246 # Alias request method to just 'r' also
1247 #
1248 4 ▶ *WebDyne::r=\&WebDyne::request || *WebDyne::r;
Condition33%1/3
\&WebDyne::request || *r
l!l&&r!l&&!r
400
MC/DC0%0/2
\&WebDyne::request || *r
\&WebDyne::request *r
Truth table33%1/3
A || B
A= \&WebDyne::requestB= *r
ABresult
1X1
011
000
1249  
1250  
1251 # Eval routine for eval'ing perl code in a non-safe way (ie hostile
1252 # code could probably easily subvert us, as all operations are
1253 # allowed, including redefining our subroutines etc).
1254 #
1255 my $eval_perl_cr=set_subname('eval_perl_cr_anon', sub {
1256  
1257  
1258 # Get self ref
1259 #
1260 8 ▶ my ($self, $data_ar, $eval_param_hr, $eval_text, $index, $tag_fg)=@_;
Subroutine __ANON__: called CC=17 SCAR=37.8
1261 8 $eval_text=decode_entities($eval_text);
1262
1263
1264 # Debug
1265 #
1266 8 debug("self: $self, data_ar: $data_ar, eval_param_hr: %s, eval_text: %s, index: $index, tag_fg: $tag_fg", Dumper($eval_param_hr, \$eval_text));
1267 8 debug('caller: %s', Dumper([(caller(0))[0..3]]));
1268  
1269  
1270 # Debug
1271 #
1272 #my $inode=$self->{'_inode'} || 'ANON'; # Was ANON but caused nasty test errors because of memory collisions after many iterations Anon used when no inode present, eg wdcompile
1273 8 ▶ my $inode=$self->{'_inode'} || $self->inode();
Condition33%1/3
$self->{'_inode'} || $self->inode
l!l&&r!l&&!r
800
MC/DC0%0/2
$self->{'_inode'} || $self->inode
$self->{'_inode'} $self->inode
Truth table33%1/3
A || B
A= $self->{'_inode'}B= $self->inode
ABresult
1X1
011
000
1274 8 my $html_line_no=$data_ar->[WEBDYNE_NODE_LINE_IX];
1275  
1276  
1277 # Get CGI vars
1278 #
1279 8 ▶ my $cgi_or=$self->{'_CGI'} || $self->CGI();
Condition33%1/3
$self->{'_CGI'} || $self->CGI
l!l&&r!l&&!r
080
MC/DC0%0/2
$self->{'_CGI'} || $self->CGI
$self->{'_CGI'} $self->CGI
Truth table33%1/3
A || B
A= $self->{'_CGI'}B= $self->CGI
ABresult
1X1
011
000
1280 my $param_hr=(
1281 8 ▶ $self->{'_eval_cgi_hr'} ||= do {
Condition33%1/3
$self->{"_eval_cgi_hr"} ||= do { $cgi_or->Vars }
l!l&&r!l&&!r
080
MC/DC0%0/2
$self->{"_eval_cgi_hr"} ||= do { $cgi_or->Vars }
$self->{"_eval_cgi_hr"} do { $cgi_or->Vars }
Truth table33%1/3
A ||= B
A= $self->{"_eval_cgi_hr"}B= do { $cgi_or->Vars }
ABresult
1X1
011
000
1282 8 $cgi_or->Vars();
1283
1284 }
1285 );
1286 #my $cgi_or;
1287 #my $param_hr;
1288  
1289  
1290 # Only eval subroutine if we have not done already, if need to eval store in
1291 # cache so only done once.
1292 #
1293 8 ▶ my $eval_cr=$Package{'_cache'}{$inode}{'eval_cr'}{$data_ar}{$index} ||= do {
Condition66%2/3
$WebDyne::Package{"_cache"}{$inode}{"eval_cr"}{$data_ar}{$index} ||= do { no strict 'vars'; debug("calling eval sub: $eval_text"); my $sub_cr = &eval_cr($inode, \$eval_text, $html_line_no); if ($@) { my $err = $@; eval { do { () } }; return $self->err_eval("eval of code returned error: $err", \$eval_text, $inode); } elsif (not defined $sub_cr) { return err("eval of code did not return a true value"); } elsif (not ref $sub_cr eq "CODE") { return err("eval of code did not return a code ref"); } ; $sub_cr }
l!l&&r!l&&!r
530
MC/DC0%0/2
$WebDyne::Package{"_cache"}{$inode}{"eval_cr"}{$data_ar}{$index} ||= do { no strict 'vars'; debug("calling eval sub: $eval_text"); my $sub_cr = &eval_cr($inode, \$eval_text, $html_line_no); if ($@) { my $err = $@; eval { do { () } }; return $self->err_eval("eval of code returned error: $err", \$eval_text, $inode); } elsif (not defined $sub_cr) { return err("eval of code did not return a true value"); } elsif (not ref $sub_cr eq "CODE") { return err("eval of code did not return a code ref"); } ; $sub_cr }
$WebDyne::Package{"_cache"}{$inode}{"eval_cr"}{$data_ar}{$index} do { no strict 'vars'; debug("calling eval sub: $eval_text"); my $sub_cr = &eval_cr($inode, \$eval_text, $html_line_no); if ($@) { my $err = $@; eval { do { () } }; return $self->err_eval("eval of code returned error: $err", \$eval_text, $inode); } elsif (not defined $sub_cr) { return err("eval of code did not return a true value"); } elsif (not ref $sub_cr eq "CODE") { return err("eval of code did not return a code ref"); } ; $sub_cr }
Truth table66%2/3
A ||= B
A= $WebDyne::Package{"_cache"}{$inode}{"eval_cr"}{$data_ar}{$index}B= do { no strict 'vars'; debug("calling eval sub: $eval_text"); my $sub_cr = &eval_cr($inode, \$eval_text, $html_line_no); if ($@) { my $err = $@; eval { do { () } }; return $self->err_eval("eval of code returned error: $err", \$eval_text, $inode); } elsif (not defined $sub_cr) { return err("eval of code did not return a true value"); } elsif (not ref $sub_cr eq "CODE") { return err("eval of code did not return a code ref"); } ; $sub_cr }
ABresult
1X1
011
000
1294  
1295 # Why did I do this ? No vars to perl_init so nothing created ?
1296 #
1297 #$Package{'_cache'}{$inode}{'perl_init'}{+undef} ||= $self->perl_init();
1298 3 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1299 3 ▶ no integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
1300 3 debug("calling eval sub: $eval_text");
1301  
1302 # Get code ref. Do this way so run in sub with no access to vars in this scope
1303 #
1304 3 my $sub_cr=&eval_cr($inode, \$eval_text, $html_line_no);
1305 3 ▶ if ($@) {
Branch: 3 branches
BranchTrueFalseTotal
if ($@) { } 0 3 3
elsif (not defined $sub_cr) { } 0 3 3
elsif (not ref $sub_cr eq 'CODE') { } 0 3 3
1306 0 my $err=$@; eval {};
1307  
1308 #return err("eval of code returned error: $err");
1309 0 return $self->err_eval("eval of code returned error: $err", \$eval_text, $inode);
1310 }
1311 elsif (!defined($sub_cr)) {
1312 0 return err("eval of code did not return a true value");
1313 }
1314 elsif (!(ref($sub_cr) eq 'CODE')) {
1315 0 return err("eval of code did not return a code ref");
1316 }
1317  
1318  
1319 # Store code away for error handling. Keep this and next bit to jog memory
1320 #
1321 #$Package{'_cache'}{$inode}{'eval_code'}{$data_ar}{$index}=$eval;
1322  
1323  
1324 # Old way we did it code
1325 #
1326 #eval("package WebDyne::$_[0]; $WebDyne::WEBDYNE_EVAL_USE_STRICT;\n" . "#line $_[2]\n" . "sub{${$_[1]}\n}");
1327 #&eval_cr($inode, \$eval_text, $html_line_no) || return
1328 # $self->err_eval("$@", \$eval_text);
1329  
1330  
1331 # Done
1332 #
1333 3 $sub_cr;
1334  
1335 };
1336  
1337 #debug("eval done, eval_cr $eval_cr");
1338  
1339  
1340 # Run eval
1341 #
1342 8 my @eval;
1343 8 eval {
1344  
1345 # The following line puts all CGI params in %_ during the eval so they are easy to
1346 # get to ..
1347 8 local *_=$param_hr;
1348 8 debug("eval call starting, tag_fg: $tag_fg");
1349  
1350 # Note change here. Now supplying request handler, CGI instanced as standard params to all code calls
1351 #
1352 #@eval=$tag_fg ? $eval_cr->($self, $eval_param_hr) : scalar $eval_cr->($self, $eval_param_hr);[B
1353 #
1354 # Change of mind again. Don't supply r, CGI as standard, let user call for if wanted. Back to original code
1355 #
1356 #@eval=$tag_fg ? $eval_cr->($self, $eval_param_hr) : scalar $eval_cr->($self, $self->{'_r'}, $cgi_or, $eval_param_hr);
1357 8 ▶ @eval=$tag_fg ? $eval_cr->($self, $eval_param_hr) : scalar $eval_cr->($self, $eval_param_hr);
Branch: 1 branch
BranchTrueFalseTotal
$tag_fg ? : 0 8 8
1358 6 debug("eval call complete, $@, %s", Dumper(\@eval));
1359  
1360 };
1361 6 ▶ if (!@eval || $@ || !$eval[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @eval or $@ or not $eval[0]) { } 0 6 6
elsif ($eval[0] eq $self) { } 0 6 6
Condition33%2/6
not @eval or $@ or not $eval[0]
l!l&&r!l&&!r
006
not @eval or $@
l!l&&r!l&&!r
006
MC/DC0%0/3
not @eval or $@ or not $eval[0]
not @eval $@ not $eval[0]
Truth table25%1/4
not(A) or B or not(C)
A= not @evalB= $@C= not $eval[0]
ABCresult
1XX1
01X1
0011
0000
1362  
1363 # An error occurred - handle it and return
1364 #
1365 0 ▶ if (my $err=(errstr() || $@)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = errstr() || $@) { } 0 0 0
Condition0%0/3
errstr() || $@
l!l&&r!l&&!r
000
MC/DC0%0/2
errstr() || $@
errstr() $@
Truth table0%0/3
A || B
A= errstr()B= $@
ABresult
1X1
011
000
1366  
1367 # Eval error or err() called during routine.
1368 #
1369 0 debug("eval error detected: $err");
1370 0 return $self->err_eval($err, \$eval_text, $inode);
1371  
1372 }
1373 else {
1374  
1375 # Some other problem
1376 #
1377 #return err ('code did not return a true value: %s, %s', $eval_text, Dumper(\@eval));
1378  
1379 }
1380  
1381 }
1382 elsif ($eval[0] eq $self) {
1383  
1384  
1385 # $self fell through, probably means no explicit return was done, e.g perl code was sub foo {}
1386 #
1387 0 debug('self ref detected, erasing eval');
1388 0 undef @eval;
1389  
1390 }
1391
1392  
1393 # Quick sanity check on return.
1394 #
1395 6 ▶ if (grep {ref($_) && (ref($_) !~ /(?:SCALAR|ARRAY|HASH|JSON)/)} @eval) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {ref $_ and not ref($_) =~ /(?:SCALAR|ARRAY|HASH|JSON)/;} @eval) 0 6 6
ref $_ and not ref($_) =~ /(?:SCALAR|ARRAY|HASH|JSON)/ 6 0 6
1396  
1397 # Whatever it is we can't render it unless SCALAR, ARRAY or HASH
1398 #
1399 0 debug('incorrect ref type detected');
1400 0 return err('return from eval of ref type \'%s\' not supported', join(',', grep {$_} map {ref($_)} @eval));
1401  
1402 }
1403  
1404  
1405 # Done
1406 #
1407 6 debug('no error detected, returning: %s', Dumper(\@eval));
1408 6 \@eval;
1409  
1410 4 });
1411  
1412  
1413 # The code ref for the eval statement if using Safe module. NOTE: old and unmaintained.
1414 #
1415 my $eval_safe_cr=set_subname('eval_safe_cr_anon', sub {
1416  
1417  
1418 # Get self ref
1419 #
1420 0 ▶ my ($self, $data_ar, $eval_param_hr, $eval_text, $index)=@_;
Subroutine __ANON__: not called CC=20 SCAR=60.4
1421  
1422  
1423 # Inode
1424 #
1425 #my $inode=$self->{'_inode'} || 'ANON' # Was ANON - see above Anon used when no inode present, eg wdcompile
1426 0 ▶ my $inode=$self->{'_inode'} || $self->inode();
Condition0%0/3
$self->{'_inode'} || $self->inode
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_inode'} || $self->inode
$self->{'_inode'} $self->inode
Truth table0%0/3
A || B
A= $self->{'_inode'}B= $self->inode
ABresult
1X1
011
000
1427  
1428 # Get CGI vars
1429 #
1430 0 ▶ my $cgi_or=$self->{'_CGI'} || $self->CGI();
Condition0%0/3
$self->{'_CGI'} || $self->CGI
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_CGI'} || $self->CGI
$self->{'_CGI'} $self->CGI
Truth table0%0/3
A || B
A= $self->{'_CGI'}B= $self->CGI
ABresult
1X1
011
000
1431 my $param_hr=(
1432 0 ▶ $self->{'_eval_cgi_hr'} ||= do {
Condition0%0/3
$self->{"_eval_cgi_hr"} ||= do { $cgi_or->Vars }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_eval_cgi_hr"} ||= do { $cgi_or->Vars }
$self->{"_eval_cgi_hr"} do { $cgi_or->Vars }
Truth table0%0/3
A ||= B
A= $self->{"_eval_cgi_hr"}B= do { $cgi_or->Vars }
ABresult
1X1
011
000
1433  
1434 0 $cgi_or->Vars();
1435  
1436 }
1437 );
1438  
1439 # Init Safe mode environment space
1440 #
1441 0 ▶ my $safe_or=$self->{'_eval_safe'} || do {
Condition0%0/3
$self->{'_eval_safe'} || do { debug('safe init (eval_init)'); require Safe; require Opcode; 'Safe'->new }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_eval_safe'} || do { debug('safe init (eval_init)'); require Safe; require Opcode; 'Safe'->new }
$self->{'_eval_safe'} do { debug('safe init (eval_init)'); require Safe; require Opcode; 'Safe'->new }
Truth table0%0/3
A || B
A= $self->{'_eval_safe'}B= do { debug('safe init (eval_init)'); require Safe; require Opcode; 'Safe'->new }
ABresult
1X1
011
000
1442 0 debug('safe init (eval_init)');
1443 0 require Safe;
1444 0 require Opcode;
1445  
1446 # Used to use Safe->new($inode), but bug in Safe (actually Opcode) is Safe root namespace too long
1447 #
1448 0 Safe->new();
1449 };
1450 0 ▶ $self->{'_eval_safe'} ||= do {
Condition0%0/3
$self->{"_eval_safe"} ||= do { $safe_or->permit_only(@{$WebDyne::WEBDYNE_EVAL_SAFE_OPCODE_AR;}); $safe_or }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_eval_safe"} ||= do { $safe_or->permit_only(@{$WebDyne::WEBDYNE_EVAL_SAFE_OPCODE_AR;}); $safe_or }
$self->{"_eval_safe"} do { $safe_or->permit_only(@{$WebDyne::WEBDYNE_EVAL_SAFE_OPCODE_AR;}); $safe_or }
Truth table0%0/3
A ||= B
A= $self->{"_eval_safe"}B= do { $safe_or->permit_only(@{$WebDyne::WEBDYNE_EVAL_SAFE_OPCODE_AR;}); $safe_or }
ABresult
1X1
011
000
1451 0 $safe_or->permit_only(@{$WEBDYNE_EVAL_SAFE_OPCODE_AR});
1452 0 $safe_or;
1453 };
1454  
1455  
1456 # Only eval subroutine if we have not done already, if need to eval store in
1457 # cache so only done once
1458 #
1459 0 local *_=$param_hr;
1460 0 ${$safe_or->varglob('_self')}=$self;
1461 0 ${$safe_or->varglob('_eval_param_hr')}=$eval_param_hr;
1462 #${$safe_or->varglob('_r')}=$self->{'_r'};
1463 #${$safe_or->varglob('_CGI')}=$cgi_or;
1464 #my $html_sr=$safe_or->reval("sub{$eval_text}->(\$::_self, \$::_r, \$::_CGI, \$::_eval_param_hr)", $WebDyne::WEBDYNE_EVAL_USE_STRICT) ||
1465 #
1466 # Change mind, remove r and CGI as supplied params, user can request if wanted.
1467 #
1468 0 ▶ my $html_sr=$safe_or->reval("sub{$eval_text}->(\$::_self, \$::_eval_param_hr)", $WebDyne::WEBDYNE_EVAL_USE_STRICT) ||
Branch: 1 branch
BranchTrueFalseTotal
errstr() ? : 0 0 0
Condition0%0/4
$safe_or->reval("sub{$eval_text}->(\$::_self, \$::_eval_param_hr)", $WebDyne::WEBDYNE_EVAL_USE_STRICT) || (return errstr() ? err() : err($@ || 'undefined return from Safe->reval()'))
l!l
00
$@ || 'undefined return from Safe->reval()'
l!l
00
MC/DC0%0/1
$safe_or->reval("sub{$eval_text}->(\$::_self, \$::_eval_param_hr)", $WebDyne::WEBDYNE_EVAL_USE_STRICT) || (return errstr() ? err() : err($@ || 'undefined return from Safe->reval()'))
$safe_or->reval("sub{$eval_text}->(\$::_self, \$::_eval_param_hr)", $WebDyne::WEBDYNE_EVAL_USE_STRICT)
MC/DC0%0/1
$@ || 'undefined return from Safe->reval()'
$@
Truth table0%0/2
A
A= $safe_or->reval("sub{$eval_text}->(\$::_self, \$::_eval_param_hr)", $WebDyne::WEBDYNE_EVAL_USE_STRICT)
Aresult
11
00
Truth table0%0/2
A
A= $@
Aresult
11
00
1469 return errstr() ? err() : err($@ || 'undefined return from Safe->reval()');
1470  
1471  
1472 # Run through the same sequence as non-safe routine
1473 #
1474 0 ▶ if (!defined($html_sr) || $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $html_sr or $@) 0 0 0
Condition0%0/3
not defined $html_sr or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $html_sr or $@
not defined $html_sr $@
Truth table0%0/3
not(A) or B
A= not defined $html_srB= $@
ABresult
1X1
011
000
1475  
1476  
1477 # An error occurred - handle it and return.
1478 #
1479 0 ▶ if (my $err=(errstr() || $@)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = errstr() || $@) { } 0 0 0
Condition0%0/3
errstr() || $@
l!l&&r!l&&!r
000
MC/DC0%0/2
errstr() || $@
errstr() $@
Truth table0%0/3
A || B
A= errstr()B= $@
ABresult
1X1
011
000
1480  
1481 # Eval error or err() called during routine.
1482 #
1483 0 return $self->err_eval($err, \$eval_text, $inode);
1484  
1485 }
1486 else {
1487  
1488 # Some other problem
1489 #
1490 0 return err('code did not return a true value: %s', $eval_text);
1491 }
1492  
1493  
1494 }
1495  
1496  
1497 # Array returned ? Convert if so
1498 #
1499 0 ▶ (ref($html_sr) eq 'ARRAY') && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $html_sr eq "ARRAY" and do { $html_sr = \join(undef, map({ref $_ ? ${$_;} : $_;} @{$html_sr;})) } 0 0 0
1500 0 ▶ $html_sr=\join(undef, map {ref($_) ? ${$_} : $_} @{$html_sr})
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
1501 };
1502  
1503  
1504 # Any 'printed data ? Prepend to output. Used to do $self->{'_print_ar'}{$data_ar} but changed to
1505 # just $self->{'_print_ar'}. See code history for background
1506 #
1507 0 ▶ if (my $print_ar=delete $self->{'_print_ar'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $print_ar = delete $self->{'_print_ar'}) { } 0 0 0
1508 0 debug("print_ar: $print_ar %s", Dumper($print_ar));
1509 0 foreach my $item (reverse @{$print_ar}) {
1510 0 debug("prepending printed data %s for data_ar: $data_ar, %s", Dumper($item, $data_ar));
1511 0 ▶ my $print_html=(ref($_) eq 'SCALAR') ? ${$_} : $_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'SCALAR' ? : 0 0 0
1512 0 ▶ $html_sr=ref($html_sr) ? \($print_html . ${$html_sr}) : ($print_html . $html_sr);
Branch: 1 branch
BranchTrueFalseTotal
ref $html_sr ? : 0 0 0
1513 }
1514  
1515 }
1516 else {
1517 0 debug('no printed data detected');
1518 }
1519  
1520  
1521 # Make sure we return a ref
1522 #
1523 0 ▶ return ref($html_sr) ? $html_sr : \$html_sr;
Branch: 1 branch
BranchTrueFalseTotal
ref $html_sr ? : 0 0 0
1524  
1525  
1526 4 });
1527  
1528  
1529 # Hash eval routine, works similar to the above, but returns a hash ref
1530 #
1531 my $eval_hash_cr=set_subname('eval_hash_cr_anon', sub {
1532  
1533  
1534 # Run eval and turn into tied hash
1535 #
1536 0 ▶ debug('eval_hash_cr, %s', Dumper(\@_));
Subroutine __ANON__: not called CC=2 SCAR=17.9
1537 0 ▶ tie(my %hr, 'Tie::IxHash', @{$eval_perl_cr->(@_) || return err()});
Branch: 1 branch
BranchTrueFalseTotal
&$eval_perl_cr(@_) or return err() 0 0 0
1538 0 return \%hr;
1539  
1540  
1541 4 });
1542  
1543  
1544 # Array eval routine, works similar to the above, but returns an array ref
1545 #
1546 my $eval_array_cr=set_subname('eval_array_cr_anon', sub {
1547  
1548  
1549 # Run eval and return default - which is an array ref
1550 #
1551 0 ▶ debug('eval_array_cr, %s', Dumper(\@_));
Subroutine __ANON__: not called CC=2 SCAR=17.9
1552 0 ▶ return $eval_perl_cr->(@_) || err();
Condition0%0/3
&$eval_perl_cr(@_) || err()
l!l&&r!l&&!r
000
MC/DC0%0/2
&$eval_perl_cr(@_) || err()
&$eval_perl_cr(@_) err()
Truth table0%0/3
A || B
A= &$eval_perl_cr(@_)B= err()
ABresult
1X1
011
000
1553  
1554 4 });
1555  
1556  
1557 # Code ref eval routine
1558 #
1559 my $eval_code_cr=set_subname('eval_code_cr_anon', sub {
1560  
1561  
1562 # Need to eval some code. Dispatch to perl code ref
1563 #
1564 8 ▶ my ($self, $data_ar, $eval_param_hr, $eval_text, $index, $tag_fg)=@_;
Subroutine __ANON__: called CC=11 SCAR=37.9
1565 8 debug("eval code start $eval_text");
1566 8 ▶ my $html_ar=$eval_perl_cr->(@_) || return err();
Condition50%1/2
&$eval_perl_cr(@_) || (return err())
l!l
60
MC/DC0%0/1
&$eval_perl_cr(@_) || (return err())
&$eval_perl_cr(@_)
Truth table50%1/2
A
A= &$eval_perl_cr(@_)
Aresult
11
00
1567 6 debug("eval code finish %s, %s", Dumper($html_ar, $eval_param_hr));
1568
1569
1570  
1571 # We only accept first item of any array ref returned (which might be an array ref itself)
1572 #
1573 6 my $html_sr=$html_ar->[0];
1574  
1575  
1576 # If array ref returned and not rendering a tag convert to string. If in tag CGI.pm can
1577 # use array ref so leave alone
1578 #
1579 6 ▶ if ((ref($html_sr) eq 'ARRAY') && !$tag_fg) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $html_sr eq "ARRAY" and not $tag_fg) 0 6 6
Condition33%1/3
ref $html_sr eq "ARRAY" and not $tag_fg
!ll&&!rl&&r
600
MC/DC0%0/2
ref $html_sr eq "ARRAY" and not $tag_fg
ref $html_sr eq "ARRAY" not $tag_fg
Truth table33%1/3
A and not(B)
A= ref $html_sr eq "ARRAY"B= not $tag_fg
ABresult
0X0
100
111
1580 0 ▶ $html_sr=\join(undef, map {(ref($_) eq 'SCALAR') ? ${$_} : $_} @{$html_sr}) ||
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'SCALAR' ? : 0 0 0
Condition0%0/2
\join(undef, map({ref $_ eq 'SCALAR' ? ${$_;} : $_;} @{$html_sr;})) || (return err('unable to generate scalar from %s', Dumper($html_sr)))
l!l
00
MC/DC0%0/1
\join(undef, map({ref $_ eq 'SCALAR' ? ${$_;} : $_;} @{$html_sr;})) || (return err('unable to generate scalar from %s', Dumper($html_sr)))
\join(undef, map({ref $_ eq 'SCALAR' ? ${$_;} : $_;} @{$html_sr;}))
Truth table0%0/2
A
A= \join(undef, map({ref $_ eq 'SCALAR' ? ${$_;} : $_;} @{$html_sr;}))
Aresult
11
00
1581 return err('unable to generate scalar from %s', Dumper($html_sr));
1582 }
1583  
1584  
1585 # Any 'printed data ? Prepend to output. Used to do $self->{'_print_ar'}{$data_ar} but changed to
1586 # just $self->{'_print_ar'}. See code history for background
1587 #
1588 6 ▶ if (my $print_ar=delete $self->{'_print_ar'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $print_ar = delete $self->{'_print_ar'}) { } 0 6 6
1589 0 debug("print_ar: $print_ar %s", Dumper($print_ar));
1590 0 foreach my $item (reverse @{$print_ar}) {
1591 0 debug("prepending printed data %s for data_ar: $data_ar, %s", Dumper($item, $data_ar));
1592 0 ▶ my $print_html=(ref($item) eq 'SCALAR') ? ${$item} : $item;
Branch: 1 branch
BranchTrueFalseTotal
ref $item eq 'SCALAR' ? : 0 0 0
1593 0 ▶ $html_sr=ref($html_sr) ? \($print_html . ${$html_sr}) : ($print_html . $html_sr);
Branch: 1 branch
BranchTrueFalseTotal
ref $html_sr ? : 0 0 0
1594 }
1595 }
1596 else {
1597 6 debug('no printed data detected');
1598 }
1599  
1600  
1601 # Make sure we return a ref
1602 #
1603 6 ▶ return ref($html_sr) ? $html_sr : \$html_sr;
Branch: 1 branch
BranchTrueFalseTotal
ref $html_sr ? : 6 0 6
1604  
1605 4 });
1606  
1607  
1608 # Scalar (${foo}) routine
1609 #
1610 my $eval_scalar_cr=set_subname('eval_scalar_cr_anon', sub {
1611  
1612 6 ▶ my $value=$_[2]->{$_[3]};
Subroutine __ANON__: called CC=7 SCAR=29.8
1613 6 ▶ unless ($value) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value) 0 6 6
1614 0 ▶ if (!exists($_[2]->{$_[3]}) && WEBDYNE_STRICT_VARS) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $_[2]{$_[3]} and 1) 0 0 0
Condition0%0/2
not exists $_[2]{$_[3]} and 1
!ll
00
MC/DC0%0/1
not exists $_[2]{$_[3]} and 1
not exists $_[2]{$_[3]}
Truth table0%0/2
not(A)
A= not exists $_[2]{$_[3]}
Aresult
00
11
1615 0 return err("no '$_[3]' parameter value supplied, parameters are: %s", join(',', map {"'$_'"} keys %{$_[2]}))
1616 }
1617 }
1618  
1619 # Get rid of any overloading
1620 6 ▶ if (ref($value) && overload::Overloaded($value)) {$value="$value"}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and overload::Overloaded($value)) 0 6 6
Condition33%1/3
ref $value and overload::Overloaded($value)
!ll&&!rl&&r
600
MC/DC0%0/2
ref $value and overload::Overloaded($value)
ref $value overload::Overloaded($value)
Truth table33%1/3
A and B
A= ref $valueB= overload::Overloaded($value)
ABresult
0X0
100
111
1621 6 ▶ return ref($value) ? $value : \$value
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 0 6 6
1622  
1623 4 });
1624  
1625  
1626 # Init anon text and attr evaluation subroutines, store in class space
1627 # for quick retrieval when needed, save redefining all the time
1628 #
1629 my %eval_cr=(
1630  
1631 '$' => $eval_scalar_cr,
1632 '@' => $eval_array_cr,
1633 '%' => $eval_hash_cr,
1634 '!' => $eval_code_cr,
1635 '#' => $eval_perl_cr,
1636 0 ▶ '+' => sub {return \($_[0]->CGI()->param($_[3]))},
Subroutine __ANON__: not called CC=1 SCAR=6.9
1637 0 ▶ '*' => sub {return \$ENV{$_[3]}},
Subroutine __ANON__: not called CC=1 SCAR=6.9
1638 '^' => sub {
1639 0 ▶ my $m=$_[3]; my $r=$_[0]->{'_r'};
Subroutine __ANON__: not called CC=2 SCAR=17.9
1640 0 ▶ UNIVERSAL::can($r, $m) ? \$r->$m : err("unknown request method '$m'")
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::can($r, $m) ? : 0 0 0
1641 }
1642  
1643 4 );
1644  
1645  
1646 # Store in class name space
1647 #
1648 4 $Package{'_eval_cr'}=\%eval_cr;
1649
1650 }
1651  
1652  
1653 sub cache_clean {
1654  
1655  
1656 # Get cache_hr, only param supplied
1657 #
1658 0 ▶ my $cache_hr=shift();
Subroutine cache_clean: not called CC=2 SCAR=17.9
Pod undocumented
1659 0 debug('in cache_clean');
1660  
1661  
1662 # Values we want, either last run time (lrun) or number of times run
1663 # (nrun)
1664 #
1665 0 my $clean_method=WEBDYNE_CACHE_CLEAN_METHOD ? 'nrun' : 'lrun';
1666  
1667  
1668 # Sort into array of inode values, sorted descending by clean attr
1669 #
1670 0 my @cache=sort {$cache_hr->{$b}{$clean_method} <=> $cache_hr->{$a}{$clean_method}}
1671 0 keys %{$cache_hr};
1672 0 debug('cache clean array %s', Dumper(\@cache));
1673  
1674  
1675 # If > high watermark entries, we need to clean
1676 #
1677 0 ▶ if (@cache > WEBDYNE_CACHE_HIGH_WATER) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cache > 64) { } 0 0 0
1678  
1679  
1680 # Yes, clean
1681 #
1682 0 debug('cleaning cache');
1683  
1684  
1685 # Delete excess entries
1686 #
1687 0 my @clean=map {delete $cache_hr->{$_}} @cache[WEBDYNE_CACHE_LOW_WATER..$#cache];
1688  
1689  
1690 # Debug
1691 #
1692 0 debug('removed %s entries from cache', scalar @clean);
1693  
1694 }
1695 else {
1696  
1697 # Nothing to do
1698 #
1699 0 debug(
1700 'no cleanup needed, cache size %s less than high watermark %s',
1701 scalar @cache, WEBDYNE_CACHE_HIGH_WATER
1702 );
1703  
1704 }
1705  
1706  
1707 # Done
1708 #
1709 0 return \undef;
1710  
1711 }
1712  
1713  
1714 sub head_request {
1715  
1716  
1717 # Head request only
1718 #
1719 0 ▶ my $r=shift();
Subroutine head_request: not called CC=2 SCAR=17.9
Pod undocumented
1720  
1721  
1722 # Clear any handlers
1723 #
1724 0 $r->set_handlers(PerlHandler => undef);
1725  
1726  
1727 # Send the request
1728 #
1729 0 ▶ $r->send_http_header() if !$MP2;
Branch: 1 branch
BranchTrueFalseTotal
unless $WebDyne::MP2 0 0 0
1730  
1731  
1732 # Done
1733 #
1734 0 return &Apache::OK;
1735  
1736 }
1737  
1738  
1739 sub render_reset {
1740  
1741 0 ▶ my ($self, $data_ar)=@_;
Subroutine render_reset: not called CC=2 SCAR=17.9
Pod undocumented
1742 0 ▶ $data_ar ? $self->{'_perl'}[0]=$data_ar : delete $self->{'_perl'};
Branch: 1 branch
BranchTrueFalseTotal
$data_ar ? : 0 0 0
1743  
1744 }
1745  
1746  
1747 sub render {
1748  
1749  
1750 # Convert data array structure into HTML
1751 #
1752 6 ▶ my ($self, $param_hr)=@_;
Subroutine render: called CC=6 SCAR=19.0
Pod undocumented
1753  
1754  
1755 # If not supplied param as hash ref assume all vars are params to be subs't when
1756 # rendering this data block
1757 #
1758 6 ▶ my %param=(ref($param_hr) eq 'HASH') ? %{$param_hr} : @_[1..$#_];
Branch: 1 branch
BranchTrueFalseTotal
ref $param_hr eq 'HASH' ? : 6 0 6
1759
1760
1761 # Get node array ref
1762 #
1763 6 ▶ my $data_ar=$self->{'_perl'}[0][WEBDYNE_NODE_CHLD_IX] ||
Condition50%1/2
$self->{'_perl'}[0][2] || (return err('unable to get HTML data array'))
l!l
60
MC/DC0%0/1
$self->{'_perl'}[0][2] || (return err('unable to get HTML data array'))
$self->{'_perl'}[0][2]
Truth table50%1/2
A
A= $self->{'_perl'}[0][2]
Aresult
11
00
1764 return err('unable to get HTML data array');
1765
1766  
1767 # Any data params for this render ? Add them to parent data as additive
1768 #
1769 6 foreach my $perl_data_hr (@{$self->{'_perl_data'}}) {
1770 6 ▶ map { $param{$_}=$perl_data_hr->{$_} unless exists $param{$_} } keys %{$perl_data_hr}
Branch: 1 branch
BranchTrueFalseTotal
unless exists $param{$_} 6 0 6
1771 }
1772  
1773
1774 # Call render_node
1775 #
1776 6 ▶ return $self->render_data_ar( data=>$data_ar, param=>\%param) ||
Condition33%1/3
$self->render_data_ar('data', $data_ar, 'param', \%param) || err()
l!l&&r!l&&!r
600
MC/DC0%0/2
$self->render_data_ar('data', $data_ar, 'param', \%param) || err()
$self->render_data_ar('data', $data_ar, 'param', \%param) err()
Truth table33%1/3
A || B
A= $self->render_data_ar('data', $data_ar, 'param', \%param)B= err()
ABresult
1X1
011
000
1777 err();
1778
1779  
1780 }
1781  
1782  
1783 sub render_data_ar {
1784  
1785  
1786 # Convert data array structure into HTML
1787 #
1788 14 ▶ my ($self, %param)=@_;
Subroutine render_data_ar: called CC=8 SCAR=21.0
Pod undocumented
1789 14 debug($self);
1790  
1791  
1792 # Get node array ref
1793 #
1794 14 ▶ my $data_ar=$param{'data'} ||
Condition50%1/2
$param{'data'} || (return err('unable to get HTML data array'))
l!l
140
MC/DC0%0/1
$param{'data'} || (return err('unable to get HTML data array'))
$param{'data'}
Truth table50%1/2
A
A= $param{'data'}
Aresult
11
00
1795 return err('unable to get HTML data array');
1796  
1797  
1798 # Debug
1799 #
1800 14 debug("render data_ar $data_ar");
1801  
1802  
1803 # Get HTML::Tiny object
1804 #
1805 14 ▶ my $html_or=$self->{'_html_tiny_or'} || $self->html_tiny() ||
Condition60%3/5
$self->{'_html_tiny_or'} || $self->html_tiny || (return err('unable to get HTML::Tiny object from self ref'))
l!l
140
$self->{"_html_tiny_or"} or $self->html_tiny
l!l&&r!l&&!r
950
MC/DC0%0/2
$self->{'_html_tiny_or'} || $self->html_tiny || (return err('unable to get HTML::Tiny object from self ref'))
$self->{"_html_tiny_or"} $self->html_tiny
Truth table66%2/3
A or B
A= $self->{"_html_tiny_or"}B= $self->html_tiny
ABresult
1X1
011
000
1806 return err("unable to get HTML::Tiny object from self ref");
1807 14 debug("html_or: $html_or");
1808  
1809  
1810 # Recursive anon sub to do the render, init and store in class space
1811 # if not already done, saves a small amount of time if doing many
1812 # iterations
1813 #
1814 14 ▶ my $render_cr=$Package{'_render_cr'} ||= \&render_cr;
Condition100%2/2
$WebDyne::Package{"_render_cr"} ||= \&WebDyne::render_cr
l!l
131
MC/DC100%1/1
$WebDyne::Package{"_render_cr"} ||= \&WebDyne::render_cr
$WebDyne::Package{"_render_cr"}
Truth table100%2/2
A
A= $WebDyne::Package{"_render_cr"}
Aresult
11
00
1815  
1816  
1817 # At the top level the array may have completly text nodes, and no children, so
1818 # need to take care to only render children if present.
1819 #
1820 14 my @html;
1821 14 foreach my $node_data_ar (@{$data_ar}) {
1822  
1823  
1824 # Is this a sub node, or only text (ref means sub-node)
1825 #
1826 28 ▶ if (ref($node_data_ar)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node_data_ar) { } 14 14 28
1827  
1828  
1829 # Sub node, we call call render routine
1830 #
1831 14 debug('recursive render node_data_ar: %s', Dumper($node_data_ar));
1832 push @html,
1833 #${$render_cr->($render_cr, $self, $cgi_or, $node_data_ar, \%param_data) || return err()};
1834 14 ▶ ${$render_cr->($render_cr, $self, $html_or, $node_data_ar, $param{'param'}) || return err()};
Branch: 1 branch
BranchTrueFalseTotal
&$render_cr($render_cr, $self, $html_or, $node_data_ar, $param{"param"}) or return err() 0 12 12
1835  
1836  
1837 }
1838 else {
1839  
1840  
1841 # Text only, do not render just push onto return array
1842 #
1843 14 debug('add text only node_data_ar: %s', \$node_data_ar);
1844 14 push @html, $node_data_ar;
1845  
1846 }
1847 }
1848  
1849  
1850 # Return scalar ref of completed HTML string
1851 #
1852 12 debug('render exit, html %s', Dumper(\@html));
1853 12 return \join(undef, @html);
1854  
1855  
1856 }
1857  
1858  
1859 sub render_cr {
1860  
1861
1862 # Code ref used recursively by render() above
1863 #
1864  
1865 # Get self ref, node array etc
1866 #
1867 14 ▶ my ($render_cr, $self, $html_or, $data_ar, $param_data_hr)=@_;
Subroutine render_cr: called CC=23 SCAR=46.3
Pod undocumented
1868 14 debug("render_cr: $render_cr, self:$self, data_ar:$data_ar, param_data_hr:$param_data_hr (%s), caller:%s", Dumper($param_data_hr), Dumper([caller()]));
1869  
1870  
1871 # Get tag
1872 #
1873 my ($html_tag, $html_line_no)=
1874 14 @{$data_ar}[WEBDYNE_NODE_NAME_IX, WEBDYNE_NODE_LINE_IX];
1875 14 my $html_chld;
1876  
1877  
1878 # Save current data block away for reference by error handler if something goes
1879 # wrong
1880 #
1881 14 push @{$self->{'_data_ar_err'}},$data_ar;
1882  
1883  
1884 # Debug
1885 #
1886 14 debug("render tag $html_tag, line $html_line_no");
1887  
1888  
1889 # Get attr hash ref
1890 #
1891 14 my $attr_hr=$data_ar->[WEBDYNE_NODE_ATTR_IX];
1892  
1893  
1894 # If subst flag present, means we need to process attr values
1895 #
1896 14 ▶ if ($data_ar->[WEBDYNE_NODE_SBST_IX]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_ar->[3]) 0 14 14
1897 0 ▶ $attr_hr=$self->subst_attr($data_ar, $attr_hr, $param_data_hr) ||
Condition0%0/2
$self->subst_attr($data_ar, $attr_hr, $param_data_hr) || (return err())
l!l
00
MC/DC0%0/1
$self->subst_attr($data_ar, $attr_hr, $param_data_hr) || (return err())
$self->subst_attr($data_ar, $attr_hr, $param_data_hr)
Truth table0%0/2
A
A= $self->subst_attr($data_ar, $attr_hr, $param_data_hr)
Aresult
11
00
1898 return err();
1899 }
1900 14 debug("attr_hr: $attr_hr (%s)", Dumper($attr_hr));
1901  
1902  
1903 # If param present, use for sub-render. Commented out was when render was co-mingled, not needed now separated to render_data_ar(), render() methods
1904 #
1905 #if (!exists($param_data_hr->{'param'})) {
1906 ## if ($attr_hr->{'param'}) {
1907 ## my %param_data=(%{$param_data_hr}, %{$attr_hr->{'param'}});
1908 ## $param_data_hr=\%param_data;
1909 ## }
1910 #}
1911 #elsif ($attr_hr->{'param'}) {
1912 # $param_data_hr=$attr_hr->{'param'}
1913 #}
1914  
1915 14 ▶ if (exists ($attr_hr->{'param'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr_hr->{"param"}) 0 14 14
1916 0 ▶ if (ref($attr_hr->{'param'}) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $attr_hr->{'param'} eq 'HASH') { } 0 0 0
elsif (ref $attr_hr->{'param'}) { } 0 0 0
1917 0 my %param_data=(%{$param_data_hr}, %{$attr_hr->{'param'}});
1918 0 $param_data_hr=\%param_data;
1919 }
1920 elsif (ref($attr_hr->{'param'})) {
1921 0 return err("perl param attribute is %s ref, must be HASH ref or plain scalar", ref($attr_hr->{'param'}));
1922 }
1923 }
1924  
1925  
1926 14 debug('result: %s', Dumper($param_data_hr));
1927  
1928  
1929 # Was this, but it didn't allow nested param
1930 #
1931 #$attr_hr->{'param'} && ($param_data_hr=$attr_hr->{'param'});
1932 14 unshift @{$self->{'_perl_data'}}, $param_data_hr;
1933  
1934  
1935 # Process sub nodes to get child html data, only if not a perl tag or block tag
1936 # though - they will choose when to render sub data. Subst is OK
1937 #
1938 14 ▶ if (!$CGI_TAG_WEBDYNE{$html_tag} || ($html_tag eq 'subst')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $WebDyne::CGI_TAG_WEBDYNE{$html_tag} or $html_tag eq 'subst') { } 6 8 14
Condition66%2/3
not $WebDyne::CGI_TAG_WEBDYNE{$html_tag} or $html_tag eq "subst"
l!l&&r!l&&!r
068
MC/DC50%1/2
not $WebDyne::CGI_TAG_WEBDYNE{$html_tag} or $html_tag eq "subst"
not $WebDyne::CGI_TAG_WEBDYNE{$html_tag} $html_tag eq "subst"
Truth table66%2/3
not(A) or B
A= not $WebDyne::CGI_TAG_WEBDYNE{$html_tag}B= $html_tag eq "subst"
ABresult
1X1
011
000
1939  
1940  
1941 # Not a perl tag, recurse through children and render them, building
1942 # up HTML from inside out
1943 #
1944 6 ▶ my @data_child_ar=$data_ar->[WEBDYNE_NODE_CHLD_IX] ? @{$data_ar->[WEBDYNE_NODE_CHLD_IX]} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$data_ar->[2] ? : 6 0 6
1945 6 foreach my $data_chld_ar (@data_child_ar) {
1946  
1947  
1948 # Debug
1949 #
1950 6 debug('data_chld_ar %s', Dumper($data_chld_ar));
1951  
1952  
1953 # Only recurse on children which are are refs, as these are sub nodes. A
1954 # child that is not a ref is merely HTML text
1955 #
1956 6 ▶ if (ref($data_chld_ar)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data_chld_ar) { } 0 6 6
1957  
1958  
1959 # It is a sub node, render recursively
1960 #
1961 $html_chld.=${
1962 0 (
1963 0 ▶ $render_cr->($render_cr, $self, $html_or, $data_chld_ar, $param_data_hr)
Branch: 1 branch
BranchTrueFalseTotal
&$render_cr($render_cr, $self, $html_or, $data_chld_ar, $param_data_hr) or return err() 0 0 0
1964 ||
1965 return err())};
1966  
1967 #$html_chld.="\n";
1968  
1969 }
1970 else {
1971  
1972  
1973 # Text node only, add text to child html string
1974 #
1975 6 $html_chld.=$data_chld_ar;
1976  
1977 }
1978  
1979 }
1980  
1981 }
1982 else {
1983  
1984 8 debug("skip child render, under $html_tag tag");
1985  
1986 }
1987  
1988  
1989 # Debug
1990 #
1991 14 debug("html_chld $html_chld");
1992 14 my $html;
1993  
1994  
1995 # Render *our* node now, trying to use most efficient/appropriated method depending on a number
1996 # of factors
1997 #
1998 14 ▶ if ($CGI_TAG_WEBDYNE{$html_tag}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($WebDyne::CGI_TAG_WEBDYNE{$html_tag}) { } 14 0 14
elsif ($attr_hr) { } 0 0 0
elsif (defined $html_chld and length $html_chld) { } 0 0 0
1999  
2000  
2001 # Special WebDyne tag, render using our self ref, not CGI object
2002 #
2003 14 debug("rendering webdyne tag $html_tag");
2004 14 ▶ $html=${ $self->$html_tag($data_ar, $attr_hr, $param_data_hr, $html_chld) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->$html_tag($data_ar, $attr_hr, $param_data_hr, $html_chld) or return err() 0 12 12
2005 return err() };
2006  
2007  
2008  
2009 }
2010 elsif ($attr_hr) {
2011  
2012  
2013 # Normal CGI tag, with attributes and perhaps child text
2014 #
2015 0 debug("rendering normal HTML tag: $html_tag with attr: %s", Dumper($attr_hr));
2016  
2017 # Always pass the attribute hash for this branch, but only pass child
2018 # text when it is defined and non-empty. This preserves valid false
2019 # content such as "0" while avoiding an explicit empty child argument
2020 # for closed/shortcut tags that HTML::Tiny expects to receive as
2021 # attribute-only calls.
2022 #
2023 0 ▶ $html=$html_or->$html_tag(
Branch: 1 branch
BranchTrueFalseTotal
defined $html_chld && length $html_chld ? : 0 0 0
Condition0%0/7
$html_or->$html_tag($attr_hr || {}, defined $html_chld && length $html_chld ? $html_chld : ()) || (return err("CGI tag '<$html_tag>' did not return any text"))
l!l
00
$attr_hr || {}
l!l
00
defined $html_chld and length $html_chld
!ll&&!rl&&r
000
MC/DC0%0/1
$html_or->$html_tag($attr_hr || {}, defined $html_chld && length $html_chld ? $html_chld : ()) || (return err("CGI tag '<$html_tag>' did not return any text"))
$html_or->$html_tag($attr_hr || {}, defined $html_chld && length $html_chld ? $html_chld : ())
MC/DC0%0/1
$attr_hr || {}
$attr_hr
MC/DC0%0/2
defined $html_chld and length $html_chld
defined $html_chld length $html_chld
Truth table0%0/2
A
A= $html_or->$html_tag($attr_hr || {}, defined $html_chld && length $html_chld ? $html_chld : ())
Aresult
11
00
Truth table0%0/2
A
A= $attr_hr
Aresult
11
00
Truth table0%0/3
A and B
A= defined $html_chldB= length $html_chld
ABresult
0X0
100
111
2024 ($attr_hr || {}),
2025 ((defined($html_chld) && length($html_chld)) ? $html_chld : ())
2026 ) ||
2027 return err( "CGI tag '<$html_tag>' did not return any text" );
2028
2029  
2030 }
2031 ▶ elsif (defined($html_chld) && length($html_chld)) {
Condition0%0/3
defined $html_chld and length $html_chld
!ll&&!rl&&r
000
MC/DC0%0/2
defined $html_chld and length $html_chld
defined $html_chld length $html_chld
Truth table0%0/3
A and B
A= defined $html_chldB= length $html_chld
ABresult
0X0
100
111
2032  
2033  
2034 # Normal CGI tag, no attributes but with child text
2035 #
2036 # Use length rather than truth so "0" renders as real content; empty
2037 # string and undef still fall through to the empty-tag branch below.
2038 #
2039 0 debug("rendering normal HTML tag: $html_tag, no attributes but with child text");
2040 0 ▶ $html=$html_or->$html_tag($html_chld) ||
Condition0%0/2
$html_or->$html_tag($html_chld) || (return err("CGI tag '<$html_tag>' did not return any text"))
l!l
00
MC/DC0%0/1
$html_or->$html_tag($html_chld) || (return err("CGI tag '<$html_tag>' did not return any text"))
$html_or->$html_tag($html_chld)
Truth table0%0/2
A
A= $html_or->$html_tag($html_chld)
Aresult
11
00
2041 return err("CGI tag '<$html_tag>' did not return any text");
2042  
2043  
2044 }
2045 else {
2046  
2047  
2048 # Empty CGI object, eg <hr>
2049 #
2050 0 debug("rendering empty HTML tag: $html_tag");
2051 0 ▶ $html=$html_or->$html_tag() ||
Condition0%0/2
$html_or->$html_tag || (return err("CGI tag '<$html_tag>' did not return any text"))
l!l
00
MC/DC0%0/1
$html_or->$html_tag || (return err("CGI tag '<$html_tag>' did not return any text"))
$html_or->$html_tag
Truth table0%0/2
A
A= $html_or->$html_tag
Aresult
11
00
2052 return err("CGI tag '<$html_tag>' did not return any text");
2053  
2054 }
2055  
2056  
2057 # No errors, pop error handler stack
2058 #
2059 12 pop @{$self->{'_data_ar_err'}};
2060 12 shift @{$self->{'_perl_data'}};
2061
2062  
2063 # Return
2064 #
2065 12 return \$html;
2066  
2067  
2068 }
2069  
2070  
2071  
2072 sub redirect {
2073  
2074  
2075 # Redirect render to different location
2076 #
2077 2 ▶ my ($self, $param_hr)=@_;
Subroutine redirect: called CC=24 SCAR=48.3
Pod undocumented
2078  
2079  
2080 # If not supplied param as hash ref assume all vars are params to be subs't when
2081 # rendering this data block
2082 #
2083 2 ▶ ref($param_hr) || ($param_hr={@_[1..$#_]}) if $param_hr;
Branch: 1 branch
BranchTrueFalseTotal
if $param_hr 2 0 2
Condition33%2/6
$param_hr && (ref $param_hr || ($param_hr = {@_[1 .. $#_]}))
!ll
020
ref $param_hr or $param_hr = {@_[1 .. $#_]}
l!l
020
MC/DC0%0/3
$param_hr && (ref $param_hr || ($param_hr = {@_[1 .. $#_]}))
$param_hr ref $param_hr $param_hr = {@_[1 .. $#_]}
Truth table0%0/4
A && B or C
A= $param_hrB= ref $param_hrC= $param_hr = {@_[1 .. $#_]}
ABCresult
0XX0
1000
11X1
1011
2084  
2085  
2086 # Debug
2087 #
2088 2 debug('in redirect, param %s', Dumper($param_hr));
2089  
2090  
2091 # Restore select handler before anything else so all output goes
2092 # to main::STDOUT;
2093 #
2094 2 ▶ if (my $select=$self->{'_select'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $select = $self->{"_select"}) 2 0 2
2095 2 debug("restoring select handle to $select");
2096 2 CORE::select $select;
2097 }
2098 2 ▶ untie *WEBDYNE if tied *WEBDYNE;
Branch: 1 branch
BranchTrueFalseTotal
if tied *WEBDYNE 2 0 2
2099  
2100  
2101 # If redirecting to a different uri, run its handler
2102 #
2103 2 ▶ if ($param_hr->{'uri'} || $param_hr->{'file'} || $param_hr->{'location'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param_hr->{'uri'} or $param_hr->{'file'} or $param_hr->{'location'}) { } 0 2 2
Condition33%2/6
$param_hr->{"uri"} or $param_hr->{"file"} or $param_hr->{"location"}
l!l&&r!l&&!r
002
$param_hr->{"uri"} or $param_hr->{"file"}
l!l&&r!l&&!r
002
MC/DC0%0/3
$param_hr->{"uri"} or $param_hr->{"file"} or $param_hr->{"location"}
$param_hr->{"uri"} $param_hr->{"file"} $param_hr->{"location"}
Truth table25%1/4
A or B or C
A= $param_hr->{"uri"}B= $param_hr->{"file"}C= $param_hr->{"location"}
ABCresult
1XX1
01X1
0011
0000
2104  
2105  
2106 # Get HTML from subrequest
2107 #
2108 0 ▶ my $status=$self->subrequest($param_hr) ||
Condition0%0/2
$self->subrequest($param_hr) || (return err())
l!l
00
MC/DC0%0/1
$self->subrequest($param_hr) || (return err())
$self->subrequest($param_hr)
Truth table0%0/2
A
A= $self->subrequest($param_hr)
Aresult
11
00
2109 return err();
2110 0 debug("redirect status was $status");
2111  
2112  
2113 # GOTOs considered harmful - except here ! Speed things up significantly, removes uneeded checks
2114 # for redirects in render code etc.
2115 #
2116 0 ▶ my $r=$self->r() || return err();
Condition0%0/2
$self->r || (return err())
l!l
00
MC/DC0%0/1
$self->r || (return err())
$self->r
Truth table0%0/2
A
A= $self->r
Aresult
11
00
2117 0 $r->status($status);
2118 0 ▶ if (my $errstr=errstr()) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $errstr = errstr()) { } 0 0 0
elsif (&is_error($status)) { } 0 0 0
elsif ($status != &Apache::OK and not &is_success($status) and not &is_redirect($status)) { } 0 0 0
2119 0 debug("error in subrequest: $errstr");
2120 0 return errsubst("error in subrequest: $errstr")
2121 }
2122 elsif (is_error($status)) {
2123 0 debug("sending error response status $status with r $r");
2124 0 $r->send_error_response(&Apache::OK)
2125 }
2126 ▶ elsif (($status != &Apache::OK) && !is_success($status) && !is_redirect($status)) {
Condition0%0/6
$status != &Apache::OK and not &is_success($status) and not &is_redirect($status)
!ll&&!rl&&r
000
$status != &Apache::OK and not &is_success($status)
!ll&&!rl&&r
000
MC/DC0%0/3
$status != &Apache::OK and not &is_success($status) and not &is_redirect($status)
$status != &Apache::OK not &is_success($status) not &is_redirect($status)
Truth table0%0/4
A and not(B) and not(C)
A= $status != &Apache::OKB= not &is_success($status)C= not &is_redirect($status)
ABCresult
0XX0
10X0
1100
1111
2127 0 return err("unknown status code '$status' returned from subrequest");
2128 }
2129 else {
2130 0 debug("status $status OK");
2131 }
2132 0 goto HANDLER_COMPLETE;
2133  
2134  
2135 }
2136 else {
2137  
2138  
2139 # html/text/json must be a param. Test with exists rather than truth
2140 # so valid false body content such as "0" can be returned.
2141 #
2142 2 my ($redirect_type)=grep {exists($param_hr->{$_})} qw(html text json);
2143 2 ▶ $redirect_type ||
Branch: 1 branch
BranchTrueFalseTotal
$redirect_type or return err("no data supplied to redirect method") 0 2 2
2144 return err('no data supplied to redirect method');
2145 2 my $html_sr=$param_hr->{$redirect_type};
2146  
2147  
2148 # Set content type
2149 #
2150 2 ▶ my $r=$self->r() || return err();
Condition50%1/2
$self->r || (return err())
l!l
20
MC/DC0%0/1
$self->r || (return err())
$self->r
Truth table50%1/2
A
A= $self->r
Aresult
11
00
2151 2 ▶ if ($redirect_type eq 'html') {
Branch: 3 branches
BranchTrueFalseTotal
if ($redirect_type eq 'html') { } 0 2 2
elsif ($redirect_type eq 'text') { } 1 1 2
elsif ($redirect_type eq 'json') { } 1 0 1
2152 0 $r->content_type(WEBDYNE_CONTENT_TYPE_HTML)
2153 }
2154 elsif ($redirect_type eq 'text') {
2155 1 $r->content_type(WEBDYNE_CONTENT_TYPE_TEXT)
2156 }
2157 elsif ($redirect_type eq 'json') {
2158 1 $r->content_type(WEBDYNE_CONTENT_TYPE_JSON)
2159 }
2160  
2161  
2162 # And length
2163 #
2164 2 ▶ my $headers_out_hr=$r->headers_out || return err();
Condition50%1/2
$r->headers_out || (return err())
l!l
20
MC/DC0%0/1
$r->headers_out || (return err())
$r->headers_out
Truth table50%1/2
A
A= $r->headers_out
Aresult
11
00
2165 2 ▶ $headers_out_hr->{'Content-Length'}=length(ref($html_sr) ? ${$html_sr} : $html_sr);
Branch: 1 branch
BranchTrueFalseTotal
ref $html_sr ? : 0 2 2
2166  
2167  
2168 # Set status, send header
2169 #
2170 2 $r->status(HTTP_OK);
2171 2 ▶ $r->send_http_header() if !$MP2;
Branch: 1 branch
BranchTrueFalseTotal
unless $WebDyne::MP2 2 0 2
2172  
2173  
2174 # Print directly and shorcut return from render routine with non-harmful GOTO ! Should
2175 # always be SR, but be generous.
2176 #
2177 2 ▶ $r->print(ref($html_sr) ? ${$html_sr} : $html_sr);
Branch: 1 branch
BranchTrueFalseTotal
ref $html_sr ? : 0 2 2
2178 2 goto RENDER_COMPLETE;
2179  
2180  
2181 }
2182  
2183  
2184 }
2185  
2186  
2187 sub subrequest {
2188  
2189  
2190 # Redirect render to different location
2191 #
2192 0 ▶ my ($self, $param_hr)=@_;
Subroutine subrequest: not called CC=21 SCAR=61.4
Pod undocumented
2193  
2194  
2195 # Debug
2196 #
2197 0 debug('in subrequest %s', Dumper($param_hr));
2198  
2199  
2200 # Get request object, var for subrequest object
2201 #
2202 0 ▶ my ($r, $cgi_or)=map {$self->$_() || return err("unable to run '$_' method")} qw(request CGI);
Branch: 1 branch
BranchTrueFalseTotal
$self->$_ or return err("unable to run '${_}' method") 0 0 0
2203 0 my $r_child;
2204  
2205  
2206 # Run taks appropriate for subrequest - location redirects with 302, uri does sinternal redirect,
2207 # and file sends content of file.
2208 #
2209 0 ▶ if (my $location=$param_hr->{'location'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $location = $param_hr->{"location"}) 0 0 0
2210  
2211  
2212 # Does the request handler take care of it ?
2213 #
2214 0 ▶ if (UNIVERSAL::can($r, 'redirect')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($r, 'redirect')) { } 0 0 0
2215  
2216  
2217 # Let the request handler take care of it
2218 #
2219 0 debug('handler does redirect, handing off');
2220 0 $r->redirect($location); # no return value
2221 0 return HTTP_FOUND;
2222  
2223 }
2224 else {
2225  
2226  
2227 # Must do it ourselves
2228 #
2229 0 debug('doing redirect ourselves');
2230 0 ▶ my $headers_out_hr=$r->headers_out || return err();
Condition0%0/2
$r->headers_out || (return err())
l!l
00
MC/DC0%0/1
$r->headers_out || (return err())
$r->headers_out
Truth table0%0/2
A
A= $r->headers_out
Aresult
11
00
2231 0 $headers_out_hr->{'Location'}=$location;
2232 0 $r->status(HTTP_FOUND);
2233 0 ▶ $r->send_http_header if !$MP2;
Branch: 1 branch
BranchTrueFalseTotal
unless $WebDyne::MP2 0 0 0
2234 0 return HTTP_FOUND;
2235  
2236 }
2237 }
2238 0 ▶ if (my $uri=$param_hr->{'uri'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $uri = $param_hr->{'uri'}) { } 0 0 0
elsif (my $file = $param_hr->{'file'}) { } 0 0 0
2239  
2240 # Handle internally if possible
2241 #
2242 0 ▶ if (UNIVERSAL::can($r, 'internal_redirect')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($r, 'internal_redirect')) { } 0 0 0
2243  
2244  
2245 # Let the request handler take care of it
2246 #
2247 0 debug('handler does internal_redirect, handing off');
2248 0 $r->internal_redirect($uri); # no return value
2249 0 return $r->status;
2250  
2251 }
2252 else {
2253  
2254 # Must do it ourselves
2255 #
2256 0 ▶ $r_child=$r->lookup_uri($uri) ||
Condition0%0/2
$r->lookup_uri($uri) || (return err('undefined lookup_uri error'))
l!l
00
MC/DC0%0/1
$r->lookup_uri($uri) || (return err('undefined lookup_uri error'))
$r->lookup_uri($uri)
Truth table0%0/2
A
A= $r->lookup_uri($uri)
Aresult
11
00
2257 return err('undefined lookup_uri error');
2258 0 debug('r_child handler %s', $r->handler());
2259 0 $r->headers_out($r_child->headers_out());
2260 0 $r->uri($uri);
2261  
2262 }
2263  
2264  
2265 }
2266 elsif (my $file=$param_hr->{'file'}) {
2267  
2268 # Get cwd, make request absolute rel to cwd if no dir given.
2269 #
2270 0 my $dn=(File::Spec->splitpath($r->filename()))[1];
2271 0 my $file_pn=File::Spec->rel2abs($file, $dn);
2272  
2273  
2274 # Get a new request object
2275 #
2276 0 ▶ $r_child=$r->lookup_file($file_pn) ||
Condition0%0/2
$r->lookup_file($file_pn) || (return err('undefined lookup_file error'))
l!l
00
MC/DC0%0/1
$r->lookup_file($file_pn) || (return err('undefined lookup_file error'))
$r->lookup_file($file_pn)
Truth table0%0/2
A
A= $r->lookup_file($file_pn)
Aresult
11
00
2277 return err('undefined lookup_file error');
2278 0 $r->headers_out($r_child->headers_out());
2279  
2280 }
2281 else {
2282  
2283  
2284 # Must be one or other
2285 #
2286 0 return err('must specify file, uri or locations for subrequest');
2287  
2288 }
2289  
2290  
2291 # Save child object, else cleanup handlers will be run when
2292 # we exit and r_child is destroyed, but before r (main) is
2293 # complete.
2294 #
2295 # UPDATE no longer needed, leave here as reminder though ..
2296 #
2297 #push @{$self->{'_r_child'}},$r_child;
2298  
2299  
2300 # Safty check after calling getting r_child - should always be
2301 # OK, but do sanity check.
2302 #
2303 0 my $status=$r_child->status();
2304 0 debug("r_child status return: $status");
2305 0 ▶ if (($status && !is_success($status)) || (my $errstr=errstr())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status and not &is_success($status) or my $errstr = errstr()) 0 0 0
Condition0%0/6
$status and not &is_success($status) or my $errstr = errstr()
l!l&&r!l&&!r
000
$status and not &is_success($status)
!ll&&!rl&&r
000
MC/DC0%0/3
$status and not &is_success($status) or my $errstr = errstr()
$status not &is_success($status) my $errstr = errstr()
Truth table0%0/5
A and not(B) or C
A= $statusB= not &is_success($status)C= my $errstr = errstr()
ABCresult
11X1
0X11
1011
0X00
1000
2306 0 ▶ if ($errstr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errstr) { } 0 0 0
2307 return errsubst(
2308 "error in status phase of subrequest to '%s': $errstr",
2309 0 ▶ $r_child->uri() || $param_hr->{'file'}
Condition0%0/3
$r_child->uri || $param_hr->{'file'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$r_child->uri || $param_hr->{'file'}
$r_child->uri $param_hr->{'file'}
Truth table0%0/3
A || B
A= $r_child->uriB= $param_hr->{'file'}
ABresult
1X1
011
000
2310 )
2311 }
2312 else {
2313 return err(
2314 "error in status phase of subrequest to '%s', return status was $status",
2315 0 ▶ $r_child->uri() || $param_hr->{'file'}
Condition0%0/3
$r_child->uri || $param_hr->{'file'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$r_child->uri || $param_hr->{'file'}
$r_child->uri $param_hr->{'file'}
Truth table0%0/3
A || B
A= $r_child->uriB= $param_hr->{'file'}
ABresult
1X1
011
000
2316 )
2317 }
2318 }
2319  
2320  
2321 # Debug
2322 #
2323 0 debug('cgi param %s', Dumper($param_hr->{'param'}));
2324  
2325  
2326 # Set up CGI with any new params
2327 #
2328 0 ▶ while (my ($param, $value)=each %{$param_hr->{'param'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$param_hr{"param"};}) 0 0 0
2329  
2330  
2331 # Add to CGI
2332 #
2333 0 $cgi_or->param($param, $value);
2334 0 debug("set cgi param $param, value $value");
2335  
2336  
2337 }
2338  
2339  
2340 # Debug
2341 #
2342 0 debug("about to call child handler with params self $self %s", Dumper($param_hr->{'param'}));
2343  
2344  
2345 # Change of plan - used to check result, but now pass back whatever the child returns - we
2346 # will let Apache handle any errors internally
2347 #
2348 0 ▶ defined($status=(ref($r_child)=~/^WebDyne::/) ? $r_child->run($self) : $r_child->run()) ||
Branch: 2 branches
BranchTrueFalseTotal
defined($status = ref($r_child) =~ /^WebDyne::/ ? $r_child->run($self) : $r_child->run) or return err() 0 0 0
ref($r_child) =~ /^WebDyne::/ ? : 0 0 0
2349 return err();
2350 0 debug("r_child run return status $status, rc_child status %s", $r_child->status());
2351 0 ▶ return $status || $r_child->status();
Condition0%0/3
$status || $r_child->status
l!l&&r!l&&!r
000
MC/DC0%0/2
$status || $r_child->status
$status $r_child->status
Truth table0%0/3
A || B
A= $statusB= $r_child->status
ABresult
1X1
011
000
2352  
2353  
2354 }
2355  
2356  
2357 sub eof {
2358  
2359 0 ▶ goto HANDLER_COMPLETE;
Subroutine eof: not called CC=1 SCAR=6.9
Pod undocumented
2360  
2361 }
2362  
2363  
2364 sub erase_block {
2365  
2366 # Erase a block section so not rendered if encountered again
2367 #
2368 0 ▶ my ($self, $param_hr)=@_;
Subroutine erase_block: not called CC=4 SCAR=30.0
Pod undocumented
2369  
2370  
2371 # Has user only given name as param
2372 #
2373 0 ▶ ref($param_hr) || ($param_hr={name => $param_hr, param => {@_[2..$#_]}});
Branch: 1 branch
BranchTrueFalseTotal
ref $param_hr or $param_hr = {"name", $param_hr, "param", {@_[2 .. $#_]}} 0 0 0
2374  
2375  
2376 # Get block name
2377 #
2378 0 ▶ my $name=$param_hr->{'name'} || $param_hr->{'block'} ||
Condition0%0/5
$param_hr->{'name'} || $param_hr->{'block'} || (return err('no block name specified'))
l!l
00
$param_hr->{"name"} or $param_hr->{"block"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$param_hr->{'name'} || $param_hr->{'block'} || (return err('no block name specified'))
$param_hr->{"name"} $param_hr->{"block"}
Truth table0%0/3
A or B
A= $param_hr->{"name"}B= $param_hr->{"block"}
ABresult
1X1
011
000
2379 return err('no block name specified');
2380 0 debug("in erase_block, name $name");
2381 0 delete $self->{'_block_param'}{$name};
2382 0 delete $self->{'_block_render'}{$name}
2383  
2384 }
2385  
2386  
2387 sub unrender_block {
2388  
2389 # Synonym for erase_block
2390 #
2391 0 ▶ return shift()->erase_block(@_);
Subroutine unrender_block: not called CC=1 SCAR=6.9
Pod undocumented
2392  
2393 }
2394  
2395  
2396 sub render_block {
2397  
2398  
2399 # Render a <block> section of HTML
2400 #
2401 0 ▶ my ($self, $param_hr)=@_;
Subroutine render_block: not called CC=17 SCAR=57.2
Pod undocumented
2402  
2403  
2404 # Has user only given name as param
2405 #
2406 0 ▶ ref($param_hr) || ($param_hr={name => $param_hr, param => {@_[2..$#_]}});
Branch: 1 branch
BranchTrueFalseTotal
ref $param_hr or $param_hr = {"name", $param_hr, "param", {@_[2 .. $#_]}} 0 0 0
2407  
2408  
2409 # Get block name
2410 #
2411 0 ▶ my $name=$param_hr->{'name'} || $param_hr->{'block'} ||
Condition0%0/5
$param_hr->{'name'} || $param_hr->{'block'} || (return err('no block name specified'))
l!l
00
$param_hr->{"name"} or $param_hr->{"block"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$param_hr->{'name'} || $param_hr->{'block'} || (return err('no block name specified'))
$param_hr->{"name"} $param_hr->{"block"}
Truth table0%0/3
A or B
A= $param_hr->{"name"}B= $param_hr->{"block"}
ABresult
1X1
011
000
2412 return err('no block name specified');
2413 0 debug("in render_block, name $name");
2414  
2415  
2416 # Get current data block
2417 #
2418 #my $data_ar=$self->{'_perl'}[0] ||
2419 #return err("unable to get current data node");
2420 0 ▶ my $data_ar=$self->{'_perl'}[0] || do {
Condition0%0/3
$self->{'_perl'}[0] || do { push @{$self->{'_block_param'}{$name} ||= [];}, $param_hr->{'param'}; return \(undef) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_perl'}[0] || do { push @{$self->{'_block_param'}{$name} ||= [];}, $param_hr->{'param'}; return \(undef) }
$self->{'_perl'}[0] do { push @{$self->{'_block_param'}{$name} ||= [];}, $param_hr->{'param'}; return \(undef) }
Truth table0%0/3
A || B
A= $self->{'_perl'}[0]B= do { push @{$self->{'_block_param'}{$name} ||= [];}, $param_hr->{'param'}; return \(undef) }
ABresult
1X1
011
000
2421  
2422 #if ($WEBDYNE_DELAYED_BLOCK_RENDER) {
2423 0 ▶ push @{$self->{'_block_param'}{$name} ||= []}, $param_hr->{'param'}; # if $WEBDYNE_DELAYED_BLOCK_RENDER;
Condition0%0/2
$self->{"_block_param"}{$name} ||= []
l!l
00
MC/DC0%0/1
$self->{"_block_param"}{$name} ||= []
$self->{"_block_param"}{$name}
Truth table0%0/2
A
A= $self->{"_block_param"}{$name}
Aresult
11
00
2424 0 return \undef;
2425  
2426 #}
2427 #else {
2428 # return err("unable to get current data node")
2429 #}
2430 };
2431  
2432  
2433 # Find block name
2434 #
2435 0 my @data_block_ar;
2436  
2437  
2438 # Debug
2439 #
2440 0 debug("render_block self $self, name $name, data_ar $data_ar, %s", Dumper($data_ar));
2441  
2442  
2443 # Have we seen this search befor ?
2444 #
2445 0 ▶ unless (exists($self->{'_block_cache'}{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_block_cache'}{$name}) { } 0 0 0
2446  
2447  
2448 # No, search for block
2449 #
2450 0 debug("searching for node $name in data_ar");
2451  
2452  
2453 # Do it
2454 #
2455 0 ▶ my $data_block_all_ar=$self->find_node(
Condition0%0/2
$self->find_node({'data_ar', $data_ar, 'tag', 'block', 'all_fg', 1}) || (return err())
l!l
00
MC/DC0%0/1
$self->find_node({'data_ar', $data_ar, 'tag', 'block', 'all_fg', 1}) || (return err())
$self->find_node({'data_ar', $data_ar, 'tag', 'block', 'all_fg', 1})
Truth table0%0/2
A
A= $self->find_node({'data_ar', $data_ar, 'tag', 'block', 'all_fg', 1})
Aresult
11
00
2456 {
2457  
2458 data_ar => $data_ar,
2459 tag => 'block',
2460 all_fg => 1,
2461  
2462 }) || return err();
2463  
2464  
2465 # Debug
2466 #
2467 0 debug('find_node returned %s', join('*', @{$data_block_all_ar}));
2468  
2469  
2470 # Go through each block found and svae in block_cache
2471 #
2472 0 foreach my $data_block_ar (@{$data_block_all_ar}) {
2473  
2474  
2475 # Get block name
2476 #
2477 0 my $name=$data_block_ar->[WEBDYNE_NODE_ATTR_IX]->{'name'};
2478 0 debug("looking at block $data_block_ar, name $name");
2479  
2480  
2481 # Save
2482 #
2483 #$self->{'_block_cache'}{$name}=$data_block_ar;
2484 0 ▶ push @{$self->{'_block_cache'}{$name} ||= []}, $data_block_ar;
Condition0%0/2
$self->{"_block_cache"}{$name} ||= []
l!l
00
MC/DC0%0/1
$self->{"_block_cache"}{$name} ||= []
$self->{"_block_cache"}{$name}
Truth table0%0/2
A
A= $self->{"_block_cache"}{$name}
Aresult
11
00
2485  
2486  
2487 }
2488  
2489  
2490 # Done, store
2491 #
2492 0 @data_block_ar=@{$self->{'_block_cache'}{$name}};
2493  
2494  
2495 }
2496 else {
2497  
2498  
2499 # Yes, set data_block_ar to whatever we saw before, even if it is
2500 # undef
2501 #
2502 0 @data_block_ar=@{$self->{'_block_cache'}{$name}};
2503  
2504  
2505 # Debug
2506 #
2507 0 debug("retrieved data_block_ar @data_block_ar for node $name from cache");
2508  
2509  
2510 }
2511  
2512  
2513 # Debug
2514 #
2515 #debug("set block node to $data_block_ar %s", Dumper($data_block_ar));
2516  
2517  
2518 # Store params for later block render (outside perl block) if needed
2519 #
2520 0 ▶ push @{$self->{'_block_param'}{$name} ||= []}, $param_hr->{'param'}; # if $WEBDYNE_DELAYED_BLOCK_RENDER;
Condition0%0/2
$self->{"_block_param"}{$name} ||= []
l!l
00
MC/DC0%0/1
$self->{"_block_param"}{$name} ||= []
$self->{"_block_param"}{$name}
Truth table0%0/2
A
A= $self->{"_block_param"}{$name}
Aresult
11
00
2521  
2522  
2523 # No data_block_ar ? Could not find block - remove this line if global block
2524 # rendering is desired (ie blocks may lay outside perl code calling render_bloc())
2525 #
2526 0 ▶ unless (@data_block_ar) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@data_block_ar) 0 0 0
2527  
2528 #if ($WEBDYNE_DELAYED_BLOCK_RENDER) {
2529 0 return \undef;
2530  
2531 #}
2532 #else {
2533 # return err("could not find block '$name' to render") unless $WEBDYNE_DELAYED_BLOCK_RENDER;
2534 #}
2535 }
2536  
2537  
2538 # Now, was it set to something ?
2539 #
2540 0 my @html_sr;
2541 0 foreach my $data_block_ar (@data_block_ar) {
2542  
2543  
2544 # Debug
2545 #
2546 0 debug("rendering block name $name, data $data_ar with param %s", Dumper($param_hr->{'param'}));
2547  
2548  
2549 # Yes, Get HTML for block immedialtly
2550 #
2551 my $html_sr=$self->render_data_ar(
2552 data => $data_block_ar->[WEBDYNE_NODE_CHLD_IX],
2553 0 ▶ param => $param_hr->{'param'},
Condition0%0/2
$self->render_data_ar('data', $data_block_ar->[2], 'param', $param_hr->{'param'}) || (return err())
l!l
00
MC/DC0%0/1
$self->render_data_ar('data', $data_block_ar->[2], 'param', $param_hr->{'param'}) || (return err())
$self->render_data_ar('data', $data_block_ar->[2], 'param', $param_hr->{'param'})
Truth table0%0/2
A
A= $self->render_data_ar('data', $data_block_ar->[2], 'param', $param_hr->{'param'})
Aresult
11
00
2554 ) || return err();
2555  
2556  
2557 # Debug
2558 #
2559 0 debug("block $name rendered HTML $html_sr %s, pushing onto name $name, data_ar $data_block_ar", ${$html_sr});
2560  
2561  
2562 # Store away for this block
2563 #
2564 0 ▶ push @{$self->{'_block_render'}{$name}{$data_block_ar} ||= []}, $html_sr;
Condition0%0/2
$self->{"_block_render"}{$name}{$data_block_ar} ||= []
l!l
00
MC/DC0%0/1
$self->{"_block_render"}{$name}{$data_block_ar} ||= []
$self->{"_block_render"}{$name}{$data_block_ar}
Truth table0%0/2
A
A= $self->{"_block_render"}{$name}{$data_block_ar}
Aresult
11
00
2565  
2566  
2567 # Store
2568 #
2569 0 push @html_sr, $html_sr;
2570  
2571  
2572 }
2573 0 ▶ if (@html_sr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@html_sr) { } 0 0 0
2574  
2575  
2576 # Return scalar or array ref, depending on number of elements
2577 #
2578 #debug('returning %s', Dumper(\@html_sr));
2579 0 ▶ return (@html_sr==1) ? $html_sr[0] : \@html_sr;
Branch: 1 branch
BranchTrueFalseTotal
@html_sr == 1 ? : 0 0 0
2580  
2581 }
2582 else {
2583  
2584  
2585 # No, could not find block below us, store param away for later
2586 # render. NOTE now done for all blocks so work both in and out of
2587 # <perl> section. Moved this code above
2588 #
2589 #push @{$self->{'_block_param'}{$name} ||=[]},$param_hr->{'param'};
2590  
2591  
2592 # Debug
2593 #
2594 0 debug("block $name not found in tree, storing params for later render");
2595  
2596  
2597 # Done, return undef at this stage
2598 #
2599 0 return \undef;
2600  
2601 }
2602  
2603  
2604 }
2605  
2606  
2607 sub block {
2608  
2609  
2610 # Called when we encounter a <block> tag
2611 #
2612 0 ▶ my ($self, $data_ar, $attr_hr, $param_data_hr, $text)=@_;
Subroutine block: not called CC=9 SCAR=45.0
Pod undocumented
2613 0 debug("in block code, data_ar $data_ar");
2614  
2615  
2616 # Get block name
2617 #
2618 0 ▶ my $name=$attr_hr->{'name'} ||
Condition0%0/2
$attr_hr->{'name'} || (return err('no block name specified'))
l!l
00
MC/DC0%0/1
$attr_hr->{'name'} || (return err('no block name specified'))
$attr_hr->{'name'}
Truth table0%0/2
A
A= $attr_hr->{'name'}
Aresult
11
00
2619 return err('no block name specified');
2620 0 debug("in block, looking for name $name, attr given %s", Dumper($attr_hr));
2621  
2622  
2623 # Only render if registered, do once for every time spec'd
2624 #
2625 0 ▶ if (exists($self->{'_block_render'}{$name}{$data_ar})) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $self->{'_block_render'}{$name}{$data_ar}) { } 0 0 0
elsif (exists $self->{'_block_param'}{$name}) { } 0 0 0
elsif ($attr_hr->{'display'}) { } 0 0 0
2626  
2627  
2628 # The block name has been pre-rendered - return it
2629 #
2630 0 debug("found pre-rendered block $name");
2631  
2632  
2633 # Var to hold render result
2634 #
2635 0 my $html_ar=delete $self->{'_block_render'}{$name}{$data_ar};
2636  
2637  
2638 # Return result as a single scalar ref
2639 #
2640 0 return \join(undef, map {${$_}} @{$html_ar});
2641  
2642  
2643 }
2644 elsif (exists($self->{'_block_param'}{$name})) {
2645  
2646  
2647 # The block params have been registered, but the block itself was
2648 # not yet rendered. Do it now
2649 #
2650 0 debug("found block param for $name in register");
2651  
2652  
2653 # Var to hold render result
2654 #
2655 0 my @html_sr;
2656  
2657  
2658 # Render the block for as many times as it has parameters associated
2659 # with it, eg user may have called ->render_block several times in
2660 # their code
2661 #
2662 0 foreach my $param_data_block_hr (@{$self->{'_block_param'}{$name}}) {
2663  
2664  
2665 # If no explicit data hash, use parent hash - not sure how useful
2666 # this really is
2667 #
2668 0 ▶ $param_data_block_hr ||= $param_data_hr;
Condition0%0/3
$param_data_block_hr ||= $param_data_hr
l!l&&r!l&&!r
000
MC/DC0%0/2
$param_data_block_hr ||= $param_data_hr
$param_data_block_hr $param_data_hr
Truth table0%0/3
A ||= B
A= $param_data_block_hrB= $param_data_hr
ABresult
1X1
011
000
2669  
2670  
2671 # Debug
2672 #
2673 0 debug("about to render block $name, param %s", Dumper($param_data_block_hr));
2674  
2675  
2676 # Render it
2677 #
2678 0 ▶ push @html_sr, $self->render_data_ar(
Condition0%0/2
$self->render_data_ar('data', $data_ar->[2], 'param', $param_data_block_hr) || (return err())
l!l
00
MC/DC0%0/1
$self->render_data_ar('data', $data_ar->[2], 'param', $param_data_block_hr) || (return err())
$self->render_data_ar('data', $data_ar->[2], 'param', $param_data_block_hr)
Truth table0%0/2
A
A= $self->render_data_ar('data', $data_ar->[2], 'param', $param_data_block_hr)
Aresult
11
00
2679 data => $data_ar->[WEBDYNE_NODE_CHLD_IX],
2680 param => $param_data_block_hr
2681 ) || return err();
2682  
2683 }
2684  
2685  
2686 # Return result as a single scalar ref
2687 #
2688 0 return \join(undef, map {${$_}} @html_sr);
2689  
2690 }
2691 elsif ($attr_hr->{'display'}) {
2692  
2693  
2694 # User wants block displayed normally
2695 #
2696 0 ▶ return $self->render_data_ar(
Condition0%0/3
$self->render_data_ar('data', $data_ar->[2], 'param', $param_data_hr) || err()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->render_data_ar('data', $data_ar->[2], 'param', $param_data_hr) || err()
$self->render_data_ar('data', $data_ar->[2], 'param', $param_data_hr) err()
Truth table0%0/3
A || B
A= $self->render_data_ar('data', $data_ar->[2], 'param', $param_data_hr)B= err()
ABresult
1X1
011
000
2697 data => $data_ar->[WEBDYNE_NODE_CHLD_IX],
2698 param => $param_data_hr
2699 ) || err();
2700  
2701 }
2702 else {
2703  
2704  
2705 # Block name not registered, therefore do not render - return
2706 # blank
2707 #
2708 0 return \undef;
2709  
2710 }
2711  
2712  
2713 }
2714  
2715  
2716 sub json {
2717  
2718  
2719 # Called when we encounter a <json> tag
2720 #
2721 0 ▶ my ($self, $data_ar, $attr_hr, $param_data_hr, $text)=@_;
Subroutine json: not called CC=13 SCAR=52.0
Pod undocumented
2722 0 debug("$self rendering json tag in block $data_ar, attr %s", $attr_hr);
2723  
2724  
2725 # Check we have a handler
2726 #
2727 0 ▶ $attr_hr->{'handler'} || $attr_hr->{'perl'} ||
Branch: 1 branch
BranchTrueFalseTotal
$attr_hr->{"handler"} or $attr_hr->{"perl"} or return err("no json tag perl handler supplied") 0 0 0
Condition0%0/3
$attr_hr->{"handler"} or $attr_hr->{"perl"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr_hr->{"handler"} or $attr_hr->{"perl"}
$attr_hr->{"handler"} $attr_hr->{"perl"}
Truth table0%0/3
A or B
A= $attr_hr->{"handler"}B= $attr_hr->{"perl"}
ABresult
1X1
011
000
2728 return err('no json tag perl handler supplied');
2729  
2730  
2731 # Run the code in perl routine specifying it is JSON, get return ref of
2732 # some kind
2733 #
2734 0 ▶ defined(my $json_xr=$self->perl($data_ar, {json => 1, %{$attr_hr}})) ||
Branch: 1 branch
BranchTrueFalseTotal
defined(my $json_xr = $self->perl($data_ar, {"json", 1, %{$attr_hr;}})) or return err() 0 0 0
2735 return err();
2736 0 ▶ if (ref($json_xr) eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json_xr eq "SCALAR") 0 0 0
2737 0 $json_xr=${$json_xr}
2738 }
2739 0 debug("json_xr %s", Dumper($json_xr));
2740  
2741  
2742 # Convert to JSON
2743 #
2744 0 require JSON;
2745 0 ▶ my $json_or=JSON->new() ||
Condition0%0/2
'JSON'->new || (return err('unable to create new JSON object'))
l!l
00
MC/DC0%0/1
'JSON'->new || (return err('unable to create new JSON object'))
'JSON'->new
Truth table0%0/2
A
A= 'JSON'->new
Aresult
11
00
2746 return err('unable to create new JSON object');
2747 0 $json_or->allow_nonref(1);
2748 #$json_or->allow_blessed(1);
2749 #$json_or->convert_blessed(1);
2750 0 debug("json_or: $json_or");
2751 0 ▶ $json_or->canonical(defined($attr_hr->{'canonical'}) ? ($attr_hr->{'canonical'} ? 1 : 0) : WEBDYNE_JSON_CANONICAL);
Branch: 2 branches
BranchTrueFalseTotal
defined $attr_hr->{'canonical'} ? : 0 0 0
$attr_hr->{'canonical'} ? : 0 0 0
2752 0 ▶ $json_or->pretty(defined($attr_hr->{'pretty'}) ? ($attr_hr->{'pretty'} ? 1 : 0) : WEBDYNE_JSON_PRETTY);
Branch: 2 branches
BranchTrueFalseTotal
defined $attr_hr->{'pretty'} ? : 0 0 0
$attr_hr->{'pretty'} ? : 0 0 0
2753 0 ▶ my $json=eval {$json_or->encode($json_xr)} ||
Condition0%0/2
eval { do { $json_or->encode($json_xr) } } || (return err('error %s on json_encode of %s', $@, Dumper($json_xr)))
l!l
00
MC/DC0%0/1
eval { do { $json_or->encode($json_xr) } } || (return err('error %s on json_encode of %s', $@, Dumper($json_xr)))
eval { do { $json_or->encode($json_xr) } }
Truth table0%0/2
A
A= eval { do { $json_or->encode($json_xr) } }
Aresult
11
00
2754 return err('error %s on json_encode of %s', $@, Dumper($json_xr));
2755 0 debug("json %s", Dumper($json));
2756  
2757  
2758 # Get new WebDyne::HTML::Tiny object ready to encode result into <script> tag
2759 #
2760 0 ▶ my $html_or=$self->{'_html_tiny_or'} || $self->html_tiny() ||
Condition0%0/5
$self->{'_html_tiny_or'} || $self->html_tiny || (return err())
l!l
00
$self->{"_html_tiny_or"} or $self->html_tiny
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_html_tiny_or'} || $self->html_tiny || (return err())
$self->{"_html_tiny_or"} $self->html_tiny
Truth table0%0/3
A or B
A= $self->{"_html_tiny_or"}B= $self->html_tiny
ABresult
1X1
011
000
2761 return err();
2762 my %attr=(
2763 type => 'application/json',
2764 0 %{$attr_hr}
2765
2766 );
2767 0 delete @attr{qw(perl package method handler pretty canonical)};
2768  
2769  
2770 # Render and return
2771 #
2772 0 my $html=$html_or->script(\%attr, $json);
2773 0 debug("generated HTML: $html");
2774 0 return \$html
2775  
2776 }
2777  
2778  
2779 sub htmx {
2780  
2781  
2782 # Called when we encounter a <htmx> tag
2783 #
2784 0 ▶ my ($self, $data_ar, $attr_hr, @param)=@_;
Subroutine htmx: not called CC=15 SCAR=54.8
Pod undocumented
2785 0 debug("$self rendering htmx tag, data_ar: $data_ar, attr_hr: %s", Dumper($attr_hr));
2786
2787
2788 # Get the request headers to look for a 'HX-Request' flag
2789 #
2790 0 ▶ my $r=$self->r() ||
Condition0%0/2
$self->r || (return err('unable to get request handler !'))
l!l
00
MC/DC0%0/1
$self->r || (return err('unable to get request handler !'))
$self->r
Truth table0%0/2
A
A= $self->r
Aresult
11
00
2791 return err('unable to get request handler !');
2792 0 my $hx_request;
2793 0 foreach my $header (@{$WEBDYNE_HTTP_HEADER_AJAX_AR}) {
2794 0 ▶ last if ($hx_request=$r->headers_in->{$header});
Branch: 1 branch
BranchTrueFalseTotal
if $hx_request = $r->headers_in->{$header} 0 0 0
2795 }
2796 0 debug("hx_request header: $hx_request");
2797
2798
2799 # If not HTMX request don't display unless forced
2800 #
2801 0 ▶ unless($hx_request || $attr_hr->{'force'} || WEBDYNE_HTMX_FORCE) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hx_request or $attr_hr->{"force"} or 0) 0 0 0
Condition0%0/5
$hx_request or $attr_hr->{"force"} or 0
l!l
00
$hx_request or $attr_hr->{"force"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$hx_request or $attr_hr->{"force"} or 0
$hx_request $attr_hr->{"force"}
Truth table0%0/3
A or B
A= $hx_requestB= $attr_hr->{"force"}
ABresult
1X1
011
000
2802
2803  
2804 # Not HTMX request, bail
2805 #
2806 0 debug('not htmx request and no force attribute or flag, bailing');
2807 0 return \undef;
2808
2809 }
2810
2811
2812 # Check if we want to fire on match
2813 #
2814 0 ▶ if (exists ($attr_hr->{'display'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr_hr->{"display"}) 0 0 0
2815 0 ▶ unless ($attr_hr->{'display'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attr_hr->{"display"}) 0 0 0
2816 # Defined but no match. Bail
2817 #
2818 0 debug('display attribute present but no match, bailing');
2819 0 return \undef;
2820 }
2821 }
2822  
2823  
2824 # Check we have a handler
2825 #
2826 0 my $html_sr;
2827 0 ▶ if ((my $handler=$attr_hr->{'handler'}) || $attr_hr->{'perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $attr_hr->{'handler'} or $attr_hr->{'perl'}) { } 0 0 0
Condition0%0/3
my $handler = $attr_hr->{"handler"} or $attr_hr->{"perl"}
l!l&&r!l&&!r
000
MC/DC0%0/2
my $handler = $attr_hr->{"handler"} or $attr_hr->{"perl"}
my $handler = $attr_hr->{"handler"} $attr_hr->{"perl"}
Truth table0%0/3
A or B
A= my $handler = $attr_hr->{"handler"}B= $attr_hr->{"perl"}
ABresult
1X1
011
000
2828
2829
2830 # Return whatever HTML we get back
2831 #
2832 0 ▶ $handler ||= '*perl*';
Condition0%0/2
$handler ||= "*perl*"
l!l
00
MC/DC0%0/1
$handler ||= "*perl*"
$handler
Truth table0%0/2
A
A= $handler
Aresult
11
00
2833 0 debug("htmx rendering with handler: $handler");
2834 0 ▶ $html_sr=$self->perl($data_ar, $attr_hr) ||
Condition0%0/2
$self->perl($data_ar, $attr_hr) || (return err())
l!l
00
MC/DC0%0/1
$self->perl($data_ar, $attr_hr) || (return err())
$self->perl($data_ar, $attr_hr)
Truth table0%0/2
A
A= $self->perl($data_ar, $attr_hr)
Aresult
11
00
2835 return err();
2836 0 debug("html_sr: $html_sr, %s", Dumper($html_sr));
2837
2838 }
2839 else {
2840
2841 # No handler, just render
2842 #
2843 0 debug('htmx render without handler');
2844 0 ▶ $html_sr=$self->render_data_ar(data=> $data_ar->[WEBDYNE_NODE_CHLD_IX]) ||
Condition0%0/2
$self->render_data_ar('data', $data_ar->[2]) || (return err())
l!l
00
MC/DC0%0/1
$self->render_data_ar('data', $data_ar->[2]) || (return err())
$self->render_data_ar('data', $data_ar->[2])
Truth table0%0/2
A
A= $self->render_data_ar('data', $data_ar->[2])
Aresult
11
00
2845 return err();
2846 0 debug("html_sr: $html_sr, %s", Dumper($html_sr));
2847
2848 }
2849
2850
2851 # Done
2852 #
2853 0 ▶ if ($hx_request) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hx_request) { } 0 0 0
2854  
2855 # Return fragment only
2856 #
2857 0 debug('returning htmx tag as html fragment only');
2858 0 return $self->redirect( html=>$html_sr );
2859
2860 }
2861 else {
2862
2863 # Continue render and return whole page
2864 #
2865 0 debug('returning normal render of htmx tag into page');
2866 0 return $html_sr;
2867
2868 }
2869
2870 }
2871  
2872  
2873 sub api {
2874  
2875  
2876 # Called when we encounter a <api> tag
2877 #
2878 0 ▶ my ($self, $data_ar, $attr_hr)=@_;
Subroutine api: not called CC=9 SCAR=45.0
Pod undocumented
2879 0 debug("$self rendering api tag in block $data_ar, attr %s", Dumper($attr_hr));
2880
2881
2882 # Perl ?
2883 #
2884 0 my %attr=%{$attr_hr};
2885 0 ▶ if (my $perl=$attr{'perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $perl = $attr{"perl"}) 0 0 0
2886 0 $attr{'name'}='perl'
2887 }
2888
2889 # Need Router::Simple. Build params needed allowing for synonyms
2890 #
2891 0 require Router::Simple;
2892 0 my $rest_or=Router::Simple->new();
2893 0 my @route=(grep {$_}
2894 #@{$attr_hr}{qw(name method handler pattern match data dest destination)}
2895 0 @attr{qw(name method handler pattern match data dest destination)}
2896 );
2897 0 ▶ $route[2] ||= undef;
Condition0%0/2
$route[2] ||= undef
l!l
00
MC/DC0%0/1
$route[2] ||= undef
$route[2]
Truth table0%0/2
A
A= $route[2]
Aresult
11
00
2898 my @option=(grep ${_},
2899 #@{$attr_hr}{qw(option options constraint constraints)}
2900 0 @attr{qw(option options constraint constraints)}
2901 );
2902 0 debug('route param: %s, %s', Dumper(\@route, \@option));
2903 0 $rest_or->connect(@route, $option[0]);
2904
2905
2906 # Now look for match. Set PATH_INFO to '' if not exists to stop warning
2907 #
2908 0 ▶ $ENV{'PATH_INFO'} ||= '';
Condition0%0/2
$ENV{"PATH_INFO"} ||= ""
l!l
00
MC/DC0%0/1
$ENV{"PATH_INFO"} ||= ""
$ENV{"PATH_INFO"}
Truth table0%0/2
A
A= $ENV{"PATH_INFO"}
Aresult
11
00
2909
2910
2911 # And match
2912 #
2913 0 ▶ if (my $match_hr=$rest_or->match(\%ENV)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $match_hr = $rest_or->match(\%ENV)) { } 0 0 0
2914
2915  
2916 # We have a match
2917 #
2918 0 debug('route match: %s', Dumper(match_hr));
2919  
2920  
2921 # Run the code in perl routine specifying it is JSON, get return ref of
2922 # some kind
2923 #
2924 #my $json_xr=$self->perl(undef, {json => 1, %{$attr_hr}, param=>$match_hr }) ||
2925 #my $json_xr=$self->perl(undef, {json => 1, %attr, param=>$match_hr }) ||
2926 0 ▶ my $json_xr=$self->perl($data_ar, {json => 1, %attr, param=>$match_hr }) ||
Condition0%0/2
$self->perl($data_ar, {'json', 1, %attr, 'param', $match_hr}) || (return err())
l!l
00
MC/DC0%0/1
$self->perl($data_ar, {'json', 1, %attr, 'param', $match_hr}) || (return err())
$self->perl($data_ar, {'json', 1, %attr, 'param', $match_hr})
Truth table0%0/2
A
A= $self->perl($data_ar, {'json', 1, %attr, 'param', $match_hr})
Aresult
11
00
2927 return err();
2928 0 debug("json_xr %s", Dumper($json_xr));
2929  
2930  
2931 # Convert to JSON
2932 #
2933 0 require JSON;
2934 0 ▶ my $json_or=JSON->new() ||
Condition0%0/2
'JSON'->new || (return err('unable to create new JSON object'))
l!l
00
MC/DC0%0/1
'JSON'->new || (return err('unable to create new JSON object'))
'JSON'->new
Truth table0%0/2
A
A= 'JSON'->new
Aresult
11
00
2935 return err('unable to create new JSON object');
2936 0 $json_or->allow_nonref(1);
2937 0 debug("json_or: $json_or");
2938 0 ▶ $json_or->canonical(defined($attr_hr->{'canonical'}) ? $attr_hr->{'canonical'} : WEBDYNE_JSON_CANONICAL);
Branch: 1 branch
BranchTrueFalseTotal
defined $attr_hr->{'canonical'} ? : 0 0 0
2939 0 ▶ my $json=eval {$json_or->encode($json_xr)} ||
Condition0%0/2
eval { do { $json_or->encode($json_xr) } } || (return err('error %s on json_encode of %s', $@, Dumper($json_xr)))
l!l
00
MC/DC0%0/1
eval { do { $json_or->encode($json_xr) } } || (return err('error %s on json_encode of %s', $@, Dumper($json_xr)))
eval { do { $json_or->encode($json_xr) } }
Truth table0%0/2
A
A= eval { do { $json_or->encode($json_xr) } }
Aresult
11
00
2940 return err('error %s on json_encode of %s', $@, Dumper($json_xr));
2941 0 debug("json %s", Dumper($json));
2942
2943
2944 # Return as JSON data only
2945 #
2946 0 return $self->redirect( json => $json );
2947
2948 }
2949 else {
2950
2951 # No match
2952 #
2953 0 debug('no match');
2954 0 return \undef;
2955
2956 }
2957
2958 }
2959  
2960  
2961 sub perl {
2962  
2963  
2964 # Called when we encounter a <perl> tag
2965 #
2966 8 ▶ my ($self, $data_ar, $attr_hr, $param_data_hr, $text)=@_;
Subroutine perl: called CC=28 SCAR=49.1
Pod undocumented
2967 8 debug("$self rendering perl tag in block $data_ar, attr %s", Dumper($attr_hr));
2968
2969
2970 # Look for run param and if exists only run if value evaluates to true
2971 #
2972 8 ▶ if(exists $attr_hr->{'run'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr_hr->{"run"}) 0 8 8
2973 0 ▶ unless ($attr_hr->{'run'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attr_hr->{"run"}) 0 0 0
2974 0 debug('run attribute evaluated as false, not running');
2975 0 return \undef;
2976 }
2977 }
2978  
2979  
2980 # Add current working directory to @INC for any use or require commands
2981 # in perl code
2982 #
2983 8 local @INC=@INC;
2984 8 push @INC, $self->cwd();
2985  
2986  
2987 # HTML scalar ref to return, starts out empty
2988 #
2989 8 my $html_sr=\undef;
2990  
2991 # Get current inode
2992 #
2993 #my $inode=$self->{'_inode'} || 'ANON';
2994 8 ▶ my $inode=$self->{'_inode'} || $self->inode();
Condition33%1/3
$self->{'_inode'} || $self->inode
l!l&&r!l&&!r
800
MC/DC0%0/2
$self->{'_inode'} || $self->inode
$self->{'_inode'} $self->inode
Truth table33%1/3
A || B
A= $self->{'_inode'}B= $self->inode
ABresult
1X1
011
000
2995  
2996  
2997 # Load any modules spec'd by require attribute
2998 #
2999 8 ▶ if (my $require_fn=$attr_hr->{'require'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $require_fn = $attr_hr->{"require"}) 0 8 8
3000  
3001 # Eval string to build
3002 #
3003 0 debug("about to require $require_fn");
3004 0 ▶ $self->eval_require($require_fn, $attr_hr) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->eval_require($require_fn, $attr_hr) or return err() 0 0 0
3005 return err();
3006  
3007 }
3008  
3009  
3010 # Get current autonewline setting, set if defined
3011 #
3012 8 my $autonewline=$self->autonewline($attr_hr->{'autonewline'});
3013  
3014  
3015 # If inline, run now
3016 #
3017 8 ▶ if (my $perl_code=$attr_hr->{'perl'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $perl_code = $attr_hr->{'perl'}) { } 0 8 8
elsif (grep {$attr_hr->{$_};} 'package', 'method', 'handler') { } 8 0 8
3018
3019
3020  
3021  
3022 # May be inline code params to supply to this block
3023 #
3024 0 ▶ my $perl_param_hr=$attr_hr->{'param'} || $self->{'_perl_data'}[0];
Condition0%0/3
$attr_hr->{'param'} || $self->{'_perl_data'}[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr_hr->{'param'} || $self->{'_perl_data'}[0]
$attr_hr->{'param'} $self->{'_perl_data'}[0]
Truth table0%0/3
A || B
A= $attr_hr->{'param'}B= $self->{'_perl_data'}[0]
ABresult
1X1
011
000
3025 0 debug("found inline perl code %s, param %s", Dumper(\$perl_code, $perl_param_hr));
3026  
3027  
3028 # Run the same code as the inline eval (!{! ... !}) would run,
3029 # for consistancy
3030 #
3031 0 ▶ $html_sr=$Package{'_eval_cr'}{'!'}->($self, $data_ar, $perl_param_hr, $perl_code) ||
Condition0%0/2
$WebDyne::Package{'_eval_cr'}{'!'}->($self, $data_ar, $perl_param_hr, $perl_code) || (return err())
l!l
00
MC/DC0%0/1
$WebDyne::Package{'_eval_cr'}{'!'}->($self, $data_ar, $perl_param_hr, $perl_code) || (return err())
$WebDyne::Package{'_eval_cr'}{'!'}->($self, $data_ar, $perl_param_hr, $perl_code)
Truth table0%0/2
A
A= $WebDyne::Package{'_eval_cr'}{'!'}->($self, $data_ar, $perl_param_hr, $perl_code)
Aresult
11
00
3032 return err();
3033
3034
3035  
3036 }
3037 24 elsif (grep {$attr_hr->{$_}} qw(package method handler)) {
3038  
3039  
3040 # Not inline, must want to call a handler, get method and caller. package synonym for class, method for handler
3041 #
3042 8 ▶ my $function=join('::', grep {$_} map {exists($attr_hr->{$_}) && $attr_hr->{$_}} qw(package method handler)) ||
Branch: 1 branch
BranchTrueFalseTotal
exists $attr_hr->{$_} and $attr_hr->{$_} 8 16 24
Condition50%1/2
join('::', grep({$_;} map({exists $attr_hr->{$_} and $attr_hr->{$_};} 'package', 'method', 'handler'))) || (return err('could not determine perl routine to run'))
l!l
80
MC/DC0%0/1
join('::', grep({$_;} map({exists $attr_hr->{$_} and $attr_hr->{$_};} 'package', 'method', 'handler'))) || (return err('could not determine perl routine to run'))
join('::', grep({$_;} map({exists $attr_hr->{$_} and $attr_hr->{$_};} 'package', 'method', 'handler')))
Truth table50%1/2
A
A= join('::', grep({$_;} map({exists $attr_hr->{$_} and $attr_hr->{$_};} 'package', 'method', 'handler')))
Aresult
11
00
3043 return err('could not determine perl routine to run');
3044 8 debug("found call to perl function: $function");
3045  
3046  
3047 # Try to get the package name as an array, pop the method off
3048 #
3049 8 my @package=split(/\:+/, $function);
3050 8 my $method=pop @package;
3051  
3052  
3053 # And return package
3054 #
3055 8 my $package=join('::', grep {$_} @package);
3056  
3057  
3058 # Debug
3059 #
3060 8 debug("perl package: $package, method $method");
3061  
3062  
3063 # If no method by now, dud caller
3064 #
3065 8 ▶ $method ||
Branch: 1 branch
BranchTrueFalseTotal
$method or return err("no handler found in perl tag") 0 8 8
3066 return err("no handler found in perl tag");
3067  
3068  
3069 # Need to load a package
3070 #
3071 8 ▶ if ($package) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package) 0 8 8
3072 0 debug("about to require $package");
3073 0 ▶ $self->eval_require($package, $attr_hr) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->eval_require($package, $attr_hr) or return err() 0 0 0
3074 return err()
3075 }
3076  
3077 # Push data_ar so we can use it if the perl routine calls self->render(). render()
3078 # then has to "know" where it is in the data_ar structure, and can get that info
3079 # here.
3080 #
3081 #unshift @{$self->{'_perl'}}, $data_ar->[$WEBDYNE_NODE_CHLD_IX];
3082 8 unshift @{$self->{'_perl'}}, $data_ar;
3083 8 debug("unshift $data_ar onto perl stack, stack:%s", join('*', @{$self->{'_perl'}}));
3084  
3085  
3086 # Contruct subroutine call
3087 #
3088 8 ▶ unless ($function=~/::/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($function =~ /::/) 8 0 8
3089 8 $function="WebDyne::${inode}::${function}"
3090 }
3091 8 debug("about to eval $function");
3092
3093
3094 # Inherit params from data stack and add any supplied here
3095 #
3096 8 my (%param, $param_scalar);
3097 8 ▶ if (exists ($attr_hr->{'param'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr_hr->{"param"}) 0 8 8
3098 0 ▶ if (ref($attr_hr->{'param'}) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $attr_hr->{'param'} eq 'HASH') { } 0 0 0
elsif (not ref $attr_hr->{'param'}) { } 0 0 0
3099 0 %param=(%{$self->{'_perl_data'}[0]}, %{$attr_hr->{'param'}});
3100 }
3101 elsif (!ref($attr_hr->{'param'})) {
3102 0 $param_scalar=$attr_hr->{'param'};
3103 }
3104 else {
3105 0 return err("perl param attribute is %s ref, must be HASH ref or plain scalar", ref($attr_hr->{'param'}));
3106 }
3107 }
3108
3109
3110 # If want json set tag_fg to 1 so eval doesn't try and process. If we don't want json then tag_fg is set to
3111 # false which is default and fine.
3112 #
3113 8 my $tag_fg=$attr_hr->{'json'};
3114  
3115  
3116 # Run the eval code to get HTML. Various previous iterations get for reference
3117 #
3118 #$html_sr=$Package{'_eval_cr'}{'!'}->($self, $data_ar, $attr_hr->{'param'}, "&${function}") || do {
3119 #$html_sr=$Package{'_eval_cr'}{'!'}->($self, $data_ar, \%param, "&${function}") || do {
3120 #$html_sr=$Package{'_eval_cr'}{'!'}->($self, $data_ar, $param_scalar ? $param_scalar : \%param, "&${function}") || do {
3121 8 ▶ defined($html_sr=$Package{'_eval_cr'}{'!'}->($self, $data_ar, $param_scalar ? $param_scalar : \%param, "&${function}", undef, $tag_fg)) || do {
Branch: 2 branches
BranchTrueFalseTotal
defined($html_sr = $WebDyne::Package{"_eval_cr"}{"!"}->($self, $data_ar, $param_scalar ? $param_scalar : \%param, "&$function", undef, $tag_fg)) or do { debug("error occured on eval, passing to error handler, $@"); shift @{$$self{"_perl"};}; debug("shift off perl stack, stack:%s", join("*", @{$self->{"_perl"};})); return err() } 0 6 6
$param_scalar ? : 0 8 8
3122  
3123  
3124 # Error occurred. Pop data ref off stack and return
3125 #
3126 0 debug("error occured on eval, passing to error handler, $@");
3127 0 shift @{$self->{'_perl'}};
3128 0 debug("shift off perl stack, stack:%s", join('*', @{$self->{'_perl'}}));
3129 0 return err();
3130  
3131  
3132 };
3133  
3134  
3135 # Debug
3136 #
3137 #debug('perl eval return %s', Dumper($html_sr));
3138  
3139  
3140 # Return if we want the data for a JSON tag (above)
3141 #
3142 6 debug('attr: %s', Dumper($attr_hr));
3143 6 ▶ if (!$attr_hr->{'json'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $attr_hr->{'json'}) { } 6 0 6
3144 6 ▶ if ((my $ref=ref($html_sr)) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ((my $ref = ref $html_sr) eq 'HASH') { } 0 6 6
elsif ($ref ne 'SCALAR') { } 0 6 6
3145  
3146 # Render with HASH ref supplied.
3147 #
3148 0 debug('HASH ref detected, rendering');
3149 0 ▶ $html_sr=$self->render(%{$html_sr}) ||
Condition0%0/2
$self->render(%{$html_sr;}) || (return err())
l!l
00
MC/DC0%0/1
$self->render(%{$html_sr;}) || (return err())
$self->render(%{$html_sr;})
Truth table0%0/2
A
A= $self->render(%{$html_sr;})
Aresult
11
00
3150 return err();
3151  
3152 }
3153 elsif ($ref ne 'SCALAR') {
3154  
3155 # If not JSON or HASH ref should be scalar. If not error
3156 #
3157 0 return err("error in perl method '$method'- code did not return a SCALAR ref value.");
3158 }
3159  
3160 }
3161 else {
3162 0 debug('returning json data');
3163 }
3164  
3165  
3166 # If get to here shift perl data_ar ref from stack
3167 #
3168 6 debug("shift off perl stack, stack:%s", join('*', @{$self->{'_perl'}}));
3169 6 shift @{$self->{'_perl'}};
3170  
3171 }
3172  
3173  
3174 # Restore autonewline to whatever it was
3175 #
3176 6 $self->autonewline($autonewline);
3177
3178
3179 # Return whatever was generated unless hidden attr set or display attr exists and is false
3180 #
3181 6 debug('attr_hr: %s', Dumper($attr_hr));
3182 6 ▶ if ( $attr_hr->{'hidden'} || (exists $attr_hr->{'display'} && !$attr_hr->{'display'}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_hr->{'hidden'} or exists $attr_hr->{'display'} and not $attr_hr->{'display'}) { } 0 6 6
Condition33%2/6
$attr_hr->{"hidden"} or exists $attr_hr->{"display"} and not $attr_hr->{"display"}
l!l&&r!l&&!r
006
exists $attr_hr->{"display"} and not $attr_hr->{"display"}
!ll&&!rl&&r
600
MC/DC0%0/3
$attr_hr->{"hidden"} or exists $attr_hr->{"display"} and not $attr_hr->{"display"}
$attr_hr->{"hidden"} exists $attr_hr->{"display"} not $attr_hr->{"display"}
Truth table25%1/4
A or B and not(C)
A= $attr_hr->{"hidden"}B= exists $attr_hr->{"display"}C= not $attr_hr->{"display"}
ABCresult
1XX1
0111
00X0
0100
3183  
3184
3185 # No display wanted. Note debug - don't do @{$attr_hr}{qw(hidden display)} or keys autovivify !
3186 #
3187 0 debug('hidden, not displaying. hidden:%s, display:%s, display(exists) %s', $attr_hr->{'hidden'}, $attr_hr->{'display'}, exists($attr_hr->{'display'}));
3188 0 return \undef;
3189
3190 }
3191 else {
3192
3193 # Not hidden return. Note debug - don't do @{$attr_hr}{qw(hidden display)} or keys autovivify !
3194 #
3195 6 debug('not hidden, displaying. hidden:%s, display:%s', $attr_hr->{'hidden'}, $attr_hr->{'display'});
3196 6 return $html_sr;
3197
3198 }
3199 #return $attr_hr->{'hidden'} ? \undef : $html_sr;
3200  
3201 }
3202  
3203  
3204 sub eval_require {
3205  
3206  
3207 # Code to require or load a module
3208 #
3209 0 ▶ my ($self, $require_fn, $attr_hr)=@_;
Subroutine eval_require: not called CC=9 SCAR=45.0
Pod undocumented
3210  
3211  
3212 # Inode ?
3213 #
3214 #my $inode=$self->{'_inode'} || 'ANON';
3215 0 ▶ my $inode=$self->{'_inode'} || $self->inode();
Condition0%0/3
$self->{'_inode'} || $self->inode
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_inode'} || $self->inode
$self->{'_inode'} $self->inode
Truth table0%0/3
A || B
A= $self->{'_inode'}B= $self->inode
ABresult
1X1
011
000
3216  
3217  
3218 # Eval cr
3219 #
3220 my $eval_cr=set_subname('eval_require_cr_anon', sub {
3221  
3222 0 ▶ local $SIG{__DIE__};
Subroutine __ANON__: not called CC=4 SCAR=30.0
3223 0 ▶ eval {} if $@; #Clear $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
3224 0 my $ret=eval(shift());
3225 0 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not $ret) { } 0 0 0
3226 0 my $err=$@; eval {};
3227 0 return err("attempt to load $require_fn returned error $err");
3228 }
3229 elsif (!$ret) {
3230 0 return err("eval of '$require_fn' did not return a true value");
3231 }
3232 0 return $ret
3233  
3234 0 });
3235  
3236  
3237 # File or module ? Try via syntax, allow force with 'file' attribute
3238 #
3239 0 ▶ if ($require_fn=~m([./\\]) || $attr_hr->{'file'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($require_fn =~ m([./\\]) or $attr_hr->{'file'}) { } 0 0 0
Condition0%0/3
$require_fn =~ m([./\\]) or $attr_hr->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$require_fn =~ m([./\\]) or $attr_hr->{"file"}
$require_fn =~ m([./\\]) $attr_hr->{"file"}
Truth table0%0/3
A or B
A= $require_fn =~ m([./\\])B= $attr_hr->{"file"}
ABresult
1X1
011
000
3240  
3241  
3242 # File contains a '.', '/' or '\'. Probably a file. Convert to full path
3243 #
3244 0 debug("found perl require command for: $require_fn, interpreting as local file");
3245 0 my $require_cn=$self->rel2abs($require_fn);
3246 0 debug("converted to full path $require_fn");
3247  
3248  
3249 # Need to load a file. Delete from INC so forced to reload in this inode package space;
3250 #
3251 0 delete $INC{$require_cn};
3252 0 (my $require_eval_cn=$require_cn)=~s/([\\'])/\\$1/g;
3253 0 my $eval=sprintf(q[package WebDyne::%s; require '%s'], $inode, $require_eval_cn);
3254 0 ▶ return $eval_cr->($eval) ||
Condition0%0/3
&$eval_cr($eval) || err()
l!l&&r!l&&!r
000
MC/DC0%0/2
&$eval_cr($eval) || err()
&$eval_cr($eval) err()
Truth table0%0/3
A || B
A= &$eval_cr($eval)B= err()
ABresult
1X1
011
000
3255 err();
3256  
3257  
3258 }
3259 else {
3260  
3261 # Probably a module as no match above
3262 #
3263 0 debug("found perl require command for $require_fn, interpreting as module with import: %s", Dumper($attr_hr->{'import'}));
3264 0 ▶ $require_fn=~m/\A[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*\z/ ||
Branch: 1 branch
BranchTrueFalseTotal
$require_fn =~ /\A[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*\z/ or return err("invalid module name '${require_fn}'") 0 0 0
3265 return err("invalid module name '$require_fn'");
3266  
3267  
3268 # Do any imports now
3269 #
3270 0 my @import;
3271 0 ▶ if (ref($attr_hr->{'import'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr_hr->{'import'} eq 'ARRAY') { } 0 0 0
3272 0 @import=@{$attr_hr->{'import'}}
3273 }
3274 else {
3275 0 @import=split(/\s+/, $attr_hr->{'import'});
3276 }
3277 0 debug("about to import functions: %s into inode:$inode", Dumper(\@import));
3278  
3279  
3280 # This only works for modules
3281 #
3282 0 map {*{"WebDyne::${inode}::$_"}=\&{"${require_fn}::$_"}} grep {$_} @import;
3283  
3284  
3285 # Check if already loaded ?
3286 #
3287 0 my @package=split(/\:+/, $require_fn);
3288  
3289  
3290 # And return package
3291 #
3292 0 my $package_fn=join('/', @package) . '.pm';
3293 0 ▶ if ($INC{$package_fn}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{$package_fn}) { } 0 0 0
3294  
3295 # Already loaded
3296 #
3297 0 debug('package %s already loaded in %%INC', $package_fn);
3298 0 return 1;
3299  
3300 }
3301 else {
3302  
3303 0 my $eval="require $require_fn";
3304 0 ▶ return $eval_cr->($eval) ||
Condition0%0/3
&$eval_cr($eval) || err()
l!l&&r!l&&!r
000
MC/DC0%0/2
&$eval_cr($eval) || err()
&$eval_cr($eval) err()
Truth table0%0/3
A || B
A= &$eval_cr($eval)B= err()
ABresult
1X1
011
000
3305 err();
3306  
3307 }
3308  
3309  
3310 }
3311  
3312 }
3313  
3314  
3315 sub eval_cr {
3316  
3317  
3318 # Return eval subroutine ref for inode ($_[0]) and eval code ref ($_[1]). Avoid using
3319 # var names so not available in eval code
3320 #
3321 #eval("package WebDyne::$_[0]; $WebDyne::WEBDYNE_EVAL_USE_STRICT;\n" . "#line $_[2]\n" . "sub{${$_[1]}\n}");
3322 3 ▶ my $eval=join(
Subroutine eval_cr: called CC=1 SCAR=0.0
Pod undocumented
3323 $/,
3324 "package WebDyne::$_[0]; $WebDyne::WEBDYNE_EVAL_USE_STRICT;",
3325 "#line $_[2] WebDyne::$_[0]",
3326 3 "sub{${$_[1]}}"
3327 );
3328 #debug("eval_cr: $eval");
3329 1 ▶ return eval($eval);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3330  
3331  
3332 }
3333  
3334  
3335 sub perl_init_eval {
3336  
3337  
3338 # Eval routine for perl_init code. Avoid using var names so things like $self not available
3339 # in eval code;
3340 # local $SIG{__DIE__};
3341 my $eval=join(
3342 $/,
3343 "package WebDyne::$_[0]; $WebDyne::WEBDYNE_EVAL_USE_STRICT;",
3344 3 ▶ grep {$_} (
Subroutine perl_init_eval: called CC=1 SCAR=0.0
Pod undocumented
3345 (WEBDYNE_EVAL_PREPEND && WEBDYNE_EVAL_PREPEND),
3346 (WEBDYNE_PAGI && $WebDyne::PAGI::WEBDYNE_PAGI_EVAL_PREPEND),
3347 (WEBDYNE_PSGI && $WebDyne::PSGI::WEBDYNE_PSGI_EVAL_PREPEND),
3348 ),
3349 "#line $_[2] WebDyne::$_[0]",
3350 3 "${$_[1]}",
3351 ';1'
3352 );
3353 3 debug("perl_init_eval:\n%s", $eval);
3354 1 ▶ return eval($eval);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3355  
3356 }
3357  
3358  
3359 sub perl_init {
3360  
3361  
3362 # Init the perl package space for this inode
3363 #
3364 3 ▶ my ($self, $perl_ar, $perl_debug_ar)=@_;
Subroutine perl_init: called CC=8 SCAR=23.8
Pod undocumented
3365 #my $inode=$self->{'_inode'} || 'ANON'; #ANON used when run from command line
3366 3 ▶ my $inode=$self->{'_inode'} || $self->inode();
Condition33%1/3
$self->{'_inode'} || $self->inode
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->{'_inode'} || $self->inode
$self->{'_inode'} $self->inode
Truth table33%1/3
A || B
A= $self->{'_inode'}B= $self->inode
ABresult
1X1
011
000
3367  
3368  
3369 # Prep package space
3370 #
3371 3 debug("$self init perl code $perl_ar in $inode, %s", Dumper($perl_ar));
3372 3 *{"WebDyne::${inode}::err"}=\&err;
3373 3 ▶ *{"WebDyne::${inode}::self"}=set_subname('perl_init_inode_self_cr_anon', sub {$self});
Subroutine __ANON__: not called CC=1 SCAR=0.4
3374 3 ▶ *{"WebDyne::${inode}::AUTOLOAD"}=sub {die("unknown function $AUTOLOAD")};
Subroutine __ANON__: not called CC=1 SCAR=0.4
3375  
3376  
3377 # Run each piece of perl code
3378 #
3379 3 foreach my $ix (0..$#{$perl_ar}) {
3380  
3381  
3382 # Get perl code and debug information
3383 #
3384 3 my $perl_sr=$perl_ar->[$ix];
3385 3 my ($perl_line_no, $perl_srce_fn)=@{$perl_debug_ar->[$ix]};
3386 3 debug("about to run $perl_sr at line:$perl_line_no from fn:$perl_srce_fn");
3387  
3388  
3389 # Do not execute twice
3390 #
3391 3 ▶ debug('execution current count is: %s', $Package{'_cache'}{$inode}{'perl_init'}{$perl_sr} ||= 0);
Condition50%1/2
$WebDyne::Package{"_cache"}{$inode}{"perl_init"}{$perl_sr} ||= 0
l!l
03
MC/DC0%0/1
$WebDyne::Package{"_cache"}{$inode}{"perl_init"}{$perl_sr} ||= 0
$WebDyne::Package{"_cache"}{$inode}{"perl_init"}{$perl_sr}
Truth table50%1/2
A
A= $WebDyne::Package{"_cache"}{$inode}{"perl_init"}{$perl_sr}
Aresult
11
00
3392 3 ▶ $Package{'_cache'}{$inode}{'perl_init'}{$perl_sr}++ && next;
Branch: 1 branch
BranchTrueFalseTotal
$WebDyne::Package{"_cache"}{$inode}{"perl_init"}{$perl_sr}++ and next 0 3 3
3393  
3394  
3395 # Set inc to include psp dir so can include packages easily
3396 #
3397 3 local @INC=@INC;
3398 3 push @INC, $self->cwd();
3399  
3400  
3401 # Error handler
3402 #
3403 my $error_cr=set_subname('error_cr_anon', sub {
3404  
3405 # An error has occurred. Deregister self subroutine call in package
3406 #
3407 #undef *{"WebDyne::${inode}::self"};
3408  
3409  
3410 # Make up a fake data block with details of error
3411 #
3412 0 ▶ my @data;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3413 0 @data[
3414 WEBDYNE_NODE_LINE_IX,
3415 WEBDYNE_NODE_LINE_TAG_END_IX,
3416 WEBDYNE_NODE_SRCE_IX,
3417 ]=($perl_line_no, $perl_line_no, $perl_srce_fn);
3418  
3419  
3420 # Save away as current data block for reference by error handler
3421 #
3422 0 push @{$self->{'_data_ar_err'}}, \@data;
3423  
3424 3 });
3425  
3426  
3427 # Var for eval return value
3428 #
3429 3 my $ret;
3430  
3431  
3432 # Wrap in anon CR, eval for syntax
3433 #
3434 3 if (WEBDYNE_EVAL_SAFE) {
3435  
3436  
3437 # Safe mode, vars don't matter so much
3438 #
3439 my $safe_or=$self->{'_eval_safe'} || do {
3440 debug('safe init (perl_init)');
3441 require Safe;
3442 require Opcode;
3443  
3444 #Safe->new($self->{'_inode'});
3445 Safe->new();
3446 };
3447 $self->{'_eval_safe'} ||= do {
3448 $safe_or->permit_only(@{$WEBDYNE_EVAL_SAFE_OPCODE_AR});
3449 $safe_or;
3450 };
3451  
3452  
3453 # Run safe eval
3454 #
3455 $ret=$safe_or->reval(${$perl_sr}, $WebDyne::WEBDYNE_EVAL_USE_STRICT);
3456  
3457  
3458 }
3459 else {
3460  
3461  
3462 # Now run eval after getting eval string;
3463 #
3464 3 debug("running perl_init_eval on $perl_sr now, line $perl_line_no");
3465 3 $ret=&perl_init_eval($inode, $perl_sr, $perl_line_no);
3466  
3467 }
3468  
3469  
3470 # Check for errors
3471 #
3472 3 ▶ if (my $err=($@ || errstr())) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $err = $@ || errstr()) { } 0 3 3
elsif (not $ret) { } 0 3 3
Condition33%1/3
$@ || errstr()
l!l&&r!l&&!r
003
MC/DC0%0/2
$@ || errstr()
$@ errstr()
Truth table33%1/3
A || B
A= $@B= errstr()
ABresult
1X1
011
000
3473 0 $error_cr->();
3474 0 eval {}; #Clear $@
3475 0 return $self->err_eval("error in __PERL__block: $err", $perl_sr, $inode);
3476 }
3477 elsif (!$ret) {
3478 0 $error_cr->();
3479 0 return err("eval of perl_init did not return a true value");
3480 }
3481  
3482 }
3483  
3484  
3485 # Done. Undef self ref sub but leave error handler and autoload
3486 #
3487 3 undef *{"WebDyne::${inode}::self"};
3488 3 debug('perl_init complete');
3489 3 return \undef;
3490  
3491 }
3492  
3493  
3494 sub subst {
3495  
3496  
3497 # Called to eval text block, replace params
3498 #
3499 6 ▶ my ($self, $data_ar, $attr_hr, $param_data_hr, $text)=@_;
Subroutine subst: called CC=4 SCAR=15.4
Pod undocumented
3500  
3501  
3502 # Debug
3503 #
3504 6 debug("eval $text %s", Dumper($param_data_hr));
3505  
3506  
3507 # Get eval code refs for subst
3508 #
3509 6 ▶ my $eval_cr=$Package{'_eval_cr'} ||
Condition50%1/2
$WebDyne::Package{'_eval_cr'} || (return err('unable to get eval code ref table'))
l!l
60
MC/DC0%0/1
$WebDyne::Package{'_eval_cr'} || (return err('unable to get eval code ref table'))
$WebDyne::Package{'_eval_cr'}
Truth table50%1/2
A
A= $WebDyne::Package{'_eval_cr'}
Aresult
11
00
3510 return err('unable to get eval code ref table');
3511  
3512  
3513 # Do we have to replace something in the text, look for pattern. We
3514 # should always find something, as subst tag is only inserted at
3515 # compile time in front of text with one of theses patterns
3516 #
3517 6 my $index;
3518 my $cr=set_subname('subst_cr_anon', sub {
3519  
3520 # Used to be this
3521 #
3522 #my $sr=$eval_cr->{$_[0]}($self, $data_ar, $param_data_hr, $_[1], $_[2]) ||
3523 # return err();
3524 #(ref($sr) eq 'SCALAR') ||
3525 # return err("eval of '$_[1]' returned %s ref, should return SCALAR ref", ref($sr));
3526 #return $sr;
3527
3528 # But doesn't have to be scalar ref, as long as represents as scalar
3529 #
3530 6 ▶ debug('running subst');
Subroutine __ANON__: called CC=2 SCAR=10.1
3531 6 ▶ return $eval_cr->{$_[0]}($self, $data_ar, $param_data_hr, $_[1], $_[2]) || do {
Condition33%1/3
$$eval_cr{$_[0]}($self, $data_ar, $param_data_hr, $_[1], $_[2]) || do { debug('subst_cr_anon returning error'); return err() }
l!l&&r!l&&!r
600
MC/DC0%0/2
$$eval_cr{$_[0]}($self, $data_ar, $param_data_hr, $_[1], $_[2]) || do { debug('subst_cr_anon returning error'); return err() }
$$eval_cr{$_[0]}($self, $data_ar, $param_data_hr, $_[1], $_[2]) do { debug('subst_cr_anon returning error'); return err() }
Truth table33%1/3
A || B
A= $$eval_cr{$_[0]}($self, $data_ar, $param_data_hr, $_[1], $_[2])B= do { debug('subst_cr_anon returning error'); return err() }
ABresult
1X1
011
000
3532 0 debug('subst_cr_anon returning error');
3533 0 return err();
3534 };
3535 6 });
3536 6 $text=~s/([\$!+*^])\{(\1?)(.*?)\2}/
3537 6 my $oper=$1;
3538 6 ▶ my $sr=$cr->($oper, $3, $index++) || do {
Condition33%1/3
&$cr($oper, $3, $index++) || do { debug('subst returning error'); return err() }
l!l&&r!l&&!r
600
MC/DC0%0/2
&$cr($oper, $3, $index++) || do { debug('subst returning error'); return err() }
&$cr($oper, $3, $index++) do { debug('subst returning error'); return err() }
Truth table33%1/3
A || B
A= &$cr($oper, $3, $index++)B= do { debug('subst returning error'); return err() }
ABresult
1X1
011
000
3539 0 debug('subst returning error');
3540 0 return err();
3541 };
3542 6 ▶ my $value=(ref($sr) eq 'SCALAR') ? ${$sr} : $sr;
Branch: 1 branch
BranchTrueFalseTotal
ref $sr eq 'SCALAR' ? : 6 0 6
3543 6 $self->subst_escape($oper, $value);
3544 /gex;
3545  
3546  
3547 # Done
3548 #
3549 6 debug("return *$text*");
3550 6 return \$text;
3551  
3552  
3553 }
3554  
3555  
3556 sub subst_escape {
3557  
3558  
3559 # Escape request-derived text substitutions when autoescape is enabled.
3560 # Attribute output is handled later by HTML::Tiny.
3561 #
3562 6 ▶ my ($self, $oper, $value)=@_;
Subroutine subst_escape: called CC=6 SCAR=25.2
Pod undocumented
3563 6 ▶ return $value
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and 1 and $oper eq "+" || $oper eq "*" || $oper eq "^" 6 0 6
Condition36%4/11
defined $value and 1 and $oper eq "+" || $oper eq "*" || $oper eq "^"
!ll&&!rl&&r
060
defined $value and 1
!ll
06
$oper eq "+" or $oper eq "*" or $oper eq "^"
l!l&&r!l&&!r
006
$oper eq "+" or $oper eq "*"
l!l&&r!l&&!r
006
MC/DC0%0/4
defined $value and 1 and $oper eq "+" || $oper eq "*" || $oper eq "^"
defined $value $oper eq "+" $oper eq "*" $oper eq "^"
Truth table20%1/5
A and B or C or D
A= defined $valueB= $oper eq "+"C= $oper eq "*"D= $oper eq "^"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
3564 unless defined($value) && WEBDYNE_CGI_AUTOESCAPE && (($oper eq '+') || ($oper eq '*') || ($oper eq '^'));
3565  
3566 0 return $self->html_tiny()->entity_encode($value);
3567  
3568 }
3569  
3570  
3571 sub subst_attr {
3572  
3573  
3574 # Called to eval tag attributes
3575 #
3576 6 ▶ my ($self, $data_ar, $attr_hr, $param_hr)=@_;
Subroutine subst_attr: called CC=9 SCAR=30.5
Pod undocumented
3577  
3578  
3579 # Debug
3580 #
3581 6 debug('subst_attr %s', Dumper({%{$attr_hr}, perl => undef}));
3582  
3583  
3584 # Get eval code refs for subst
3585 #
3586 6 ▶ my $eval_cr=$Package{'_eval_cr'} ||
Condition50%1/2
$WebDyne::Package{'_eval_cr'} || (return err('unable to get eval code ref table'))
l!l
60
MC/DC0%0/1
$WebDyne::Package{'_eval_cr'} || (return err('unable to get eval code ref table'))
$WebDyne::Package{'_eval_cr'}
Truth table50%1/2
A
A= $WebDyne::Package{'_eval_cr'}
Aresult
11
00
3587 return err('unable to get eval code ref table');
3588  
3589  
3590 # Hash to hold results
3591 #
3592 6 my %attr=%{$attr_hr};
3593  
3594  
3595 # Go through each attribute and value. *MUST BE DETERMINISTIC AND IN SAME ORDER EACH RUN*. If not the eval cached using
3596 # $index may change ! So don't use while.
3597 #
3598 # Actually can use while - but have to use attribute name as index so always deterministic
3599 #
3600 #my $index;
3601 #foreach my $attr_name (sort keys %attr) {
3602 6 ▶ while (my ($attr_name, $attr_value)=each %attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %attr) 9 6 15
3603  
3604  
3605 # Get value
3606 #
3607 #my $attr_value=$attr{$attr_name};
3608  
3609  
3610 # Skip perl attr, as that is perl code, do not do any regexp on perl code, as we will
3611 # probably botch it.
3612 #
3613 9 debug("subst_attr $attr_name: $attr_value");
3614 9 ▶ next if ($attr_name eq 'perl');
Branch: 1 branch
BranchTrueFalseTotal
if $attr_name eq "perl" 0 9 9
3615  
3616  
3617 # Look for attribute value strings that need substitution. First and second attemps did'nt work as single regexp
3618 #
3619 9 ▶ if ($attr_value=~/^\s*([\@%!+*^])\{(\1?)(.*)\2}\s*$/so || $attr_value=~/^\s*(\$)\{(\1?)([^{]+)\2}\s*$/so) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_value =~ /^\s*([\@%!+*^])\{(\1?)(.*)\2}\s*$/so or $attr_value =~ /^\s*(\$)\{(\1?)([^{]+)\2}\s*$/so) { } 0 9 9
Condition33%1/3
$attr_value =~ /^\s*([\@%!+*^])\{(\1?)(.*)\2}\s*$/so or $attr_value =~ /^\s*(\$)\{(\1?)([^{]+)\2}\s*$/so
l!l&&r!l&&!r
009
MC/DC0%0/2
$attr_value =~ /^\s*([\@%!+*^])\{(\1?)(.*)\2}\s*$/so or $attr_value =~ /^\s*(\$)\{(\1?)([^{]+)\2}\s*$/so
$attr_value =~ /^\s*([\@%!+*^])\{(\1?)(.*)\2}\s*$/so $attr_value =~ /^\s*(\$)\{(\1?)([^{]+)\2}\s*$/so
Truth table33%1/3
A or B
A= $attr_value =~ /^\s*([\@%!+*^])\{(\1?)(.*)\2}\s*$/soB= $attr_value =~ /^\s*(\$)\{(\1?)([^{]+)\2}\s*$/so
ABresult
1X1
011
000
3620  
3621 # Straightforward $@%!+^ operator, must be only content of value (can't be mixed
3622 # with string, e.g. <popup_list values="foo=@{qw(bar)}" dont make sense
3623 #
3624 0 my ($oper, $eval_text)=($1, $3);
3625 0 debug("subst_attr $attr_name path 1: oper:$oper, eval_text: $eval_text");
3626  
3627 #my $eval=$eval_cr->{$oper}->($self, $data_ar, $param_hr, $eval_text, $index++, 1) ||
3628 0 ▶ my $eval=$eval_cr->{$oper}->($self, $data_ar, $param_hr, $eval_text, $attr_name, 1) ||
Condition0%0/2
$eval_cr->{$oper}->($self, $data_ar, $param_hr, $eval_text, $attr_name, 1) || (return err())
l!l
00
MC/DC0%0/1
$eval_cr->{$oper}->($self, $data_ar, $param_hr, $eval_text, $attr_name, 1) || (return err())
$eval_cr->{$oper}->($self, $data_ar, $param_hr, $eval_text, $attr_name, 1)
Truth table0%0/2
A
A= $eval_cr->{$oper}->($self, $data_ar, $param_hr, $eval_text, $attr_name, 1)
Aresult
11
00
3629 return err();
3630 0 ▶ $attr{$attr_name}=(ref($eval) eq 'SCALAR') ? ${$eval} : $eval;
Branch: 1 branch
BranchTrueFalseTotal
ref $eval eq 'SCALAR' ? : 0 0 0
3631  
3632 }
3633 else {
3634  
3635 # Trickier - might be interspersed in strings, e.g <submit name="foo=1&${bar}=2&car=${dar}"/>
3636 # Substitution needed
3637 #
3638 9 debug("subst_attr path 2: $attr_name, $attr_value");
3639 my $cr=set_subname('subst_attr_cr_anon', sub {
3640 0 ▶ my $sr=$eval_cr->{$_[0]}($self, $data_ar, $param_hr, $_[1], $_[2]) ||
Subroutine __ANON__: not called CC=3 SCAR=24.8
Condition0%0/2
$$eval_cr{$_[0]}($self, $data_ar, $param_hr, $_[1], $_[2]) || (return err())
l!l
00
MC/DC0%0/1
$$eval_cr{$_[0]}($self, $data_ar, $param_hr, $_[1], $_[2]) || (return err())
$$eval_cr{$_[0]}($self, $data_ar, $param_hr, $_[1], $_[2])
Truth table0%0/2
A
A= $$eval_cr{$_[0]}($self, $data_ar, $param_hr, $_[1], $_[2])
Aresult
11
00
3641 return err();
3642 0 ▶ (ref($sr) eq 'SCALAR') ||
Branch: 1 branch
BranchTrueFalseTotal
ref $sr eq "SCALAR" or return err("eval of '$_[1]' returned %s ref, should return SCALAR ref", ref $sr) 0 0 0
3643 return err("eval of '$_[1]' returned %s ref, should return SCALAR ref", ref($sr));
3644 0 $sr;
3645 9 });
3646  
3647 #$attr_value=~s/([\$!+*^]){1}{(\1?)(.*?)\2}/${$cr->($1,$3,$index++) || return err()}/ge;
3648 9 ▶ $attr_value=~s/([\$!+*^]){1}{(\1?)(.*?)\2}/${$cr->($1,$3,$attr_name) || return err()}/ge;
Branch: 1 branch
BranchTrueFalseTotal
&$cr($1, $3, $attr_name) or return err() 0 0 0
3649 9 $attr{$attr_name}=$attr_value;
3650  
3651 }
3652  
3653 }
3654  
3655  
3656 # Debug
3657 #
3658 6 debug('returning attr hash %s', Dumper({%attr, perl => undef}));
3659  
3660  
3661 # Return new attribute hash
3662 #
3663 6 \%attr;
3664  
3665 }
3666  
3667  
3668 sub include {
3669  
3670  
3671 # Called to include text/psp block. Can be called from <include> tag or
3672 # perl code, so need to massage params appropriatly.
3673 #
3674 0 ▶ my $self=shift();
Subroutine include: not called CC=37 SCAR=72.5
Pod undocumented
3675 0 my ($data_ar, $param_hr, $param_data_hr, $text);
3676  
3677  
3678 # Normally get:
3679 #
3680 # my ($self, $data_ar, $attr_hr, $param_data_hr, $text)=@_;
3681 #
3682 # from tag, but in this case param_hr subs for attr_hr because
3683 # we use that for code called from perl. Check what called us
3684 # now - if first param (after self) is array ref, called from
3685 # tag
3686 #
3687 0 ▶ if (ref($_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 0 0
3688  
3689 # Called from <include> tag
3690 #
3691 0 ($data_ar, $param_hr, $param_data_hr, $text)=@_;
3692 }
3693 else {
3694  
3695 # Called from perl code, massage params into hr if not already there
3696 #
3697 0 $param_hr=shift();
3698 0 ▶ ref($param_hr) || ($param_hr={file => $param_hr, param => {@_}});
Branch: 1 branch
BranchTrueFalseTotal
ref $param_hr or $param_hr = {"file", $param_hr, "param", {@_}} 0 0 0
3699  
3700 }
3701  
3702  
3703 # Debug
3704 #
3705 0 debug('in include, param %s, %s', Dumper($param_hr, $param_data_hr));
3706  
3707  
3708 # Get CWD
3709 #
3710 0 ▶ my $r=$self->r() || return err();
Condition0%0/2
$self->r || (return err())
l!l
00
MC/DC0%0/1
$self->r || (return err())
$self->r
Truth table0%0/2
A
A= $self->r
Aresult
11
00
3711 #my $dn=(File::Spec->splitpath($r->filename()))[1] ||
3712 0 ▶ my $dn=$self->cwd() ||
Condition0%0/2
$self->cwd || (return err('unable to determine cwd for requested file %s', $r->filename))
l!l
00
MC/DC0%0/1
$self->cwd || (return err('unable to determine cwd for requested file %s', $r->filename))
$self->cwd
Truth table0%0/2
A
A= $self->cwd
Aresult
11
00
3713 return err('unable to determine cwd for requested file %s', $r->filename());
3714 0 debug("dn: $dn");
3715  
3716  
3717 # Any param must supply a file name as an attribute
3718 #
3719 0 ▶ my $fn_ar=$param_hr->{'file'} ||
Condition0%0/2
$param_hr->{'file'} || (return err('no file name supplied with include tag'))
l!l
00
MC/DC0%0/1
$param_hr->{'file'} || (return err('no file name supplied with include tag'))
$param_hr->{'file'}
Truth table0%0/2
A
A= $param_hr->{'file'}
Aresult
11
00
3720 return err('no file name supplied with include tag');
3721 0 ▶ unless (ref($fn_ar) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fn_ar eq "ARRAY") 0 0 0
3722 0 $fn_ar=[$fn_ar]
3723 }
3724 0 debug('fn_ar: %s', Dumper($fn_ar));
3725
3726
3727 # Array for HTML results
3728 #
3729 0 my @html;
3730 0 my $count=0;
3731
3732
3733 # Iterate
3734 #
3735 0 foreach my $fn (@{$fn_ar}) {
3736
3737
3738 # Get full path name
3739 #
3740 0 my $pn=File::Spec->rel2abs($fn, $dn);
3741 0 $count++;
3742 0 debug("processing fn: $fn, pn: $pn");
3743  
3744  
3745 # Check what user wants to do
3746 #
3747 0 ▶ if (my $node=(grep {exists $param_hr->{$_}} qw(head body))[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $node = (grep {exists $param_hr->{$_};} 'head', 'body')[0]) { } 0 0 0
elsif (my $block = $param_hr->{'block'}) { } 0 0 0
3748  
3749  
3750 # They want to include the head or body section of an existing pure HTML
3751 # file.
3752 #
3753 0 debug('head or body render');
3754 0 my %option=(
3755  
3756 no_filter => 1,
3757 no_perl => 1,
3758 stage0 => 1,
3759 srce => $pn,
3760
3761 # Note this - don't want implicit <p> tags for included files at body start,
3762 # i.e. <body><p>Some Text in included file may end up as <body><p><p> in initiator file
3763 implicit_body_p_tag => 0,
3764  
3765 );
3766
3767
3768 # Bring in WebDyne::Compile - going to need it
3769 #
3770 0 ▶ eval {require WebDyne::Compile}
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require WebDyne::Compile } } or return $self->err_html(errsubst("unable to load WebDyne:Compile, %s", $@ || "undefined error")) 0 0 0
Condition0%0/2
$@ || 'undefined error'
l!l
00
MC/DC0%0/1
$@ || 'undefined error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
3771 || return $self->err_html(
3772 errsubst('unable to load WebDyne:Compile, %s', $@ || 'undefined error'));
3773
3774  
3775 # compile spec'd file
3776 #
3777 0 ▶ my $container_ar=$self->compile(\%option) ||
Condition0%0/2
$self->compile(\%option) || (return err())
l!l
00
MC/DC0%0/1
$self->compile(\%option) || (return err())
$self->compile(\%option)
Truth table0%0/2
A
A= $self->compile(\%option)
Aresult
11
00
3778 return err();
3779 #$self->data_ar_err_pop();
3780 0 my $block_data_ar=$container_ar->[1];
3781 0 debug('compiled to data_ar %s', Dumper($block_data_ar));
3782
3783
3784 # Any perl code in content ? Initialize it
3785 #
3786 0 ▶ if (my $meta_hr=$container_ar->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meta_hr = $container_ar->[0]) 0 0 0
3787 0 ▶ if (my $perl_ar=$meta_hr->{'perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $perl_ar = $meta_hr->{"perl"}) 0 0 0
3788 0 ▶ my $perl_debug_ar=$meta_hr->{'perl_debug'} ||
Condition0%0/2
$meta_hr->{'perl_debug'} || (return err('unable to load perl_debug array reference'))
l!l
00
MC/DC0%0/1
$meta_hr->{'perl_debug'} || (return err('unable to load perl_debug array reference'))
$meta_hr->{'perl_debug'}
Truth table0%0/2
A
A= $meta_hr->{'perl_debug'}
Aresult
11
00
3789 return err('unable to load perl_debug array reference');
3790 0 ▶ $self->perl_init($perl_ar, $perl_debug_ar) || return $self->err_html();
Branch: 1 branch
BranchTrueFalseTotal
$self->perl_init($perl_ar, $perl_debug_ar) or return $self->err_html 0 0 0
3791 }
3792 }
3793  
3794  
3795 # Find the head or body tag
3796 #
3797 0 ▶ my $block_ar=$self->find_node(
Condition0%0/2
$self->find_node({'data_ar', $block_data_ar, 'tag', $node}) || (return err())
l!l
00
MC/DC0%0/1
$self->find_node({'data_ar', $block_data_ar, 'tag', $node}) || (return err())
$self->find_node({'data_ar', $block_data_ar, 'tag', $node})
Truth table0%0/2
A
A= $self->find_node({'data_ar', $block_data_ar, 'tag', $node})
Aresult
11
00
3798 {
3799  
3800 data_ar => $block_data_ar,
3801 tag => $node,
3802  
3803 }) || return err();
3804 0 ▶ @{$block_ar} ||
Branch: 1 branch
BranchTrueFalseTotal
@{$block_ar;} or return err("unable to find block '${node}' in include file '${fn}'") 0 0 0
3805 return err("unable to find block '$node' in include file '$fn'");
3806 0 debug('found block_ar %s', Dumper($block_ar));
3807  
3808  
3809 # Find_node returns array of blocks that match - we only want first
3810 #
3811 0 $block_ar=$block_ar->[0];
3812  
3813  
3814 # Need to finish compiling now found
3815 #
3816 0 ▶ $self->optimise_one($block_ar) || return err();
Branch: 1 branch
BranchTrueFalseTotal
$self->optimise_one($block_ar) or return err() 0 0 0
3817 0 ▶ $self->optimise_two($block_ar) || return err();
Branch: 1 branch
BranchTrueFalseTotal
$self->optimise_two($block_ar) or return err() 0 0 0
3818 0 debug('optimised data now %s', Dumper($block_ar));
3819  
3820  
3821 # Need to encapsulate into <block display=1> tag, so alter tag name, attr
3822 #
3823 0 $block_ar->[WEBDYNE_NODE_NAME_IX]='block';
3824 0 $block_ar->[WEBDYNE_NODE_ATTR_IX]={name => $node, display => 1};
3825  
3826  
3827 # Incorporate into top level data so we don't have to do this again if
3828 # called from tag
3829 #
3830 0 ▶ @{$data_ar}=@{$block_ar} if ($data_ar && !$param_hr->{'nocache'});
Branch: 1 branch
BranchTrueFalseTotal
if $data_ar and not $param_hr->{"nocache"} 0 0 0
Condition0%0/3
$data_ar and not $param_hr->{"nocache"}
!ll&&!rl&&r
000
MC/DC0%0/2
$data_ar and not $param_hr->{"nocache"}
$data_ar not $param_hr->{"nocache"}
Truth table0%0/3
A and not(B)
A= $data_arB= not $param_hr->{"nocache"}
ABresult
0X0
100
111
3831  
3832  
3833 # Render included block and return after stripping <p></p>
3834 #
3835 0 ▶ my $html_sr=$self->render_data_ar(data => $block_ar->[WEBDYNE_NODE_CHLD_IX], param => $param_hr->{'param'}) ||
Condition0%0/2
$self->render_data_ar('data', $block_ar->[2], 'param', $param_hr->{'param'}) || (return err())
l!l
00
MC/DC0%0/1
$self->render_data_ar('data', $block_ar->[2], 'param', $param_hr->{'param'}) || (return err())
$self->render_data_ar('data', $block_ar->[2], 'param', $param_hr->{'param'})
Truth table0%0/2
A
A= $self->render_data_ar('data', $block_ar->[2], 'param', $param_hr->{'param'})
Aresult
11
00
3836 return err();
3837 #return $html_sr;
3838 0 push @html, ${$html_sr}
3839
3840  
3841 }
3842 elsif (my $block=$param_hr->{'block'}) {
3843  
3844 # Wants to include a paticular block from a psp library file
3845 #
3846 0 debug('block render');
3847 0 my %option=(
3848  
3849 no_filter => 1,
3850 #no_perl => 1,
3851 stage1 => 1,
3852 srce => $pn,
3853 implicit_body_p_tag => 0,
3854  
3855 );
3856  
3857  
3858 # Bring in WebDyne::Compile - going to need it
3859 #
3860 0 ▶ eval {require WebDyne::Compile}
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require WebDyne::Compile } } or return $self->err_html(errsubst("unable to load WebDyne:Compile, %s", $@ || "undefined error")) 0 0 0
Condition0%0/2
$@ || 'undefined error'
l!l
00
MC/DC0%0/1
$@ || 'undefined error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
3861 || return $self->err_html(
3862 errsubst('unable to load WebDyne:Compile, %s', $@ || 'undefined error'));
3863  
3864  
3865 # compile spec'd file
3866 #
3867 0 ▶ my $container_ar=$self->compile(\%option) ||
Condition0%0/2
$self->compile(\%option) || (return err())
l!l
00
MC/DC0%0/1
$self->compile(\%option) || (return err())
$self->compile(\%option)
Truth table0%0/2
A
A= $self->compile(\%option)
Aresult
11
00
3868 return err();
3869 0 my $block_data_ar=$container_ar->[1];
3870 0 debug('block data %s', Dumper($block_data_ar));
3871  
3872  
3873 # Find the block node with name we want
3874 #
3875 0 debug("looking for block name $block");
3876 0 ▶ my $block_ar=$self->find_node(
Condition0%0/2
$self->find_node({'data_ar', $block_data_ar, 'tag', 'block', 'attr_hr', {'name', $block}}) || (return err())
l!l
00
MC/DC0%0/1
$self->find_node({'data_ar', $block_data_ar, 'tag', 'block', 'attr_hr', {'name', $block}}) || (return err())
$self->find_node({'data_ar', $block_data_ar, 'tag', 'block', 'attr_hr', {'name', $block}})
Truth table0%0/2
A
A= $self->find_node({'data_ar', $block_data_ar, 'tag', 'block', 'attr_hr', {'name', $block}})
Aresult
11
00
3877 {
3878  
3879 data_ar => $block_data_ar,
3880 tag => 'block',
3881 attr_hr => {name => $block},
3882  
3883 }) || return err();
3884 0 ▶ @{$block_ar} ||
Branch: 1 branch
BranchTrueFalseTotal
@{$block_ar;} or return err("unable to find block '${block}' in include file '${fn}'") 0 0 0
3885 return err("unable to find block '$block' in include file '$fn'");
3886 0 debug('found block_ar %s', Dumper($block_ar));
3887  
3888  
3889 # Find_node returns array of blocks that match - we only want first
3890 #
3891 0 $block_ar=$block_ar->[0];
3892  
3893  
3894 # Set to attr always display
3895 #
3896 0 $block_ar->[WEBDYNE_NODE_ATTR_IX]{'display'}=1;
3897  
3898  
3899 # Incorporate into top level data so we don't have to do this again if
3900 # called from tag
3901 #
3902 # COMMENTED OUT FOR NOW: Doesn't work in terms of stripping <p></p> tags
3903 #
3904 0 ▶ @{$data_ar}=@{$block_ar} if ($data_ar && !$param_hr->{'nocache'});
Branch: 1 branch
BranchTrueFalseTotal
if $data_ar and not $param_hr->{"nocache"} 0 0 0
Condition0%0/3
$data_ar and not $param_hr->{"nocache"}
!ll&&!rl&&r
000
MC/DC0%0/2
$data_ar and not $param_hr->{"nocache"}
$data_ar not $param_hr->{"nocache"}
Truth table0%0/3
A and not(B)
A= $data_arB= not $param_hr->{"nocache"}
ABresult
0X0
100
111
3905 #@{$data_ar}=@{$block_ar} if $data_ar;
3906  
3907  
3908 # We don't want to render <block> tags, so start at
3909 # child of results [WEBDYNE_NODE_CHLD_IX].
3910 #
3911 0 debug('calling render');
3912 0 ▶ my $html_sr=$self->render_data_ar(data => $block_ar->[WEBDYNE_NODE_CHLD_IX], param => ($param_hr->{'param'} || $param_data_hr)) ||
Condition0%0/5
$self->render_data_ar('data', $block_ar->[2], 'param', $param_hr->{'param'} || $param_data_hr) || (return err())
l!l
00
$param_hr->{'param'} || $param_data_hr
l!l&&r!l&&!r
000
MC/DC0%0/1
$self->render_data_ar('data', $block_ar->[2], 'param', $param_hr->{'param'} || $param_data_hr) || (return err())
$self->render_data_ar('data', $block_ar->[2], 'param', $param_hr->{'param'} || $param_data_hr)
MC/DC0%0/2
$param_hr->{'param'} || $param_data_hr
$param_hr->{'param'} $param_data_hr
Truth table0%0/2
A
A= $self->render_data_ar('data', $block_ar->[2], 'param', $param_hr->{'param'} || $param_data_hr)
Aresult
11
00
Truth table0%0/3
A || B
A= $param_hr->{'param'}B= $param_data_hr
ABresult
1X1
011
000
3913 return err();
3914 #return $html_sr;
3915 0 push @html, ${$html_sr};
3916  
3917  
3918 }
3919 else {
3920  
3921  
3922 # Plain vanilla file include, no mods
3923 #
3924 0 debug('vanilla file include');
3925 0 ▶ my $fh=IO::File->new($pn, O_RDONLY) || return err("unable to open file '$fn' for read, $!");
Condition0%0/2
'IO::File'->new($pn, 0) || (return err("unable to open file '${fn}' for read, $!"))
l!l
00
MC/DC0%0/1
'IO::File'->new($pn, 0) || (return err("unable to open file '${fn}' for read, $!"))
'IO::File'->new($pn, 0)
Truth table0%0/2
A
A= 'IO::File'->new($pn, 0)
Aresult
11
00
3926 0 local $/;
3927 0 my $html = <$fh>;
3928 0 $fh->close();
3929
3930  
3931 # Wrap ?
3932 #
3933 0 ▶ if (my $tag=$param_hr->{'wrap'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tag = $param_hr->{"wrap"}) 0 0 0
3934 0 debug("wrapping in tag: $tag");
3935 0 my $html_or=HTML::Element->new($tag);
3936 0 $html_or->push_content($html);
3937 0 $html=$html_or->as_HTML();
3938 }
3939
3940
3941 # Need to create fake <block> tag to hold this if want to cache
3942 #
3943 0 ▶ if ($data_ar && !$param_hr->{'nocache'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_ar and not $param_hr->{"nocache"}) 0 0 0
Condition0%0/3
$data_ar and not $param_hr->{"nocache"}
!ll&&!rl&&r
000
MC/DC0%0/2
$data_ar and not $param_hr->{"nocache"}
$data_ar not $param_hr->{"nocache"}
Truth table0%0/3
A and not(B)
A= $data_arB= not $param_hr->{"nocache"}
ABresult
0X0
100
111
3944
3945 # Yes, want to cache this file, create fake block tag and force display
3946 #
3947 0 my @block=('block', { name=>"file_${count}", display=>1 }, [$html], undef, 1, 1, \$pn);
3948 0 push @{$data_ar}, \@block;
3949
3950 }
3951
3952
3953 # And return HTML
3954 #
3955 #return \$html;
3956 0 push @html, $html;
3957  
3958 }
3959 }
3960  
3961 # Done
3962 #
3963 0 my $html=join(undef, grep {$_} @html);
3964 0 debug("returning html: $html");
3965 0 return \$html;
3966  
3967 }
3968  
3969  
3970 sub find_node {
3971  
3972  
3973 # Find a particular node in the tree
3974 #
3975 6 ▶ my ($self, $param_hr)=@_;
Subroutine find_node: called CC=2 SCAR=7.2
Pod undocumented
3976  
3977  
3978 # Get max depth we can descend to, zero out in params
3979 #
3980 6 my ($data_ar, $tag, $attr_hr, $depth_max, $prnt_fg, $all_fg)=@{$param_hr}{
3981 6 qw(data_ar tag attr_hr depth prnt_fg all_fg)
3982 };
3983 6 ▶ $attr_hr ||= {};
Condition50%1/2
$attr_hr ||= {}
l!l
06
MC/DC0%0/1
$attr_hr ||= {}
$attr_hr
Truth table50%1/2
A
A= $attr_hr
Aresult
11
00
3984 6 debug("find_node looking for tag $tag in data_ar $data_ar, %s", Dumper($data_ar));
3985  
3986  
3987 # Array to hold results, depth
3988 #
3989 6 my @node;
3990  
3991  
3992 # Create recursive anon sub
3993 #
3994 my $find_cr=set_subname('find_node_cr_anon', sub {
3995  
3996  
3997 # Get params
3998 #
3999 18 ▶ my ($find_cr, $data_ar, $data_prnt_ar, $depth)=@_;
Subroutine __ANON__: called CC=15 SCAR=30.1
4000 18 debug("find_cr, data_ar $data_ar, data_prnt_ar $data_prnt_ar");
4001  
4002  
4003 # Do we match at this level ?
4004 #
4005 18 ▶ if ((my $data_ar_tag=$data_ar->[WEBDYNE_NODE_NAME_IX]) eq $tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $data_ar_tag = $data_ar->[0]) eq $tag) { } 9 9 18
4006  
4007  
4008 # Match for tag name, now check any attrs
4009 #
4010 9 my $tag_attr_hr=$data_ar->[WEBDYNE_NODE_ATTR_IX];
4011  
4012  
4013 # Debug
4014 #
4015 9 debug("tag '$tag' match, $data_ar_tag, checking attr %s", Dumper($tag_attr_hr));
4016  
4017  
4018 # Check only the attributes the caller asked to match. Missing
4019 # attr_hr means "tag name only", so the empty filter below matches
4020 # any node with the requested tag. Iterate over the filter rather
4021 # than the node's full attr hash to avoid accepting partial
4022 # matches accidentally and to keep the work proportional to the
4023 # requested search criteria.
4024 #
4025 9 my $attr_match_fg=1;
4026 9 foreach my $attr (keys %{$attr_hr}) {
4027 0 ▶ if (!exists($tag_attr_hr->{$attr}) || ($tag_attr_hr->{$attr} ne $attr_hr->{$attr})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $tag_attr_hr->{$attr} or $tag_attr_hr->{$attr} ne $attr_hr->{$attr}) 0 0 0
Condition0%0/3
not exists $tag_attr_hr->{$attr} or $tag_attr_hr->{$attr} ne $attr_hr->{$attr}
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $tag_attr_hr->{$attr} or $tag_attr_hr->{$attr} ne $attr_hr->{$attr}
not exists $tag_attr_hr->{$attr} $tag_attr_hr->{$attr} ne $attr_hr->{$attr}
Truth table0%0/3
not(A) or B
A= not exists $tag_attr_hr->{$attr}B= $tag_attr_hr->{$attr} ne $attr_hr->{$attr}
ABresult
1X1
011
000
4028 0 $attr_match_fg=0;
4029 0 last;
4030 }
4031 }
4032 9 ▶ if ($attr_match_fg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_match_fg) 9 0 9
4033  
4034  
4035 # Match, debug
4036 #
4037 9 debug("$data_ar_tag attr match, saving");
4038  
4039  
4040 # Tag name and attribs match, push onto node
4041 #
4042 9 ▶ push @node, $prnt_fg ? $data_prnt_ar : $data_ar;
Branch: 1 branch
BranchTrueFalseTotal
$prnt_fg ? : 0 9 9
4043 9 ▶ return $node[0] unless $all_fg;
Branch: 1 branch
BranchTrueFalseTotal
unless $all_fg 3 6 9
4044  
4045  
4046 }
4047  
4048 }
4049 else {
4050  
4051 9 debug("mismatch on tag $data_ar_tag for tag '$tag'");
4052  
4053 }
4054  
4055  
4056 # Return if out of depth
4057 #
4058 15 ▶ return if ($depth_max && ($depth >= $depth_max));
Branch: 1 branch
BranchTrueFalseTotal
if $depth_max and $depth >= $depth_max 0 15 15
Condition33%1/3
$depth_max and $depth >= $depth_max
!ll&&!rl&&r
1500
MC/DC0%0/2
$depth_max and $depth >= $depth_max
$depth_max $depth >= $depth_max
Truth table33%1/3
A and B
A= $depth_maxB= $depth >= $depth_max
ABresult
0X0
100
111
4059  
4060  
4061 # Start looking through current node
4062 #
4063 15 ▶ my @data_child_ar=$data_ar->[WEBDYNE_NODE_CHLD_IX] ? @{$data_ar->[WEBDYNE_NODE_CHLD_IX]} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$data_ar->[2] ? : 9 6 15
4064 15 foreach my $data_child_ar (@data_child_ar) {
4065  
4066  
4067 # Only check and/or recurse through children that are child nodes, (ie
4068 # are refs), ignor non-ref (text) nodes
4069 #
4070 21 ▶ ref($data_child_ar) && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $data_child_ar and do { if (my $data_match_ar = &$find_cr($find_cr, $data_child_ar, $data_ar, $depth + 1)) { return $data_match_ar unless $all_fg; } } 12 9 21
4071  
4072  
4073 # We have a ref, recurse look for match
4074 #
4075 12 ▶ if (my $data_match_ar=$find_cr->($find_cr, $data_child_ar, $data_ar, $depth + 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data_match_ar = &$find_cr($find_cr, $data_child_ar, $data_ar, $depth + 1)) 3 9 12
4076  
4077  
4078 # Found match during recursion, return
4079 #
4080 3 ▶ return $data_match_ar unless $all_fg;
Branch: 1 branch
BranchTrueFalseTotal
unless $all_fg 3 0 3
4081  
4082 }
4083  
4084 }
4085  
4086 }
4087  
4088 6 });
4089  
4090  
4091 # Start it running with our top node
4092 #
4093 6 $find_cr->($find_cr, $data_ar, undef, 0);
4094  
4095  
4096 # Debug
4097 #
4098 6 debug('find complete, return node %s', \@node);
4099  
4100  
4101 # Return results
4102 #
4103 6 return \@node;
4104  
4105 }
4106  
4107  
4108 sub delete_node {
4109  
4110  
4111 # Delete a particular node from the tree
4112 #
4113 0 ▶ my ($self, $param_hr)=@_;
Subroutine delete_node: not called CC=2 SCAR=17.9
Pod undocumented
4114  
4115  
4116 # Get max depth we can descend to, zero out in params
4117 #
4118 0 my ($data_ar, $node_ar)=@{$param_hr}{qw(data_ar node_ar)};
4119 0 debug("delete node $node_ar starting from data_ar $data_ar");
4120  
4121  
4122 # Create recursive anon sub
4123 #
4124 my $find_cr=set_subname('delete_node_cr_anon', sub {
4125  
4126  
4127 # Get params
4128 #
4129 0 ▶ my ($find_cr, $data_ar)=@_;
Subroutine __ANON__: not called CC=7 SCAR=40.3
4130  
4131  
4132 # Iterate through child nodes
4133 #
4134 0 foreach my $data_chld_ix (0..$#{$data_ar->[WEBDYNE_NODE_CHLD_IX]}) {
4135  
4136 0 ▶ my $data_chld_ar=$data_ar->[WEBDYNE_NODE_CHLD_IX][$data_chld_ix] ||
Condition0%0/2
$data_ar->[2][$data_chld_ix] || (return err("unable to get chld node from $data_ar"))
l!l
00
MC/DC0%0/1
$data_ar->[2][$data_chld_ix] || (return err("unable to get chld node from $data_ar"))
$data_ar->[2][$data_chld_ix]
Truth table0%0/2
A
A= $data_ar->[2][$data_chld_ix]
Aresult
11
00
4137 return err("unable to get chld node from $data_ar");
4138 0 debug("looking at chld node $data_chld_ar");
4139  
4140 0 ▶ if ($data_chld_ar eq $node_ar) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_chld_ar eq $node_ar) { } 0 0 0
4141  
4142 # Found node we want to delete. Get rid of it, all done
4143 #
4144 0 debug("match - splicing at chld $data_chld_ix from array %s", Dumper($data_ar));
4145 0 splice(@{$data_ar->[WEBDYNE_NODE_CHLD_IX]}, $data_chld_ix, 1);
4146 0 return \1;
4147  
4148 }
4149 else {
4150  
4151  
4152 # Non-ref children are text nodes, not subtrees.
4153 #
4154 0 ▶ next unless ref($data_chld_ar);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data_chld_ar 0 0 0
4155  
4156  
4157 # Not target node - recurse
4158 #
4159 0 debug("no match - recursing to chld $data_chld_ar");
4160 0 ▶ ${$find_cr->($find_cr, $data_chld_ar) || return err()} &&
Branch: 2 branches
BranchTrueFalseTotal
${&$find_cr($find_cr, $data_chld_ar) or return err();} and return \1 0 0 0
&$find_cr($find_cr, $data_chld_ar) or return err() 0 0 0
4161 return \1;
4162  
4163 }
4164 }
4165  
4166  
4167 # All done, but no cigar
4168 #
4169 0 return \undef;
4170  
4171 0 });
4172  
4173  
4174 # Start
4175 #
4176 0 ▶ return $find_cr->($find_cr, $data_ar) || err()
Condition0%0/3
&$find_cr($find_cr, $data_ar) || err()
l!l&&r!l&&!r
000
MC/DC0%0/2
&$find_cr($find_cr, $data_ar) || err()
&$find_cr($find_cr, $data_ar) err()
Truth table0%0/3
A || B
A= &$find_cr($find_cr, $data_ar)B= err()
ABresult
1X1
011
000
4177  
4178 }
4179  
4180  
4181 sub CGI {
4182  
4183  
4184 # Return WebDyne::CGI::Simple wrapper object
4185 #
4186 8 ▶ my $self=shift();
Subroutine CGI: called CC=4 SCAR=14.4
Pod undocumented
4187 8 debug("$self get WebDyne::CGI object, caller: %s", Dumper([caller(0)]));
4188  
4189  
4190 # Accessor method for CGI::Simple object
4191 #
4192 8 ▶ return $self->{'_CGI'} ||= do {
Condition33%1/3
$self->{"_CGI"} ||= do { debug("creating new object"); local $SIG{"__DIE__"} = sub { } ; my $cgi_or = "WebDyne::CGI::Simple"->new($self->{"_r"}) || (return err("unable to get WebDyne::CGI object")); $self->CGI_param_expand($cgi_or); debug("cgi_or: $cgi_or"); eval { do { () } } if @_; $cgi_or }
l!l&&r!l&&!r
080
MC/DC0%0/2
$self->{"_CGI"} ||= do { debug("creating new object"); local $SIG{"__DIE__"} = sub { } ; my $cgi_or = "WebDyne::CGI::Simple"->new($self->{"_r"}) || (return err("unable to get WebDyne::CGI object")); $self->CGI_param_expand($cgi_or); debug("cgi_or: $cgi_or"); eval { do { () } } if @_; $cgi_or }
$self->{"_CGI"} do { debug("creating new object"); local $SIG{"__DIE__"} = sub { } ; my $cgi_or = "WebDyne::CGI::Simple"->new($self->{"_r"}) || (return err("unable to get WebDyne::CGI object")); $self->CGI_param_expand($cgi_or); debug("cgi_or: $cgi_or"); eval { do { () } } if @_; $cgi_or }
Truth table33%1/3
A ||= B
A= $self->{"_CGI"}B= do { debug("creating new object"); local $SIG{"__DIE__"} = sub { } ; my $cgi_or = "WebDyne::CGI::Simple"->new($self->{"_r"}) || (return err("unable to get WebDyne::CGI object")); $self->CGI_param_expand($cgi_or); debug("cgi_or: $cgi_or"); eval { do { () } } if @_; $cgi_or }
ABresult
1X1
011
000
4193  
4194  
4195 # CGI good practice
4196 #
4197 8 debug('creating new object');
4198  
4199  
4200 # And create it. CGI::Simple looks for mod_perl in an eval
4201 # block and we don't want to trigger an error so be careful
4202 #
4203 8 ▶ local $SIG{'__DIE__'}=sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
4204 8 ▶ my $cgi_or=WebDyne::CGI::Simple->new($self->{'_r'}) ||
Condition50%1/2
'WebDyne::CGI::Simple'->new($self->{'_r'}) || (return err('unable to get WebDyne::CGI object'))
l!l
80
MC/DC0%0/1
'WebDyne::CGI::Simple'->new($self->{'_r'}) || (return err('unable to get WebDyne::CGI object'))
'WebDyne::CGI::Simple'->new($self->{'_r'})
Truth table50%1/2
A
A= 'WebDyne::CGI::Simple'->new($self->{'_r'})
Aresult
11
00
4205 return err('unable to get WebDyne::CGI object');
4206 8 $self->CGI_param_expand($cgi_or);
4207 8 debug("cgi_or: $cgi_or");
4208 8 ▶ eval {} if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 8 8
4209  
4210  
4211 # Return new CGI object
4212 #
4213 8 $cgi_or;
4214  
4215 };
4216  
4217 }
4218  
4219  
4220 sub html_tiny {
4221  
4222 8 ▶ my $self=shift();
Subroutine html_tiny: called CC=3 SCAR=13.3
Pod undocumented
4223 8 debug("$self get HTML::Tiny object");
4224 8 ▶ return ($self->{'_html_tiny_or'} ||= (WebDyne::HTML::Tiny->new(mode => WEBDYNE_HTML_TINY_MODE, r=>$self->{'_r'}) ||
Condition33%2/6
$self->{"_html_tiny_or"} ||= "WebDyne::HTML::Tiny"->new("mode", "html", "r", $self->{"_r"}) || err("unable to instantiate new WebDybe::HTTP::Tiny object")
l!l&&r!l&&!r
080
'WebDyne::HTML::Tiny'->new('mode', 'html', 'r', $self->{'_r'}) || err('unable to instantiate new WebDybe::HTTP::Tiny object')
l!l&&r!l&&!r
800
MC/DC0%0/3
$self->{"_html_tiny_or"} ||= "WebDyne::HTML::Tiny"->new("mode", "html", "r", $self->{"_r"}) || err("unable to instantiate new WebDybe::HTTP::Tiny object")
$self->{"_html_tiny_or"} 'WebDyne::HTML::Tiny'->new('mode', 'html', 'r', $self->{'_r'}) err('unable to instantiate new WebDybe::HTTP::Tiny object')
Truth table0%0/4
A ||= B || C
A= $self->{"_html_tiny_or"}B= 'WebDyne::HTML::Tiny'->new('mode', 'html', 'r', $self->{'_r'})C= err('unable to instantiate new WebDybe::HTTP::Tiny object')
ABCresult
1XX1
01X1
0011
0000
4225 err('unable to instantiate new WebDybe::HTTP::Tiny object')));
4226  
4227 }
4228  
4229  
4230 sub CGI_param_expand {
4231  
4232 # Expand CGI params if the form "foo&a=b" into "foo=param", "a=b", so if we
4233 # have HTML like <submit name="foo&bar=1"> it will expand out to params as
4234 # foo=>Submit, bar=>1
4235 #
4236 8 ▶ my ($self, $cgi_or)=@_;
Subroutine CGI_param_expand: called CC=5 SCAR=26.7
Pod undocumented
4237 8 ▶ $cgi_or ||
Branch: 1 branch
BranchTrueFalseTotal
$cgi_or or return err("unable to get CGI object") 0 8 8
4238 return err('unable to get CGI object');
4239 8 debug("$cgi_or param_expand");
4240 8 foreach my $param (grep /=/, $cgi_or->param()) {
4241 0 my (@pairs)=split(/&/, $param);
4242 0 debug('pairs: %s', Dumper(\@pairs));
4243 0 foreach my $pair (@pairs) {
4244 0 my ($key, $value)=split('=', $pair, 2);
4245 0 ▶ defined($value) || ($value=$cgi_or->param($param));
Branch: 1 branch
BranchTrueFalseTotal
defined $value or $value = $cgi_or->param($param) 0 0 0
4246 0 my @value=$cgi_or->param($key);
4247 0 push @value, $value;
4248 0 debug("$cgi_or param splt $key => $value");
4249 0 $cgi_or->param($key, @value);
4250 }
4251 0 $cgi_or->delete($param);
4252 }
4253 }
4254  
4255  
4256 sub request {
4257  
4258  
4259 # Accessor method for Apache request object
4260 #
4261 2 ▶ my $self=shift();
Subroutine request: called CC=2 SCAR=7.2
Pod undocumented
4262 2 ▶ return @_ ? $self->{'_r'}=shift() : $self->{'_r'};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 2 2
4263  
4264 }
4265  
4266  
4267 sub dump {
4268  
4269  
4270 # Run the dump CGI dump routine. Is here because it produces different output each
4271 # time it is run, and if not a WebDyne tag it would be optimised to static text by
4272 # the compiler
4273 #
4274 0 ▶ my ($self, $data_ar, $attr_hr)=@_;
Subroutine dump: not called CC=16 SCAR=56.1
Pod undocumented
4275 0 ▶ my $cgi_or=$self->CGI() ||
Condition0%0/2
$self->CGI || (return err())
l!l
00
MC/DC0%0/1
$self->CGI || (return err())
$self->CGI
Truth table0%0/2
A
A= $self->CGI
Aresult
11
00
4276 return err();
4277 0 my @html;
4278 0 ▶ if (WEBDYNE_DUMP_FLAG || $attr_hr->{'force'} || $attr_hr->{'display'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_hr->{'force'} or $attr_hr->{'display'}) { } 0 0 0
Condition0%0/3
$attr_hr->{"force"} or $attr_hr->{"display"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr_hr->{"force"} or $attr_hr->{"display"}
$attr_hr->{"force"} $attr_hr->{"display"}
Truth table0%0/3
A or B
A= $attr_hr->{"force"}B= $attr_hr->{"display"}
ABresult
1X1
011
000
4279
4280  
4281 # Always do CGI vars
4282 #
4283 0 push @html, Data::Dumper->Dump([scalar $cgi_or->Vars()], ['WebDyne::CGI::Simple']);
4284
4285
4286 # Others are optional. Environment
4287 #
4288 0 ▶ if ($attr_hr->{'env'} || $attr_hr->{'all'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_hr->{"env"} or $attr_hr->{"all"}) 0 0 0
Condition0%0/3
$attr_hr->{"env"} or $attr_hr->{"all"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr_hr->{"env"} or $attr_hr->{"all"}
$attr_hr->{"env"} $attr_hr->{"all"}
Truth table0%0/3
A or B
A= $attr_hr->{"env"}B= $attr_hr->{"all"}
ABresult
1X1
011
000
4289
4290  
4291 # Environment
4292 #
4293 0 push @html, Data::Dumper->Dump([\%ENV], ['WebDyne::ENV']);
4294
4295 }
4296
4297
4298 # @INC Library path
4299 #
4300 0 ▶ if ($attr_hr->{'lib'} || $attr_hr->{'inc'} || $attr_hr->{'all'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_hr->{"lib"} or $attr_hr->{"inc"} or $attr_hr->{"all"}) 0 0 0
Condition0%0/6
$attr_hr->{"lib"} or $attr_hr->{"inc"} or $attr_hr->{"all"}
l!l&&r!l&&!r
000
$attr_hr->{"lib"} or $attr_hr->{"inc"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$attr_hr->{"lib"} or $attr_hr->{"inc"} or $attr_hr->{"all"}
$attr_hr->{"lib"} $attr_hr->{"inc"} $attr_hr->{"all"}
Truth table0%0/4
A or B or C
A= $attr_hr->{"lib"}B= $attr_hr->{"inc"}C= $attr_hr->{"all"}
ABCresult
1XX1
01X1
0011
0000
4301
4302
4303 # @INC wanted
4304 #
4305 0 push @html, Data::Dumper->Dump([\@INC], ['WebDyne::INC']);
4306  
4307 # %INC wanted
4308 #
4309 0 push @html, Data::Dumper->Dump([\%INC], ['WebDyne::INC']);
4310
4311 }
4312
4313
4314  
4315 # WebDyne constants
4316 #
4317 0 ▶ if ($attr_hr->{'constant'} || $attr_hr->{'all'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_hr->{"constant"} or $attr_hr->{"all"}) 0 0 0
Condition0%0/3
$attr_hr->{"constant"} or $attr_hr->{"all"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr_hr->{"constant"} or $attr_hr->{"all"}
$attr_hr->{"constant"} $attr_hr->{"all"}
Truth table0%0/3
A or B
A= $attr_hr->{"constant"}B= $attr_hr->{"all"}
ABresult
1X1
011
000
4318
4319  
4320 # Constant
4321 #
4322 #my %constant=map { $_=> encode_entities($WebDyne::Constant::Constant{$_}) } keys(%WebDyne::Constant::Constant);
4323 #push @html, Data::Dumper->Dump([\%constant], ['WebDyne::Constant']);
4324  
4325  
4326 # Update - take from WebDyne module vars, don't trust hasn't changed from Constants file
4327 #
4328 0 my %constant;
4329 0 ▶ while (my ($k, $cv) = each %WebDyne::Constant::Constant) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %WebDyne::Constant::Constant) 0 0 0
4330 0 my $wv=${"WebDyne::${k}"};
4331 0 ▶ $constant{$k}=($cv eq $wv) ? $wv : "$wv [$cv]";
Branch: 1 branch
BranchTrueFalseTotal
$cv eq $wv ? : 0 0 0
4332 }
4333 0 my $constant_dumper=Data::Dumper->Dump([\%constant], ['WebDyne::Constant']);
4334 0 $constant_dumper=$cgi_or->escapeHTML($constant_dumper);
4335 0 push @html, $constant_dumper;
4336
4337 }
4338
4339
4340 # Dir_config
4341 #
4342 0 ▶ if ($attr_hr->{'dir_config'} || $attr_hr->{'all'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_hr->{"dir_config"} or $attr_hr->{"all"}) 0 0 0
Condition0%0/3
$attr_hr->{"dir_config"} or $attr_hr->{"all"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr_hr->{"dir_config"} or $attr_hr->{"all"}
$attr_hr->{"dir_config"} $attr_hr->{"all"}
Truth table0%0/3
A or B
A= $attr_hr->{"dir_config"}B= $attr_hr->{"all"}
ABresult
1X1
011
000
4343
4344  
4345 # Yes, wanted
4346 #
4347 0 push @html, Data::Dumper->Dump([$self->r->dir_config()], ['WebDyne::Dir_Config']);
4348
4349 }
4350
4351  
4352  
4353 # Version mandatory
4354 #
4355 0 my %version=(
4356 VERSION => $VERSION,
4357 VERSION_GIT_SHA => $VERSION_GIT_SHA
4358 );
4359 0 push @html, Data::Dumper->Dump([\%version], ['WebDyne::VERSION']);
4360
4361  
4362 # Render time
4363 #
4364 0 push @html, sprintf('Render time: %.3f sec', $self->render_time());
4365
4366
4367 # Wrap in a pre tag and return
4368 #
4369 0 ▶ my $html_or=$self->{'_html_tiny_or'} || $self->html_tiny();
Condition0%0/3
$self->{'_html_tiny_or'} || $self->html_tiny
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_html_tiny_or'} || $self->html_tiny
$self->{'_html_tiny_or'} $self->html_tiny
Truth table0%0/3
A || B
A= $self->{'_html_tiny_or'}B= $self->html_tiny
ABresult
1X1
011
000
4370 0 return \($html_or->pre(join("\n", @html)));
4371
4372 }
4373 else {
4374
4375 # Not wanted, return nothing
4376 #
4377 0 return \undef;
4378 }
4379  
4380 }
4381  
4382  
4383 sub cwd {
4384  
4385 # Return cwd of current psp file
4386 #
4387 11 ▶ my $self=shift();
Subroutine cwd: called CC=4 SCAR=15.0
Pod undocumented
4388 11 ▶ return $self->{'_cwd'} ||= do {
Condition66%2/3
$self->{"_cwd"} ||= do { debug("$self, fn: %s", $self->{"_r"}->filename); my $fn = $self->{"_r"}->filename; my $dn; if (-d ($dn = "File::Spec"->rel2abs($fn))) { debug("return existing dn: $dn"); $dn; } else { $dn = ("File::Spec"->splitpath($fn))[1] || fastcwd(); debug("return calculated dn: $dn"); $dn; } }
l!l&&r!l&&!r
380
MC/DC0%0/2
$self->{"_cwd"} ||= do { debug("$self, fn: %s", $self->{"_r"}->filename); my $fn = $self->{"_r"}->filename; my $dn; if (-d ($dn = "File::Spec"->rel2abs($fn))) { debug("return existing dn: $dn"); $dn; } else { $dn = ("File::Spec"->splitpath($fn))[1] || fastcwd(); debug("return calculated dn: $dn"); $dn; } }
$self->{"_cwd"} do { debug("$self, fn: %s", $self->{"_r"}->filename); my $fn = $self->{"_r"}->filename; my $dn; if (-d ($dn = "File::Spec"->rel2abs($fn))) { debug("return existing dn: $dn"); $dn; } else { $dn = ("File::Spec"->splitpath($fn))[1] || fastcwd(); debug("return calculated dn: $dn"); $dn; } }
Truth table66%2/3
A ||= B
A= $self->{"_cwd"}B= do { debug("$self, fn: %s", $self->{"_r"}->filename); my $fn = $self->{"_r"}->filename; my $dn; if (-d ($dn = "File::Spec"->rel2abs($fn))) { debug("return existing dn: $dn"); $dn; } else { $dn = ("File::Spec"->splitpath($fn))[1] || fastcwd(); debug("return calculated dn: $dn"); $dn; } }
ABresult
1X1
011
000
4389 8 debug("$self, fn: %s", $self->{'_r'}->filename());
4390 8 my $fn=$self->{'_r'}->filename();
4391 8 my $dn;
4392 8 ▶ unless (-d ($dn=File::Spec->rel2abs($fn))) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d ($dn = 'File::Spec'->rel2abs($fn))) { } 0 8 8
4393 # Not a directory, must be file
4394 #
4395 8 ▶ $dn=(File::Spec->splitpath($fn))[1] || fastcwd();
Condition33%1/3
('File::Spec'->splitpath($fn))[1] || fastcwd()
l!l&&r!l&&!r
800
MC/DC0%0/2
('File::Spec'->splitpath($fn))[1] || fastcwd()
('File::Spec'->splitpath($fn))[1] fastcwd()
Truth table33%1/3
A || B
A= ('File::Spec'->splitpath($fn))[1]B= fastcwd()
ABresult
1X1
011
000
4396 8 debug("return calculated dn: $dn");
4397 8 $dn;
4398 }
4399 else {
4400 0 debug("return existing dn: $dn");
4401 0 $dn;
4402 }
4403
4404 }
4405  
4406 }
4407  
4408  
4409 sub filename {
4410  
4411 # Return the full filename from the request handler
4412 #
4413 0 ▶ return shift()->{'_r'}->filename();
Subroutine filename: not called CC=1 SCAR=6.9
Pod undocumented
4414  
4415 }
4416  
4417  
4418 sub rel2abs {
4419  
4420  
4421 # Concatenate cwd onto supplied file
4422 #
4423 0 ▶ my ($self, $fn)=@_;
Subroutine rel2abs: not called CC=1 SCAR=6.9
Pod undocumented
4424 0 return File::Spec->rel2abs($fn, $self->cwd());
4425  
4426 }
4427  
4428  
4429 sub source_mtime {
4430  
4431 # Get mtime of source file. Is a no-op here so can be subclassed by other handlers. We
4432 # return undef, means engine will use original source mtime
4433 #
4434 8 ▶ \undef;
Subroutine source_mtime: called CC=1 SCAR=0.0
Pod undocumented
4435  
4436 }
4437  
4438  
4439 sub cache_mtime {
4440  
4441 # Mtime accessor - will return mtime of srce inode (default), or mtime of supplied
4442 # inode if given
4443 #
4444 0 ▶ my $self=shift();
Subroutine cache_mtime: not called CC=3 SCAR=24.8
Pod undocumented
4445 0 debug("self: $self");
4446 my $inode_pn=${
4447 0 ▶ $self->cache_filename(@_) || return err()};
Branch: 1 branch
BranchTrueFalseTotal
$self->cache_filename(@_) or return err() 0 0 0
4448 0 debug("inode_pn: $inode_pn");
4449 0 ▶ my $mtime=$inode_pn ? (stat($inode_pn))[9] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$inode_pn ? : 0 0 0
4450 0 return \$mtime;
4451  
4452 }
4453  
4454  
4455 sub render_time {
4456  
4457 # Time so far in render
4458 #
4459 0 ▶ my $self=shift();
Subroutine render_time: not called CC=1 SCAR=6.9
Pod undocumented
4460 0 return time()-$self->{'_time'}
4461
4462 }
4463  
4464  
4465 sub cache_filename {
4466  
4467 # Get cache fq filename given inode or using srce inode if not supplied
4468 #
4469 0 ▶ my $self=shift();
Subroutine cache_filename: not called CC=2 SCAR=17.9
Pod undocumented
4470 0 ▶ my $inode=@_ ? shift() : $self->{'_inode'};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
4471 0 my $inode_pn=File::Spec->catfile(WEBDYNE_CACHE_DN, $inode) if WEBDYNE_CACHE_DN;
4472 0 \$inode_pn;
4473  
4474 }
4475  
4476  
4477 sub cache_html {
4478  
4479 # Write an inode that is fully HTML out to disk to we dispatch it as a subrequest
4480 # next time. This is a &register_cleanup callback
4481 #
4482 0 ▶ my ($cache_pn, $html_sr)=@_;
Subroutine cache_html: not called CC=5 SCAR=34.0
Pod undocumented
4483 0 debug("cache_html @_");
4484  
4485 # If there was an error no html_sr will be supplied
4486 #
4487 0 ▶ if ($html_sr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html_sr) 0 0 0
4488  
4489 # Write to a temporary file in the same directory, then rename into
4490 # place so other workers never see a partially written cache file.
4491 #
4492 0 my $cache_tmp_pn="${cache_pn}.$$";
4493 0 ▶ my $cache_fh=IO::File->new($cache_tmp_pn, O_WRONLY | O_CREAT | O_TRUNC) ||
Condition0%0/2
'IO::File'->new($cache_tmp_pn, 577) || (return warn("unable to open cache file $cache_tmp_pn for write, $!"))
l!l
00
MC/DC0%0/1
'IO::File'->new($cache_tmp_pn, 577) || (return warn("unable to open cache file $cache_tmp_pn for write, $!"))
'IO::File'->new($cache_tmp_pn, 577)
Truth table0%0/2
A
A= 'IO::File'->new($cache_tmp_pn, 577)
Aresult
11
00
4494 return warn("unable to open cache file $cache_tmp_pn for write, $!");
4495 0 CORE::print $cache_fh ${$html_sr};
4496 0 ▶ $cache_fh->close() ||
Branch: 1 branch
BranchTrueFalseTotal
$cache_fh->close or return warn("unable to close cache file $cache_tmp_pn, $!") 0 0 0
4497 return warn("unable to close cache file $cache_tmp_pn, $!");
4498 0 ▶ rename($cache_tmp_pn, $cache_pn) ||
Branch: 1 branch
BranchTrueFalseTotal
rename $cache_tmp_pn, $cache_pn or return warn("unable to rename cache file $cache_tmp_pn to $cache_pn, $!") 0 0 0
4499 return warn("unable to rename cache file $cache_tmp_pn to $cache_pn, $!");
4500 }
4501 0 \undef;
4502  
4503 }
4504  
4505  
4506 sub cache_compile {
4507  
4508 # Compile flag accessor - if set will force inode recompile, regardless of mtime
4509 #
4510 0 ▶ my $self=shift();
Subroutine cache_compile: not called CC=2 SCAR=17.9
Pod undocumented
4511 0 ▶ @_ && ($self->{'_compile'}=shift());
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"_compile"} = shift() 0 0 0
4512 0 debug("cache_compile set to %s", $self->{'_compile'});
4513 0 \$self->{'_compile'};
4514  
4515 }
4516  
4517  
4518 sub filter {
4519  
4520  
4521 # No op
4522 #
4523 0 ▶ my ($self, $data_ar)=@_;
Subroutine filter: not called CC=1 SCAR=6.9
Pod undocumented
4524 0 debug('in filter');
4525 0 $data_ar;
4526  
4527 }
4528  
4529  
4530 sub meta {
4531  
4532 # Return/read/update meta info hash
4533 #
4534 0 ▶ my ($self, @param)=@_;
Subroutine meta: not called CC=5 SCAR=34.0
Pod undocumented
4535 0 my $inode=$self->{'_inode'};
4536 0 debug("get meta data for inode $inode");
4537 0 ▶ my $meta_hr=$Package{'_cache'}{$inode}{'meta'} ||= (delete $self->{'_meta_hr'} || {});
Condition0%0/5
$WebDyne::Package{"_cache"}{$inode}{"meta"} ||= delete $self->{"_meta_hr"} || {}
l!l&&r!l&&!r
000
delete $self->{'_meta_hr'} || {}
l!l
00
MC/DC0%0/2
$WebDyne::Package{"_cache"}{$inode}{"meta"} ||= delete $self->{"_meta_hr"} || {}
$WebDyne::Package{"_cache"}{$inode}{"meta"} delete $self->{'_meta_hr'}
Truth table0%0/3
A ||= B
A= $WebDyne::Package{"_cache"}{$inode}{"meta"}B= delete $self->{'_meta_hr'}
ABresult
1X1
011
000
4538 0 debug("existing meta $meta_hr %s", Dumper($meta_hr));
4539 0 ▶ if (@param == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (@param == 2) { } 0 0 0
elsif (@param) { } 0 0 0
4540 0 return $meta_hr->{$param[0]}=$param[1];
4541 }
4542 elsif (@param) {
4543 0 return $meta_hr->{$param[0]};
4544 }
4545 else {
4546 0 return $meta_hr;
4547 }
4548  
4549 }
4550  
4551  
4552 sub static {
4553  
4554  
4555 # Set/get static flag for this instance only. If all instances wanted
4556 # set in meta data. This method used by WebDyne::Static module
4557 #
4558 0 ▶ my ($self, $static)=@_;
Subroutine static: not called CC=4 SCAR=30.0
Pod undocumented
4559 0 debug("self: $self, static: $static");
4560
4561
4562 # Set or get
4563 #
4564 0 ▶ if (defined($static)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $static) { } 0 0 0
4565
4566  
4567 # Set
4568 #
4569 0 $self->meta()->{'static'}=$static;
4570 0 return $self->{'_static'}=$static;
4571
4572 }
4573 else {
4574
4575 # Get
4576 #
4577 0 ▶ return $self->meta()->{'static'} || $self->{'_static'} || 0
Condition0%0/5
$self->meta->{'static'} || $self->{'_static'} || 0
l!l
00
$self->meta->{"static"} or $self->{"_static"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->meta->{'static'} || $self->{'_static'} || 0
$self->meta->{"static"} $self->{"_static"}
Truth table0%0/3
A or B
A= $self->meta->{"static"}B= $self->{"_static"}
ABresult
1X1
011
000
4578
4579 }
4580  
4581 }
4582  
4583  
4584 sub cache {
4585  
4586 # Set cache handler for this instance only. If all instances wanted
4587 # set in meta data. This method used by WebDyne::Cache module
4588 #
4589 0 ▶ my $self=shift();
Subroutine cache: not called CC=2 SCAR=17.9
Pod undocumented
4590 0 ▶ $self->{'_cache'}=shift() ||
Condition0%0/2
shift() || (return err('cache code ref or method name must be supplied'))
l!l
00
MC/DC0%0/1
shift() || (return err('cache code ref or method name must be supplied'))
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
4591 return err('cache code ref or method name must be supplied');
4592  
4593 }
4594  
4595  
4596 sub set_filter {
4597  
4598 # Set cache handler for this instance only. If all instances wanted
4599 # set in meta data. This method used by WebDyne::Cache module
4600 #
4601 0 ▶ my $self=shift();
Subroutine set_filter: not called CC=2 SCAR=17.9
Pod undocumented
4602 0 ▶ $self->{'_filter'}=shift() ||
Condition0%0/2
shift() || (return err('filter name must be supplied'))
l!l
00
MC/DC0%0/1
shift() || (return err('filter name must be supplied'))
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
4603 return err('filter name must be supplied');
4604  
4605 }
4606  
4607  
4608 sub set_handler {
4609  
4610  
4611 # Set/return internal handler. Only good in __PERL__ block, after
4612 # that is too late !
4613 #
4614 0 ▶ my $self=shift();
Subroutine set_handler: not called CC=3 SCAR=24.8
Pod undocumented
4615 0 ▶ my $meta_hr=$self->meta() || return err();
Condition0%0/2
$self->meta || (return err())
l!l
00
MC/DC0%0/1
$self->meta || (return err())
$self->meta
Truth table0%0/2
A
A= $self->meta
Aresult
11
00
4616 0 ▶ @_ && ($meta_hr->{'handler'}=shift());
Branch: 1 branch
BranchTrueFalseTotal
@_ and $meta_hr->{"handler"} = shift() 0 0 0
4617 0 \$meta_hr->{'handler'};
4618  
4619 }
4620  
4621  
4622 sub select {
4623  
4624  
4625 # If we are in select mode where print output is redirected to handler output
4626 #
4627 0 ▶ shift->{'_select'};
Subroutine select: not called CC=1 SCAR=6.9
Pod undocumented
4628  
4629 }
4630  
4631  
4632 sub inode {
4633  
4634 # Return or set inode name
4635 #
4636 0 ▶ my $self=shift();
Subroutine inode: not called CC=4 SCAR=30.0
Pod undocumented
4637 0 debug("self: $self, inode: %s", Dumper(\@_));
4638 0 ▶ my $r=$self->r() ||
Condition0%0/2
$self->r || (return err('unable to get request handler'))
l!l
00
MC/DC0%0/1
$self->r || (return err('unable to get request handler'))
$self->r
Truth table0%0/2
A
A= $self->r
Aresult
11
00
4639 return err('unable to get request handler');
4640 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
4641 0 $self->{'_inode'}=md5_hex(ref($self), $r->location, $r->filename(), @_);
4642 }
4643 else {
4644 0 ▶ $self->{'_inode'} ||=
Condition0%0/3
$self->{"_inode"} ||= md5_hex(ref $self, $r->location, $r->filename)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_inode"} ||= md5_hex(ref $self, $r->location, $r->filename)
$self->{"_inode"} md5_hex(ref $self, $r->location, $r->filename)
Truth table0%0/3
A ||= B
A= $self->{"_inode"}B= md5_hex(ref $self, $r->location, $r->filename)
ABresult
1X1
011
000
4645 md5_hex(ref($self), $r->location, $r->filename());
4646 }
4647 0 return $self->{'_inode'};
4648  
4649 }
4650  
4651  
4652 sub data_ar_err {
4653  
4654 # Return last data_ar block off error hint stack
4655 #
4656 0 ▶ my $self=shift();
Subroutine data_ar_err: not called CC=1 SCAR=6.9
Pod undocumented
4657 0 debug("self: $self");
4658 0 return $self->{'_data_ar_err'}[-1];
4659
4660 }
4661  
4662  
4663 sub data_ar_html_srce_fn {
4664  
4665  
4666 # The file name that this data node was sourced from
4667 #
4668 0 ▶ my ($self, $data_ar)=@_;
Subroutine data_ar_html_srce_fn: not called CC=3 SCAR=24.8
Pod undocumented
4669 0 debug("self: $self, data_ar: $data_ar");
4670 0 ▶ if ($data_ar ||= $self->data_ar_err()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_ar ||= $self->data_ar_err) 0 0 0
Condition0%0/3
$data_ar ||= $self->data_ar_err
l!l&&r!l&&!r
000
MC/DC0%0/2
$data_ar ||= $self->data_ar_err
$data_ar $self->data_ar_err
Truth table0%0/3
A ||= B
A= $data_arB= $self->data_ar_err
ABresult
1X1
011
000
4671 0 return ${$data_ar->[WEBDYNE_NODE_SRCE_IX]}
4672 }
4673  
4674 }
4675  
4676  
4677 sub data_ar_html_line_no {
4678  
4679  
4680 # The line number (in the original HTML file) this data node was sourced from. Return tag start line in scalar ref, tag start + tag end in array ref
4681 #
4682 0 ▶ my ($self, $data_ar)=@_;
Subroutine data_ar_html_line_no: not called CC=4 SCAR=30.0
Pod undocumented
4683 0 debug("self: $self, data_ar: $data_ar");
4684 0 ▶ if ($data_ar ||= $self->data_ar_err()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_ar ||= $self->data_ar_err) 0 0 0
Condition0%0/3
$data_ar ||= $self->data_ar_err
l!l&&r!l&&!r
000
MC/DC0%0/2
$data_ar ||= $self->data_ar_err
$data_ar $self->data_ar_err
Truth table0%0/3
A ||= B
A= $data_arB= $self->data_ar_err
ABresult
1X1
011
000
4685 0 ▶ return wantarray ? @{$data_ar}[WEBDYNE_NODE_LINE_IX, WEBDYNE_NODE_LINE_TAG_END_IX] : $data_ar->[WEBDYNE_NODE_LINE_IX];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
4686 }
4687  
4688  
4689 }
4690  
4691  
4692 sub print {
4693  
4694 0 ▶ my $self=shift();
Subroutine print: not called CC=5 SCAR=34.0
Pod undocumented
4695 0 ▶ debug("$self in print, autonewline: %d, %s", $self->autonewline() ? 1 : 0, Dumper(\@_));
Branch: 1 branch
BranchTrueFalseTotal
$self->autonewline ? : 0 0 0
4696 0 ▶ return $self->say(@_) if $self->{'_autonewline'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_autonewline"} 0 0 0
4697 #push @{$self->{'_print_ar'} ||= []}, [map {(ref($_) eq 'ARRAY') ? @{$_} : $_ } @_];
4698 0 ▶ push @{$self->{'_print_ar'} ||= []}, map {(ref($_) eq 'ARRAY') ? @{$_} : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 0 0
Condition0%0/2
$self->{"_print_ar"} ||= []
l!l
00
MC/DC0%0/1
$self->{"_print_ar"} ||= []
$self->{"_print_ar"}
Truth table0%0/2
A
A= $self->{"_print_ar"}
Aresult
11
00
4699 0 return \undef;
4700  
4701 }
4702  
4703  
4704 sub printf {
4705  
4706 0 ▶ my $self=shift();
Subroutine printf: not called CC=2 SCAR=17.9
Pod undocumented
4707 0 debug("$self in printf, %s", Dumper(\@_));
4708 #push @{$self->{'_print_ar'} ||= []}, [sprintf(shift(), @_)];
4709 0 ▶ push @{$self->{'_print_ar'} ||= []}, sprintf(shift(), @_);
Condition0%0/2
$self->{"_print_ar"} ||= []
l!l
00
MC/DC0%0/1
$self->{"_print_ar"} ||= []
$self->{"_print_ar"}
Truth table0%0/2
A
A= $self->{"_print_ar"}
Aresult
11
00
4710 0 return \undef;
4711  
4712 }
4713  
4714  
4715 sub autonewline {
4716  
4717 14 ▶ my $self=shift();
Subroutine autonewline: called CC=3 SCAR=11.2
Pod undocumented
4718 14 debug("$self in autonewline");
4719 14 my $autonewline=$self->{'_autonewline'};
4720 14 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 0 14
4721 14 ▶ $self->{'_autonewline'}=($_[0] ? "\n" : '');
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 14 14
4722 }
4723 14 return $autonewline;
4724 #return @_ ? $self->{'_autonewline'}=($_[0] ? "\n" : 0) : $self->{'_autonewline'};
4725
4726 }
4727  
4728  
4729 sub say {
4730  
4731 0 ▶ my $self=shift();
Subroutine say: not called CC=5 SCAR=34.0
Pod undocumented
4732 0 debug("$self in say, %s", Dumper(\@_));
4733 0 ▶ my $print_ar=($self->{'_print_ar'} ||= []);
Condition0%0/2
$self->{"_print_ar"} ||= []
l!l
00
MC/DC0%0/1
$self->{"_print_ar"} ||= []
$self->{"_print_ar"}
Truth table0%0/2
A
A= $self->{"_print_ar"}
Aresult
11
00
4734 0 foreach my $item (@_) {
4735 0 ▶ if (ref($item) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $item eq 'ARRAY') { } 0 0 0
elsif (ref $item eq 'SCALAR') { } 0 0 0
4736 0 push @{$print_ar}, join("\n", @{$item})
4737 }
4738 elsif (ref($item) eq 'SCALAR') {
4739 0 push @{$print_ar}, ${$item}."\n";
4740 }
4741 else {
4742 0 push @{$print_ar}, $item."\n";
4743 }
4744 }
4745 0 return \undef;
4746  
4747 }
4748  
4749  
4750 sub DESTROY {
4751  
4752  
4753 # Stops AUTOLOAD chucking wobbly at end of request because no DESTROY method
4754 # found, logs total page cycle time
4755 #
4756 9 ▶ my $self=shift();
Subroutine DESTROY: called CC=2 SCAR=6.9
4757  
4758  
4759 # Call CGI reset_globals if we created a CGI object
4760 #
4761 9 ▶ $self->{'_CGI'} && (&CGI::Simple::_reset_globals);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_CGI"} and &CGI::Simple::_reset_globals 8 1 9
4762  
4763  
4764 # Work out complete request cylcle time
4765 #
4766 9 debug("in destroy self $self, param %s", Dumper(\@_));
4767 9 my $time_request=sprintf('%0.4f', time()-$self->{'_time'});
4768 9 debug("page request cycle time , $time_request sec");
4769  
4770  
4771 # Destroy object
4772 #
4773 9 %{$self}=();
4774 9 undef $self;
4775  
4776 }
4777  
4778  
4779 sub webdyne_status {
4780  
4781 0 ▶ return \%Package;
Subroutine webdyne_status: not called CC=1 SCAR=6.9
Pod undocumented
4782  
4783 }
4784  
4785  
4786 sub AUTOLOAD {
4787  
4788  
4789 # Get self ref
4790 #
4791 0 ▶ my $self=$_[0];
Subroutine AUTOLOAD: not called CC=4 SCAR=30.0
4792 0 debug("AUTOLOAD $self, $AUTOLOAD");
4793  
4794  
4795 # Get method user was looking for
4796 #
4797 0 my $method=(reverse split(/\:+/, $AUTOLOAD))[0];
4798  
4799  
4800 # Vars for iterator, call stack
4801 #
4802 0 my $i; my @caller;
4803  
4804  
4805 # Start going backwards through call stack, looking for package that can
4806 # run method, pass control to it if found
4807 #
4808 0 my %caller;
4809 0 ▶ while (my $caller=(caller($i++))[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $caller = (caller $i++)[0]) 0 0 0
4810 0 ▶ next if ($caller{$caller}++);
Branch: 1 branch
BranchTrueFalseTotal
if $caller{$caller}++ 0 0 0
4811 0 push @caller, $caller;
4812 0 ▶ if (my $cr=UNIVERSAL::can($caller, $method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cr = UNIVERSAL::can($caller, $method)) 0 0 0
4813  
4814 # POLLUTE is virtually useless - no speedup in real life ..
4815 0 if (WEBDYNE_AUTOLOAD_POLLUTE) {
4816 my $class=ref($self);
4817 *{"${class}::${method}"}=$cr;
4818 }
4819  
4820 #return $cr->($self, @_);
4821 0 goto &{$cr}
4822 }
4823 }
4824  
4825  
4826 # If we get here, we could not find the method in any caller. Error
4827 #
4828 0 err("unable to find method '$method' in call stack: %s", join(', ', @caller));
4829 0 goto RENDER_ERROR;
4830  
4831 }
4832  
4833  
4834 # Package to tie select()ed output handle to so we can override print() command
4835 #
4836 package WebDyne::TieHandle;
4837 3 *debug=\&WebDyne::Util::debug;
4838  
4839  
4840 sub TIEHANDLE {
4841  
4842 8 ▶ my ($class, $self)=@_;
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
4843 8 debug("$self TIEHANDLE class: $class");
4844 8 bless \$self, $class;
4845 }
4846  
4847  
4848 sub PRINT {
4849  
4850 0 ▶ my $self=shift();
Subroutine PRINT: not called CC=1 SCAR=6.9
4851 0 debug("$self PRINT %s", join('*', @_));
4852 0 return ${$self}->print(@_);
4853  
4854 }
4855  
4856  
4857 sub PRINTF {
4858  
4859 0 ▶ my $self=shift();
Subroutine PRINTF: not called CC=1 SCAR=6.9
4860 0 debug("$self PRINTF %s", join('*', @_));
4861 0 return ${$self}->printf(@_);
4862  
4863 }
4864  
4865  
4866 sub DESTROY {
4867 8 ▶ my $self=shift();
Subroutine DESTROY: called CC=1 SCAR=0.0
4868 8 debug("$self DESTROY");
4869 8 delete ${$self}->{'_print_ar'};
4870 }
4871  
4872  
4873 sub UNTIE {
4874 8 ▶ my $self=shift();
Subroutine UNTIE: called CC=1 SCAR=0.0
4875 8 debug("$self UNTIE");
4876 8 delete ${$self}->{'_print_ar'};
4877 }
4878  
4879  
4880 sub AUTOLOAD {
4881 0 ▶ debug("AUTOLOAD %s", join('*', @_));
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
4882 }
4883  
4884  
4885 __END__
↑ Summary blib/lib/WebDyne/Err.pm »