lib/WebDyne.pm

filter: Statementstmt 39.3% 584 / 1486 Branchbran 22.1% 128 / 578 Conditioncond 16.6% 97 / 582 MC/DCmcdc 1.5% 5 / 320 Subroutinesub 48.0% 62 / 129 Podpod 0.0% 0 / 63 totaltotal 27.7% 876 / 3158 CC 537 SCAR 66.7
CC
537
Cov
31%
handler
3681.4
include
1406.0
subrequest
462.0
CRAP 787.3
« blib/lib/WebDyne/Install/Apache.pm ↑ Summary 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.029';
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 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
127 3 eval {require Time::HiRes; Time::HiRes->import('time')};
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 8 ▶sub html_sr {
Subroutine html_sr: called CC=13 SCAR=26.6
Pod undocumented
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)=@_;
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() 8 0 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 8 ▶sub handler : method { # no subsort
Subroutine handler: called CC=114 SCAR=82.1
Pod undocumented
209  
210  
211 # Get self ref/class, request ref
212 #
213 8 my ($self, $r, $param_hr)=@_;
214 8 debug("handler called with self: $self, r: $r, MP2: $MP2, param: %s", Dumper($param_hr));
215
216
217 # Update r if needed
218 #
219 8 ▶ if (ref($r)=~/^Apache/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($r) =~ /^Apache/) 0 8 8
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 8 my $time=($self->{'_time'}=time());
231  
232  
233 # Work out class and correct self ref
234 #
235 8 ▶ 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
080
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 8 %{delete $self->{'_self'}},
245  
246 );
247 8 $self=bless \%self, $self;
248 8 ref($self);
249  
250  
251 };
252  
253  
254 # Setup error handlers
255 #
256 8 local $SIG{'__DIE__'} =\&handler_die;
257 8 local $SIG{'__WARN__'}=\&handler_warn;
258
259  
260 # Debug
261 #
262 8 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 0 ▶ if ($r->header_only()) {return &head_request($r)}
Branch: 1 branch
BranchTrueFalseTotal
if ($r->header_only) 0 8 8
269  
270  
271 # Debug
272 #
273 debug(
274 8 "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 8 ▶ 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
800
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 8 my $srce_mtime;
293 8 ▶ $srce_mtime=(stat(_))[9] if (-f $srce_pn);
Branch: 1 branch
BranchTrueFalseTotal
if -f $srce_pn 8 0 8
294 8 ▶ 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) } 8 0 8
295  
296 # Found file but couldn't stat or similar issue
297 #
298 0 debug("srce_mtime for file '$srce_pn' not found, could not stat !");
299 0 ▶ return $MP2 ? &Apache::DECLINED : $r->status(HTTP_NOT_FOUND);
Branch: 1 branch
BranchTrueFalseTotal
$WebDyne::MP2 ? : 0 0 0
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()}
Condition40%2/5
${$self->source_mtime($srce_mtime) or return $self->err_html;} || $srce_mtime
l!l&&r!l&&!r
080
$self->source_mtime($srce_mtime) || (return $self->err_html)
l!l
80
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
MC/DC0%0/1
$self->source_mtime($srce_mtime) || (return $self->err_html)
$self->source_mtime($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
Truth table50%1/2
A
A= $self->source_mtime($srce_mtime)
Aresult
11
00
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} } 0 3 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")) 3 0 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 0 ▶ my $cr=set_subname('cache_disk_writeback_anon', sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
850 &cache_html(
851 0 ▶ "${cache_pn}.html", ($meta_hr->{'static'} || $self->{'_static'}) ? $html_sr : \$data_ar->[0])
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 0 ▶ my $cr=set_subname('cache_mem_writeback_anon', sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
862 $cache_inode_hr->{'data'}=[
863 0 ▶ ($meta_hr->{'static'} || $self->{'_static'}) ? ${$html_sr} : $data_ar->[0]]
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', $!") 8 0 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 0 ▶ $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 0 ▶sub handler_die {
Subroutine handler_die: not called CC=5 SCAR=34.0
Pod undocumented
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]));
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 0 ▶sub handler_warn {
Subroutine handler_warn: not called CC=2 SCAR=17.9
Pod undocumented
1150  
1151 # Warn signal handler
1152 #
1153 0 debug('in __WARN__ sig handler, caller %s', join(',', (caller(0))[0..3]));
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 4 ▶sub init {
Subroutine init: called CC=15 SCAR=46.7
Pod undocumented
1161  
1162  
1163 # Clear Package cache and start from scratch
1164 #
1165 4 undef %Package;
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 0 ▶ *Apache::OK=sub {0};
Subroutine __ANON__: not called CC=1 SCAR=1.2
1226 0 ▶ *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 8 ▶ my $eval_perl_cr=set_subname('eval_perl_cr_anon', sub {
Subroutine __ANON__: called CC=17 SCAR=38.0
1256  
1257  
1258 # Get self ref
1259 #
1260 8 my ($self, $data_ar, $eval_param_hr, $eval_text, $index, $tag_fg)=@_;
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: 1 branch
BranchTrueFalseTotal
if (grep {ref $_ and not ref($_) =~ /(?:SCALAR|ARRAY|HASH|JSON)/;} @eval) 0 6 6
Condition33%1/3
ref $_ && !(ref($_) =~ /(?:SCALAR|ARRAY|HASH|JSON)/)
!ll&&!rl&&r
060
MC/DC0%0/2
ref $_ && !(ref($_) =~ /(?:SCALAR|ARRAY|HASH|JSON)/)
ref $_ !(ref($_) =~ /(?:SCALAR|ARRAY|HASH|JSON)/)
Truth table33%1/3
A && not(B)
A= ref $_B= !(ref($_) =~ /(?:SCALAR|ARRAY|HASH|JSON)/)
ABresult
0X0
100
111
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 0 ▶ my $eval_safe_cr=set_subname('eval_safe_cr_anon', sub {
Subroutine __ANON__: not called CC=20 SCAR=60.4
1416  
1417  
1418 # Get self ref
1419 #
1420 0 my ($self, $data_ar, $eval_param_hr, $eval_text, $index)=@_;
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 0 ▶ my $eval_hash_cr=set_subname('eval_hash_cr_anon', sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1532  
1533  
1534 # Run eval and turn into tied hash
1535 #
1536 0 debug('eval_hash_cr, %s', Dumper(\@_));
1537 0 ▶ tie(my %hr, 'Tie::IxHash', @{$eval_perl_cr->(@_) || return err()});
Condition0%0/2
&$eval_perl_cr(@_) || (return err())
l!l
00
MC/DC0%0/1
&$eval_perl_cr(@_) || (return err())
&$eval_perl_cr(@_)
Truth table0%0/2
A
A= &$eval_perl_cr(@_)
Aresult
11
00
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 0 ▶ my $eval_array_cr=set_subname('eval_array_cr_anon', sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1547  
1548  
1549 # Run eval and return default - which is an array ref
1550 #
1551 0 debug('eval_array_cr, %s', Dumper(\@_));
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 8 ▶ my $eval_code_cr=set_subname('eval_code_cr_anon', sub {
Subroutine __ANON__: called CC=11 SCAR=37.9
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)=@_;
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 6 ▶ my $eval_scalar_cr=set_subname('eval_scalar_cr_anon', sub {
Subroutine __ANON__: called CC=7 SCAR=29.8
1611  
1612 6 my $value=$_[2]->{$_[3]};
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 0 ▶ 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 0 ▶ '^' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1639 0 my $m=$_[3]; my $r=$_[0]->{'_r'};
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 0 ▶sub cache_clean {
Subroutine cache_clean: not called CC=2 SCAR=17.9
Pod undocumented
1654  
1655  
1656 # Get cache_hr, only param supplied
1657 #
1658 0 my $cache_hr=shift();
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 0 ▶sub head_request {
Subroutine head_request: not called CC=2 SCAR=17.9
Pod undocumented
1715  
1716  
1717 # Head request only
1718 #
1719 0 my $r=shift();
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 0 ▶sub render_reset {
Subroutine render_reset: not called CC=2 SCAR=17.9
Pod undocumented
1740  
1741 0 my ($self, $data_ar)=@_;
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 6 ▶sub render {
Subroutine render: called CC=6 SCAR=19.0
Pod undocumented
1748  
1749  
1750 # Convert data array structure into HTML
1751 #
1752 6 my ($self, $param_hr)=@_;
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 14 ▶sub render_data_ar {
Subroutine render_data_ar: called CC=8 SCAR=21.0
Pod undocumented
1784  
1785  
1786 # Convert data array structure into HTML
1787 #
1788 14 my ($self, %param)=@_;
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()};
Condition50%1/2
&$render_cr($render_cr, $self, $html_or, $node_data_ar, $param{'param'}) || (return err())
l!l
120
MC/DC0%0/1
&$render_cr($render_cr, $self, $html_or, $node_data_ar, $param{'param'}) || (return err())
&$render_cr($render_cr, $self, $html_or, $node_data_ar, $param{'param'})
Truth table50%1/2
A
A= &$render_cr($render_cr, $self, $html_or, $node_data_ar, $param{'param'})
Aresult
11
00
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 14 ▶sub render_cr {
Subroutine render_cr: called CC=23 SCAR=46.3
Pod undocumented
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)=@_;
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)
Condition0%0/2
&$render_cr($render_cr, $self, $html_or, $data_chld_ar, $param_data_hr) || (return err())
l!l
00
MC/DC0%0/1
&$render_cr($render_cr, $self, $html_or, $data_chld_ar, $param_data_hr) || (return err())
&$render_cr($render_cr, $self, $html_or, $data_chld_ar, $param_data_hr)
Truth table0%0/2
A
A= &$render_cr($render_cr, $self, $html_or, $data_chld_ar, $param_data_hr)
Aresult
11
00
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) ||
Condition50%1/2
$self->$html_tag($data_ar, $attr_hr, $param_data_hr, $html_chld) || (return err())
l!l
120
MC/DC0%0/1
$self->$html_tag($data_ar, $attr_hr, $param_data_hr, $html_chld) || (return err())
$self->$html_tag($data_ar, $attr_hr, $param_data_hr, $html_chld)
Truth table50%1/2
A
A= $self->$html_tag($data_ar, $attr_hr, $param_data_hr, $html_chld)
Aresult
11
00
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 2 ▶sub redirect {
Subroutine redirect: called CC=25 SCAR=49.2
Pod undocumented
2073  
2074  
2075 # Redirect render to different location
2076 #
2077 2 my ($self, $param_hr)=@_;
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") 2 0 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 (my $content_type=$param_hr->{'content_type'}) {
Branch: 4 branches
BranchTrueFalseTotal
if (my $content_type = $param_hr->{'content_type'}) { } 0 2 2
elsif ($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($content_type)
2153 }
2154 elsif ($redirect_type eq 'html') {
2155 0 $r->content_type(WEBDYNE_CONTENT_TYPE_HTML)
2156 }
2157 elsif ($redirect_type eq 'text') {
2158 1 $r->content_type(WEBDYNE_CONTENT_TYPE_TEXT)
2159 }
2160 elsif ($redirect_type eq 'json') {
2161 1 $r->content_type(WEBDYNE_CONTENT_TYPE_JSON)
2162 }
2163  
2164  
2165 # And length
2166 #
2167 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
2168 0 ▶ $headers_out_hr->{'Content-Length'}=length(ref($html_sr) ? ${$html_sr} : $html_sr);
Branch: 1 branch
BranchTrueFalseTotal
ref $html_sr ? : 0 2 2
2169  
2170  
2171 # Set status, send header
2172 #
2173 2 $r->status(HTTP_OK);
2174 2 ▶ $r->send_http_header() if !$MP2;
Branch: 1 branch
BranchTrueFalseTotal
unless $WebDyne::MP2 2 0 2
2175  
2176  
2177 # Print directly and shorcut return from render routine with non-harmful GOTO ! Should
2178 # always be SR, but be generous.
2179 #
2180 0 ▶ $r->print(ref($html_sr) ? ${$html_sr} : $html_sr);
Branch: 1 branch
BranchTrueFalseTotal
ref $html_sr ? : 0 2 2
2181 2 goto RENDER_COMPLETE;
2182  
2183  
2184 }
2185  
2186  
2187 }
2188  
2189  
2190 0 ▶sub subrequest {
Subroutine subrequest: not called CC=21 SCAR=61.4
Pod undocumented
2191  
2192  
2193 # Redirect render to different location
2194 #
2195 0 my ($self, $param_hr)=@_;
2196  
2197  
2198 # Debug
2199 #
2200 0 debug('in subrequest %s', Dumper($param_hr));
2201  
2202  
2203 # Get request object, var for subrequest object
2204 #
2205 0 ▶ my ($r, $cgi_or)=map {$self->$_() || return err("unable to run '$_' method")} qw(request CGI);
Condition0%0/2
$self->$_ || (return err("unable to run '${_}' method"))
l!l
00
MC/DC0%0/1
$self->$_ || (return err("unable to run '${_}' method"))
$self->$_
Truth table0%0/2
A
A= $self->$_
Aresult
11
00
2206 0 my $r_child;
2207  
2208  
2209 # Run taks appropriate for subrequest - location redirects with 302, uri does sinternal redirect,
2210 # and file sends content of file.
2211 #
2212 0 ▶ if (my $location=$param_hr->{'location'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $location = $param_hr->{"location"}) 0 0 0
2213  
2214  
2215 # Does the request handler take care of it ?
2216 #
2217 0 ▶ if (UNIVERSAL::can($r, 'redirect')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($r, 'redirect')) { } 0 0 0
2218  
2219  
2220 # Let the request handler take care of it
2221 #
2222 0 debug('handler does redirect, handing off');
2223 0 $r->redirect($location); # no return value
2224 0 return HTTP_FOUND;
2225  
2226 }
2227 else {
2228  
2229  
2230 # Must do it ourselves
2231 #
2232 0 debug('doing redirect ourselves');
2233 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
2234 0 $headers_out_hr->{'Location'}=$location;
2235 0 $r->status(HTTP_FOUND);
2236 0 ▶ $r->send_http_header if !$MP2;
Branch: 1 branch
BranchTrueFalseTotal
unless $WebDyne::MP2 0 0 0
2237 0 return HTTP_FOUND;
2238  
2239 }
2240 }
2241 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
2242  
2243 # Handle internally if possible
2244 #
2245 0 ▶ if (UNIVERSAL::can($r, 'internal_redirect')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($r, 'internal_redirect')) { } 0 0 0
2246  
2247  
2248 # Let the request handler take care of it
2249 #
2250 0 debug('handler does internal_redirect, handing off');
2251 0 $r->internal_redirect($uri); # no return value
2252 0 return $r->status;
2253  
2254 }
2255 else {
2256  
2257 # Must do it ourselves
2258 #
2259 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
2260 return err('undefined lookup_uri error');
2261 0 debug('r_child handler %s', $r->handler());
2262 0 $r->headers_out($r_child->headers_out());
2263 0 $r->uri($uri);
2264  
2265 }
2266  
2267  
2268 }
2269 elsif (my $file=$param_hr->{'file'}) {
2270  
2271 # Get cwd, make request absolute rel to cwd if no dir given.
2272 #
2273 0 my $dn=(File::Spec->splitpath($r->filename()))[1];
2274 0 my $file_pn=File::Spec->rel2abs($file, $dn);
2275  
2276  
2277 # Get a new request object
2278 #
2279 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
2280 return err('undefined lookup_file error');
2281 0 $r->headers_out($r_child->headers_out());
2282  
2283 }
2284 else {
2285  
2286  
2287 # Must be one or other
2288 #
2289 0 return err('must specify file, uri or locations for subrequest');
2290  
2291 }
2292  
2293  
2294 # Save child object, else cleanup handlers will be run when
2295 # we exit and r_child is destroyed, but before r (main) is
2296 # complete.
2297 #
2298 # UPDATE no longer needed, leave here as reminder though ..
2299 #
2300 #push @{$self->{'_r_child'}},$r_child;
2301  
2302  
2303 # Safty check after calling getting r_child - should always be
2304 # OK, but do sanity check.
2305 #
2306 0 my $status=$r_child->status();
2307 0 debug("r_child status return: $status");
2308 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
2309 0 ▶ if ($errstr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errstr) { } 0 0 0
2310 return errsubst(
2311 "error in status phase of subrequest to '%s': $errstr",
2312 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
2313 )
2314 }
2315 else {
2316 return err(
2317 "error in status phase of subrequest to '%s', return status was $status",
2318 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
2319 )
2320 }
2321 }
2322  
2323  
2324 # Debug
2325 #
2326 0 debug('cgi param %s', Dumper($param_hr->{'param'}));
2327  
2328  
2329 # Set up CGI with any new params
2330 #
2331 0 ▶ while (my ($param, $value)=each %{$param_hr->{'param'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$param_hr{"param"};}) 0 0 0
2332  
2333  
2334 # Add to CGI
2335 #
2336 0 $cgi_or->param($param, $value);
2337 0 debug("set cgi param $param, value $value");
2338  
2339  
2340 }
2341  
2342  
2343 # Debug
2344 #
2345 0 debug("about to call child handler with params self $self %s", Dumper($param_hr->{'param'}));
2346  
2347  
2348 # Change of plan - used to check result, but now pass back whatever the child returns - we
2349 # will let Apache handle any errors internally
2350 #
2351 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
2352 return err();
2353 0 debug("r_child run return status $status, rc_child status %s", $r_child->status());
2354 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
2355  
2356  
2357 }
2358  
2359  
2360 0 ▶sub eof {
Subroutine eof: not called CC=1 SCAR=6.9
Pod undocumented
2361  
2362 0 goto HANDLER_COMPLETE;
2363  
2364 }
2365  
2366  
2367 0 ▶sub erase_block {
Subroutine erase_block: not called CC=4 SCAR=30.0
Pod undocumented
2368  
2369 # Erase a block section so not rendered if encountered again
2370 #
2371 0 my ($self, $param_hr)=@_;
2372  
2373  
2374 # Has user only given name as param
2375 #
2376 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
2377  
2378  
2379 # Get block name
2380 #
2381 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
2382 return err('no block name specified');
2383 0 debug("in erase_block, name $name");
2384 0 delete $self->{'_block_param'}{$name};
2385 0 delete $self->{'_block_render'}{$name}
2386  
2387 }
2388  
2389  
2390 0 ▶sub unrender_block {
Subroutine unrender_block: not called CC=1 SCAR=6.9
Pod undocumented
2391  
2392 # Synonym for erase_block
2393 #
2394 0 return shift()->erase_block(@_);
2395  
2396 }
2397  
2398  
2399 0 ▶sub render_block {
Subroutine render_block: not called CC=17 SCAR=57.2
Pod undocumented
2400  
2401  
2402 # Render a <block> section of HTML
2403 #
2404 0 my ($self, $param_hr)=@_;
2405  
2406  
2407 # Has user only given name as param
2408 #
2409 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
2410  
2411  
2412 # Get block name
2413 #
2414 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
2415 return err('no block name specified');
2416 0 debug("in render_block, name $name");
2417  
2418  
2419 # Get current data block
2420 #
2421 #my $data_ar=$self->{'_perl'}[0] ||
2422 #return err("unable to get current data node");
2423 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
2424  
2425 #if ($WEBDYNE_DELAYED_BLOCK_RENDER) {
2426 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
2427 0 return \undef;
2428  
2429 #}
2430 #else {
2431 # return err("unable to get current data node")
2432 #}
2433 };
2434  
2435  
2436 # Find block name
2437 #
2438 0 my @data_block_ar;
2439  
2440  
2441 # Debug
2442 #
2443 0 debug("render_block self $self, name $name, data_ar $data_ar, %s", Dumper($data_ar));
2444  
2445  
2446 # Have we seen this search befor ?
2447 #
2448 0 ▶ unless (exists($self->{'_block_cache'}{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_block_cache'}{$name}) { } 0 0 0
2449  
2450  
2451 # No, search for block
2452 #
2453 0 debug("searching for node $name in data_ar");
2454  
2455  
2456 # Do it
2457 #
2458 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
2459 {
2460  
2461 data_ar => $data_ar,
2462 tag => 'block',
2463 all_fg => 1,
2464  
2465 }) || return err();
2466  
2467  
2468 # Debug
2469 #
2470 0 debug('find_node returned %s', join('*', @{$data_block_all_ar}));
2471  
2472  
2473 # Go through each block found and svae in block_cache
2474 #
2475 0 foreach my $data_block_ar (@{$data_block_all_ar}) {
2476  
2477  
2478 # Get block name
2479 #
2480 0 my $name=$data_block_ar->[WEBDYNE_NODE_ATTR_IX]->{'name'};
2481 0 debug("looking at block $data_block_ar, name $name");
2482  
2483  
2484 # Save
2485 #
2486 #$self->{'_block_cache'}{$name}=$data_block_ar;
2487 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
2488  
2489  
2490 }
2491  
2492  
2493 # Done, store
2494 #
2495 0 @data_block_ar=@{$self->{'_block_cache'}{$name}};
2496  
2497  
2498 }
2499 else {
2500  
2501  
2502 # Yes, set data_block_ar to whatever we saw before, even if it is
2503 # undef
2504 #
2505 0 @data_block_ar=@{$self->{'_block_cache'}{$name}};
2506  
2507  
2508 # Debug
2509 #
2510 0 debug("retrieved data_block_ar @data_block_ar for node $name from cache");
2511  
2512  
2513 }
2514  
2515  
2516 # Debug
2517 #
2518 #debug("set block node to $data_block_ar %s", Dumper($data_block_ar));
2519  
2520  
2521 # Store params for later block render (outside perl block) if needed
2522 #
2523 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
2524  
2525  
2526 # No data_block_ar ? Could not find block - remove this line if global block
2527 # rendering is desired (ie blocks may lay outside perl code calling render_bloc())
2528 #
2529 0 ▶ unless (@data_block_ar) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@data_block_ar) 0 0 0
2530  
2531 #if ($WEBDYNE_DELAYED_BLOCK_RENDER) {
2532 0 return \undef;
2533  
2534 #}
2535 #else {
2536 # return err("could not find block '$name' to render") unless $WEBDYNE_DELAYED_BLOCK_RENDER;
2537 #}
2538 }
2539  
2540  
2541 # Now, was it set to something ?
2542 #
2543 0 my @html_sr;
2544 0 foreach my $data_block_ar (@data_block_ar) {
2545  
2546  
2547 # Debug
2548 #
2549 0 debug("rendering block name $name, data $data_ar with param %s", Dumper($param_hr->{'param'}));
2550  
2551  
2552 # Yes, Get HTML for block immedialtly
2553 #
2554 my $html_sr=$self->render_data_ar(
2555 data => $data_block_ar->[WEBDYNE_NODE_CHLD_IX],
2556 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
2557 ) || return err();
2558  
2559  
2560 # Debug
2561 #
2562 0 debug("block $name rendered HTML $html_sr %s, pushing onto name $name, data_ar $data_block_ar", ${$html_sr});
2563  
2564  
2565 # Store away for this block
2566 #
2567 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
2568  
2569  
2570 # Store
2571 #
2572 0 push @html_sr, $html_sr;
2573  
2574  
2575 }
2576 0 ▶ if (@html_sr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@html_sr) { } 0 0 0
2577  
2578  
2579 # Return scalar or array ref, depending on number of elements
2580 #
2581 #debug('returning %s', Dumper(\@html_sr));
2582 0 ▶ return (@html_sr==1) ? $html_sr[0] : \@html_sr;
Branch: 1 branch
BranchTrueFalseTotal
@html_sr == 1 ? : 0 0 0
2583  
2584 }
2585 else {
2586  
2587  
2588 # No, could not find block below us, store param away for later
2589 # render. NOTE now done for all blocks so work both in and out of
2590 # <perl> section. Moved this code above
2591 #
2592 #push @{$self->{'_block_param'}{$name} ||=[]},$param_hr->{'param'};
2593  
2594  
2595 # Debug
2596 #
2597 0 debug("block $name not found in tree, storing params for later render");
2598  
2599  
2600 # Done, return undef at this stage
2601 #
2602 0 return \undef;
2603  
2604 }
2605  
2606  
2607 }
2608  
2609  
2610 0 ▶sub block {
Subroutine block: not called CC=9 SCAR=45.0
Pod undocumented
2611  
2612  
2613 # Called when we encounter a <block> tag
2614 #
2615 0 my ($self, $data_ar, $attr_hr, $param_data_hr, $text)=@_;
2616 0 debug("in block code, data_ar $data_ar");
2617  
2618  
2619 # Get block name
2620 #
2621 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
2622 return err('no block name specified');
2623 0 debug("in block, looking for name $name, attr given %s", Dumper($attr_hr));
2624  
2625  
2626 # Only render if registered, do once for every time spec'd
2627 #
2628 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
2629  
2630  
2631 # The block name has been pre-rendered - return it
2632 #
2633 0 debug("found pre-rendered block $name");
2634  
2635  
2636 # Var to hold render result
2637 #
2638 0 my $html_ar=delete $self->{'_block_render'}{$name}{$data_ar};
2639  
2640  
2641 # Return result as a single scalar ref
2642 #
2643 0 return \join(undef, map {${$_}} @{$html_ar});
2644  
2645  
2646 }
2647 elsif (exists($self->{'_block_param'}{$name})) {
2648  
2649  
2650 # The block params have been registered, but the block itself was
2651 # not yet rendered. Do it now
2652 #
2653 0 debug("found block param for $name in register");
2654  
2655  
2656 # Var to hold render result
2657 #
2658 0 my @html_sr;
2659  
2660  
2661 # Render the block for as many times as it has parameters associated
2662 # with it, eg user may have called ->render_block several times in
2663 # their code
2664 #
2665 0 foreach my $param_data_block_hr (@{$self->{'_block_param'}{$name}}) {
2666  
2667  
2668 # If no explicit data hash, use parent hash - not sure how useful
2669 # this really is
2670 #
2671 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
2672  
2673  
2674 # Debug
2675 #
2676 0 debug("about to render block $name, param %s", Dumper($param_data_block_hr));
2677  
2678  
2679 # Render it
2680 #
2681 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
2682 data => $data_ar->[WEBDYNE_NODE_CHLD_IX],
2683 param => $param_data_block_hr
2684 ) || return err();
2685  
2686 }
2687  
2688  
2689 # Return result as a single scalar ref
2690 #
2691 0 return \join(undef, map {${$_}} @html_sr);
2692  
2693 }
2694 elsif ($attr_hr->{'display'}) {
2695  
2696  
2697 # User wants block displayed normally
2698 #
2699 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
2700 data => $data_ar->[WEBDYNE_NODE_CHLD_IX],
2701 param => $param_data_hr
2702 ) || err();
2703  
2704 }
2705 else {
2706  
2707  
2708 # Block name not registered, therefore do not render - return
2709 # blank
2710 #
2711 0 return \undef;
2712  
2713 }
2714  
2715  
2716 }
2717  
2718  
2719 0 ▶sub json {
Subroutine json: not called CC=13 SCAR=52.0
Pod undocumented
2720  
2721  
2722 # Called when we encounter a <json> tag
2723 #
2724 0 my ($self, $data_ar, $attr_hr, $param_data_hr, $text)=@_;
2725 0 debug("$self rendering json tag in block $data_ar, attr %s", $attr_hr);
2726  
2727  
2728 # Check we have a handler
2729 #
2730 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
2731 return err('no json tag perl handler supplied');
2732  
2733  
2734 # Run the code in perl routine specifying it is JSON, get return ref of
2735 # some kind
2736 #
2737 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
2738 return err();
2739 0 ▶ if (ref($json_xr) eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json_xr eq "SCALAR") 0 0 0
2740 0 $json_xr=${$json_xr}
2741 }
2742 0 debug("json_xr %s", Dumper($json_xr));
2743  
2744  
2745 # Convert to JSON
2746 #
2747 0 require JSON;
2748 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
2749 return err('unable to create new JSON object');
2750 0 $json_or->allow_nonref(1);
2751 #$json_or->allow_blessed(1);
2752 #$json_or->convert_blessed(1);
2753 0 debug("json_or: $json_or");
2754 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
2755 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
2756 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
2757 return err('error %s on json_encode of %s', $@, Dumper($json_xr));
2758 0 debug("json %s", Dumper($json));
2759  
2760  
2761 # Get new WebDyne::HTML::Tiny object ready to encode result into <script> tag
2762 #
2763 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
2764 return err();
2765 my %attr=(
2766 type => 'application/json',
2767 0 %{$attr_hr}
2768
2769 );
2770 0 delete @attr{qw(perl package method handler pretty canonical)};
2771  
2772  
2773 # Render and return
2774 #
2775 0 my $html=$html_or->script(\%attr, $json);
2776 0 debug("generated HTML: $html");
2777 0 return \$html
2778  
2779 }
2780  
2781  
2782 0 ▶sub htmx {
Subroutine htmx: not called CC=15 SCAR=54.8
Pod undocumented
2783  
2784  
2785 # Called when we encounter a <htmx> tag
2786 #
2787 0 my ($self, $data_ar, $attr_hr, @param)=@_;
2788 0 debug("$self rendering htmx tag, data_ar: $data_ar, attr_hr: %s", Dumper($attr_hr));
2789
2790
2791 # Get the request headers to look for a 'HX-Request' flag
2792 #
2793 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
2794 return err('unable to get request handler !');
2795 0 my $hx_request;
2796 0 foreach my $header (@{$WEBDYNE_HTTP_HEADER_AJAX_AR}) {
2797 0 ▶ last if ($hx_request=$r->headers_in->{$header});
Branch: 1 branch
BranchTrueFalseTotal
if $hx_request = $r->headers_in->{$header} 0 0 0
2798 }
2799 0 debug("hx_request header: $hx_request");
2800
2801
2802 # If not HTMX request don't display unless forced
2803 #
2804 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
2805
2806  
2807 # Not HTMX request, bail
2808 #
2809 0 debug('not htmx request and no force attribute or flag, bailing');
2810 0 return \undef;
2811
2812 }
2813
2814
2815 # Check if we want to fire on match
2816 #
2817 0 ▶ if (exists ($attr_hr->{'display'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr_hr->{"display"}) 0 0 0
2818 0 ▶ unless ($attr_hr->{'display'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attr_hr->{"display"}) 0 0 0
2819 # Defined but no match. Bail
2820 #
2821 0 debug('display attribute present but no match, bailing');
2822 0 return \undef;
2823 }
2824 }
2825  
2826  
2827 # Check we have a handler
2828 #
2829 0 my $html_sr;
2830 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
2831
2832
2833 # Return whatever HTML we get back
2834 #
2835 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
2836 0 debug("htmx rendering with handler: $handler");
2837 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
2838 return err();
2839 0 debug("html_sr: $html_sr, %s", Dumper($html_sr));
2840
2841 }
2842 else {
2843
2844 # No handler, just render
2845 #
2846 0 debug('htmx render without handler');
2847 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
2848 return err();
2849 0 debug("html_sr: $html_sr, %s", Dumper($html_sr));
2850
2851 }
2852
2853
2854 # Done
2855 #
2856 0 ▶ if ($hx_request) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hx_request) { } 0 0 0
2857  
2858 # Return fragment only
2859 #
2860 0 debug('returning htmx tag as html fragment only');
2861 0 return $self->redirect( html=>$html_sr );
2862
2863 }
2864 else {
2865
2866 # Continue render and return whole page
2867 #
2868 0 debug('returning normal render of htmx tag into page');
2869 0 return $html_sr;
2870
2871 }
2872
2873 }
2874  
2875  
2876 0 ▶sub api {
Subroutine api: not called CC=9 SCAR=45.0
Pod undocumented
2877  
2878  
2879 # Called when we encounter a <api> tag
2880 #
2881 0 my ($self, $data_ar, $attr_hr)=@_;
2882 0 debug("$self rendering api tag in block $data_ar, attr %s", Dumper($attr_hr));
2883
2884
2885 # Perl ?
2886 #
2887 0 my %attr=%{$attr_hr};
2888 0 ▶ if (my $perl=$attr{'perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $perl = $attr{"perl"}) 0 0 0
2889 0 $attr{'name'}='perl'
2890 }
2891
2892 # Need Router::Simple. Build params needed allowing for synonyms
2893 #
2894 0 require Router::Simple;
2895 0 my $rest_or=Router::Simple->new();
2896 0 my @route=(grep {$_}
2897 #@{$attr_hr}{qw(name method handler pattern match data dest destination)}
2898 0 @attr{qw(name method handler pattern match data dest destination)}
2899 );
2900 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
2901 my @option=(grep ${_},
2902 #@{$attr_hr}{qw(option options constraint constraints)}
2903 0 @attr{qw(option options constraint constraints)}
2904 );
2905 0 debug('route param: %s, %s', Dumper(\@route, \@option));
2906 0 $rest_or->connect(@route, $option[0]);
2907
2908
2909 # Now look for match. Set PATH_INFO to '' if not exists to stop warning
2910 #
2911 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
2912
2913
2914 # And match
2915 #
2916 0 ▶ if (my $match_hr=$rest_or->match(\%ENV)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $match_hr = $rest_or->match(\%ENV)) { } 0 0 0
2917
2918  
2919 # We have a match
2920 #
2921 0 debug('route match: %s', Dumper(match_hr));
2922  
2923  
2924 # Run the code in perl routine specifying it is JSON, get return ref of
2925 # some kind
2926 #
2927 #my $json_xr=$self->perl(undef, {json => 1, %{$attr_hr}, param=>$match_hr }) ||
2928 #my $json_xr=$self->perl(undef, {json => 1, %attr, param=>$match_hr }) ||
2929 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
2930 return err();
2931 0 debug("json_xr %s", Dumper($json_xr));
2932  
2933  
2934 # Convert to JSON
2935 #
2936 0 require JSON;
2937 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
2938 return err('unable to create new JSON object');
2939 0 $json_or->allow_nonref(1);
2940 0 debug("json_or: $json_or");
2941 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
2942 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
2943 return err('error %s on json_encode of %s', $@, Dumper($json_xr));
2944 0 debug("json %s", Dumper($json));
2945
2946
2947 # Return as JSON data only
2948 #
2949 0 return $self->redirect( json => $json );
2950
2951 }
2952 else {
2953
2954 # No match
2955 #
2956 0 debug('no match');
2957 0 return \undef;
2958
2959 }
2960
2961 }
2962  
2963  
2964 8 ▶sub perl {
Subroutine perl: called CC=28 SCAR=49.2
Pod undocumented
2965  
2966  
2967 # Called when we encounter a <perl> tag
2968 #
2969 8 my ($self, $data_ar, $attr_hr, $param_data_hr, $text)=@_;
2970 8 debug("$self rendering perl tag in block $data_ar, attr %s", Dumper($attr_hr));
2971
2972
2973 # Look for run param and if exists only run if value evaluates to true
2974 #
2975 8 ▶ if(exists $attr_hr->{'run'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr_hr->{"run"}) 0 8 8
2976 0 ▶ unless ($attr_hr->{'run'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attr_hr->{"run"}) 0 0 0
2977 0 debug('run attribute evaluated as false, not running');
2978 0 return \undef;
2979 }
2980 }
2981  
2982  
2983 # Add current working directory to @INC for any use or require commands
2984 # in perl code
2985 #
2986 8 local @INC=@INC;
2987 8 push @INC, $self->cwd();
2988  
2989  
2990 # HTML scalar ref to return, starts out empty
2991 #
2992 8 my $html_sr=\undef;
2993  
2994 # Get current inode
2995 #
2996 #my $inode=$self->{'_inode'} || 'ANON';
2997 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
2998  
2999  
3000 # Load any modules spec'd by require attribute
3001 #
3002 8 ▶ if (my $require_fn=$attr_hr->{'require'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $require_fn = $attr_hr->{"require"}) 0 8 8
3003  
3004 # Eval string to build
3005 #
3006 0 debug("about to require $require_fn");
3007 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
3008 return err();
3009  
3010 }
3011  
3012  
3013 # Get current autonewline setting, set if defined
3014 #
3015 8 my $autonewline=$self->autonewline($attr_hr->{'autonewline'});
3016  
3017  
3018 # If inline, run now
3019 #
3020 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
3021
3022
3023  
3024  
3025 # May be inline code params to supply to this block
3026 #
3027 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
3028 0 debug("found inline perl code %s, param %s", Dumper(\$perl_code, $perl_param_hr));
3029  
3030  
3031 # Run the same code as the inline eval (!{! ... !}) would run,
3032 # for consistancy
3033 #
3034 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
3035 return err();
3036
3037
3038  
3039 }
3040 24 elsif (grep {$attr_hr->{$_}} qw(package method handler)) {
3041  
3042  
3043 # Not inline, must want to call a handler, get method and caller. package synonym for class, method for handler
3044 #
3045 8 ▶ my $function=join('::', grep {$_} map {exists($attr_hr->{$_}) && $attr_hr->{$_}} qw(package method handler)) ||
Condition60%3/5
join('::', grep({$_;} map({exists $attr_hr->{$_} and $attr_hr->{$_};} 'package', 'method', 'handler'))) || (return err('could not determine perl routine to run'))
l!l
80
exists $attr_hr->{$_} && $attr_hr->{$_}
!ll&&!rl&&r
1608
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')))
MC/DC50%1/2
exists $attr_hr->{$_} && $attr_hr->{$_}
exists $attr_hr->{$_} $attr_hr->{$_}
Truth table50%1/2
A
A= join('::', grep({$_;} map({exists $attr_hr->{$_} and $attr_hr->{$_};} 'package', 'method', 'handler')))
Aresult
11
00
Truth table66%2/3
A && B
A= exists $attr_hr->{$_}B= $attr_hr->{$_}
ABresult
0X0
100
111
3046 return err('could not determine perl routine to run');
3047 8 debug("found call to perl function: $function");
3048  
3049  
3050 # Try to get the package name as an array, pop the method off
3051 #
3052 8 my @package=split(/\:+/, $function);
3053 8 my $method=pop @package;
3054  
3055  
3056 # And return package
3057 #
3058 0 my $package=join('::', grep {$_} @package);
3059  
3060  
3061 # Debug
3062 #
3063 8 debug("perl package: $package, method $method");
3064  
3065  
3066 # If no method by now, dud caller
3067 #
3068 8 ▶ $method ||
Branch: 1 branch
BranchTrueFalseTotal
$method or return err("no handler found in perl tag") 8 0 8
3069 return err("no handler found in perl tag");
3070  
3071  
3072 # Need to load a package
3073 #
3074 8 ▶ if ($package) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package) 0 8 8
3075 0 debug("about to require $package");
3076 0 ▶ $self->eval_require($package, $attr_hr) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->eval_require($package, $attr_hr) or return err() 0 0 0
3077 return err()
3078 }
3079  
3080 # Push data_ar so we can use it if the perl routine calls self->render(). render()
3081 # then has to "know" where it is in the data_ar structure, and can get that info
3082 # here.
3083 #
3084 #unshift @{$self->{'_perl'}}, $data_ar->[$WEBDYNE_NODE_CHLD_IX];
3085 8 unshift @{$self->{'_perl'}}, $data_ar;
3086 8 debug("unshift $data_ar onto perl stack, stack:%s", join('*', @{$self->{'_perl'}}));
3087  
3088  
3089 # Contruct subroutine call
3090 #
3091 8 ▶ unless ($function=~/::/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($function =~ /::/) 8 0 8
3092 8 $function="WebDyne::${inode}::${function}"
3093 }
3094 8 debug("about to eval $function");
3095
3096
3097 # Inherit params from data stack and add any supplied here
3098 #
3099 8 my (%param, $param_scalar);
3100 8 ▶ if (exists ($attr_hr->{'param'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr_hr->{"param"}) 0 8 8
3101 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
3102 0 %param=(%{$self->{'_perl_data'}[0]}, %{$attr_hr->{'param'}});
3103 }
3104 elsif (!ref($attr_hr->{'param'})) {
3105 0 $param_scalar=$attr_hr->{'param'};
3106 }
3107 else {
3108 0 return err("perl param attribute is %s ref, must be HASH ref or plain scalar", ref($attr_hr->{'param'}));
3109 }
3110 }
3111
3112
3113 # 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
3114 # false which is default and fine.
3115 #
3116 8 my $tag_fg=$attr_hr->{'json'};
3117  
3118  
3119 # Run the eval code to get HTML. Various previous iterations get for reference
3120 #
3121 #$html_sr=$Package{'_eval_cr'}{'!'}->($self, $data_ar, $attr_hr->{'param'}, "&${function}") || do {
3122 #$html_sr=$Package{'_eval_cr'}{'!'}->($self, $data_ar, \%param, "&${function}") || do {
3123 #$html_sr=$Package{'_eval_cr'}{'!'}->($self, $data_ar, $param_scalar ? $param_scalar : \%param, "&${function}") || do {
3124 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() } 6 0 6
$param_scalar ? : 0 8 8
3125  
3126  
3127 # Error occurred. Pop data ref off stack and return
3128 #
3129 0 debug("error occured on eval, passing to error handler, $@");
3130 0 shift @{$self->{'_perl'}};
3131 0 debug("shift off perl stack, stack:%s", join('*', @{$self->{'_perl'}}));
3132 0 return err();
3133  
3134  
3135 };
3136  
3137  
3138 # Debug
3139 #
3140 #debug('perl eval return %s', Dumper($html_sr));
3141  
3142  
3143 # Return if we want the data for a JSON tag (above)
3144 #
3145 6 debug('attr: %s', Dumper($attr_hr));
3146 6 ▶ if (!$attr_hr->{'json'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $attr_hr->{'json'}) { } 6 0 6
3147 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
3148  
3149 # Render with HASH ref supplied.
3150 #
3151 0 debug('HASH ref detected, rendering');
3152 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
3153 return err();
3154  
3155 }
3156 elsif ($ref ne 'SCALAR') {
3157  
3158 # If not JSON or HASH ref should be scalar. If not error
3159 #
3160 0 return err("error in perl method '$method'- code did not return a SCALAR ref value.");
3161 }
3162  
3163 }
3164 else {
3165 0 debug('returning json data');
3166 }
3167  
3168  
3169 # If get to here shift perl data_ar ref from stack
3170 #
3171 6 debug("shift off perl stack, stack:%s", join('*', @{$self->{'_perl'}}));
3172 6 shift @{$self->{'_perl'}};
3173  
3174 }
3175  
3176  
3177 # Restore autonewline to whatever it was
3178 #
3179 6 $self->autonewline($autonewline);
3180
3181
3182 # Return whatever was generated unless hidden attr set or display attr exists and is false
3183 #
3184 6 debug('attr_hr: %s', Dumper($attr_hr));
3185 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
3186  
3187
3188 # No display wanted. Note debug - don't do @{$attr_hr}{qw(hidden display)} or keys autovivify !
3189 #
3190 0 debug('hidden, not displaying. hidden:%s, display:%s, display(exists) %s', $attr_hr->{'hidden'}, $attr_hr->{'display'}, exists($attr_hr->{'display'}));
3191 0 return \undef;
3192
3193 }
3194 else {
3195
3196 # Not hidden return. Note debug - don't do @{$attr_hr}{qw(hidden display)} or keys autovivify !
3197 #
3198 6 debug('not hidden, displaying. hidden:%s, display:%s', $attr_hr->{'hidden'}, $attr_hr->{'display'});
3199 6 return $html_sr;
3200
3201 }
3202 #return $attr_hr->{'hidden'} ? \undef : $html_sr;
3203  
3204 }
3205  
3206  
3207 0 ▶sub eval_require {
Subroutine eval_require: not called CC=9 SCAR=45.0
Pod undocumented
3208  
3209  
3210 # Code to require or load a module
3211 #
3212 0 my ($self, $require_fn, $attr_hr)=@_;
3213  
3214  
3215 # Inode ?
3216 #
3217 #my $inode=$self->{'_inode'} || 'ANON';
3218 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
3219  
3220  
3221 # Eval cr
3222 #
3223 0 ▶ my $eval_cr=set_subname('eval_require_cr_anon', sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
3224  
3225 0 local $SIG{__DIE__};
3226 0 ▶ eval {} if $@; #Clear $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
3227 0 my $ret=eval(shift());
3228 0 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not $ret) { } 0 0 0
3229 0 my $err=$@; eval {};
3230 0 return err("attempt to load $require_fn returned error $err");
3231 }
3232 elsif (!$ret) {
3233 0 return err("eval of '$require_fn' did not return a true value");
3234 }
3235 0 return $ret
3236  
3237 0 });
3238  
3239  
3240 # File or module ? Try via syntax, allow force with 'file' attribute
3241 #
3242 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
3243  
3244  
3245 # File contains a '.', '/' or '\'. Probably a file. Convert to full path
3246 #
3247 0 debug("found perl require command for: $require_fn, interpreting as local file");
3248 0 my $require_cn=$self->rel2abs($require_fn);
3249 0 debug("converted to full path $require_fn");
3250  
3251  
3252 # Need to load a file. Delete from INC so forced to reload in this inode package space;
3253 #
3254 0 delete $INC{$require_cn};
3255 0 (my $require_eval_cn=$require_cn)=~s/([\\'])/\\$1/g;
3256 0 my $eval=sprintf(q[package WebDyne::%s; require '%s'], $inode, $require_eval_cn);
3257 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
3258 err();
3259  
3260  
3261 }
3262 else {
3263  
3264 # Probably a module as no match above
3265 #
3266 0 debug("found perl require command for $require_fn, interpreting as module with import: %s", Dumper($attr_hr->{'import'}));
3267 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
3268 return err("invalid module name '$require_fn'");
3269  
3270  
3271 # Do any imports now
3272 #
3273 0 my @import;
3274 0 ▶ if (ref($attr_hr->{'import'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr_hr->{'import'} eq 'ARRAY') { } 0 0 0
3275 0 @import=@{$attr_hr->{'import'}}
3276 }
3277 else {
3278 0 @import=split(/\s+/, $attr_hr->{'import'});
3279 }
3280 0 debug("about to import functions: %s into inode:$inode", Dumper(\@import));
3281  
3282  
3283 # This only works for modules
3284 #
3285 0 map {*{"WebDyne::${inode}::$_"}=\&{"${require_fn}::$_"}} grep {$_} @import;
3286  
3287  
3288 # Check if already loaded ?
3289 #
3290 0 my @package=split(/\:+/, $require_fn);
3291  
3292  
3293 # And return package
3294 #
3295 0 my $package_fn=join('/', @package) . '.pm';
3296 0 ▶ if ($INC{$package_fn}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{$package_fn}) { } 0 0 0
3297  
3298 # Already loaded
3299 #
3300 0 debug('package %s already loaded in %%INC', $package_fn);
3301 0 return 1;
3302  
3303 }
3304 else {
3305  
3306 0 my $eval="require $require_fn";
3307 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
3308 err();
3309  
3310 }
3311  
3312  
3313 }
3314  
3315 }
3316  
3317  
3318 3 ▶sub eval_cr {
Subroutine eval_cr: called CC=1 SCAR=0.0
Pod undocumented
3319  
3320  
3321 # Return eval subroutine ref for inode ($_[0]) and eval code ref ($_[1]). Avoid using
3322 # var names so not available in eval code
3323 #
3324 #eval("package WebDyne::$_[0]; $WebDyne::WEBDYNE_EVAL_USE_STRICT;\n" . "#line $_[2]\n" . "sub{${$_[1]}\n}");
3325 3 my $eval=join(
3326 $/,
3327 "package WebDyne::$_[0]; $WebDyne::WEBDYNE_EVAL_USE_STRICT;",
3328 "#line $_[2] WebDyne::$_[0]",
3329 3 "sub{${$_[1]}}"
3330 );
3331 #debug("eval_cr: $eval");
3332 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
3333  
3334  
3335 }
3336  
3337  
3338 3 ▶sub perl_init_eval {
Subroutine perl_init_eval: called CC=1 SCAR=0.0
Pod undocumented
3339  
3340  
3341 # Eval routine for perl_init code. Avoid using var names so things like $self not available
3342 # in eval code;
3343 # local $SIG{__DIE__};
3344 my $eval=join(
3345 $/,
3346 "package WebDyne::$_[0]; $WebDyne::WEBDYNE_EVAL_USE_STRICT;",
3347 3 grep {$_} (
3348 (WEBDYNE_EVAL_PREPEND && WEBDYNE_EVAL_PREPEND),
3349 (WEBDYNE_PAGI && $WebDyne::PAGI::WEBDYNE_PAGI_EVAL_PREPEND),
3350 (WEBDYNE_PSGI && $WebDyne::PSGI::WEBDYNE_PSGI_EVAL_PREPEND),
3351 ),
3352 "#line $_[2] WebDyne::$_[0]",
3353 3 "${$_[1]}",
3354 ';1'
3355 );
3356 3 debug("perl_init_eval:\n%s", $eval);
3357 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
3358  
3359 }
3360  
3361  
3362 3 ▶sub perl_init {
Subroutine perl_init: called CC=8 SCAR=23.8
Pod undocumented
3363  
3364  
3365 # Init the perl package space for this inode
3366 #
3367 3 my ($self, $perl_ar, $perl_debug_ar)=@_;
3368 #my $inode=$self->{'_inode'} || 'ANON'; #ANON used when run from command line
3369 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
3370  
3371  
3372 # Prep package space
3373 #
3374 3 debug("$self init perl code $perl_ar in $inode, %s", Dumper($perl_ar));
3375 3 *{"WebDyne::${inode}::err"}=\&err;
3376 0 ▶ *{"WebDyne::${inode}::self"}=set_subname('perl_init_inode_self_cr_anon', sub {$self});
Subroutine __ANON__: not called CC=1 SCAR=0.4
3377 0 ▶ *{"WebDyne::${inode}::AUTOLOAD"}=sub {die("unknown function $AUTOLOAD")};
Subroutine __ANON__: not called CC=1 SCAR=0.4
3378  
3379  
3380 # Run each piece of perl code
3381 #
3382 3 foreach my $ix (0..$#{$perl_ar}) {
3383  
3384  
3385 # Get perl code and debug information
3386 #
3387 3 my $perl_sr=$perl_ar->[$ix];
3388 3 my ($perl_line_no, $perl_srce_fn)=@{$perl_debug_ar->[$ix]};
3389 3 debug("about to run $perl_sr at line:$perl_line_no from fn:$perl_srce_fn");
3390  
3391  
3392 # Do not execute twice
3393 #
3394 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
3395 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
3396  
3397  
3398 # Set inc to include psp dir so can include packages easily
3399 #
3400 3 local @INC=@INC;
3401 3 push @INC, $self->cwd();
3402  
3403  
3404 # Error handler
3405 #
3406 0 ▶ my $error_cr=set_subname('error_cr_anon', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3407  
3408 # An error has occurred. Deregister self subroutine call in package
3409 #
3410 #undef *{"WebDyne::${inode}::self"};
3411  
3412  
3413 # Make up a fake data block with details of error
3414 #
3415 0 my @data;
3416 0 @data[
3417 WEBDYNE_NODE_LINE_IX,
3418 WEBDYNE_NODE_LINE_TAG_END_IX,
3419 WEBDYNE_NODE_SRCE_IX,
3420 ]=($perl_line_no, $perl_line_no, $perl_srce_fn);
3421  
3422  
3423 # Save away as current data block for reference by error handler
3424 #
3425 0 push @{$self->{'_data_ar_err'}}, \@data;
3426  
3427 3 });
3428  
3429  
3430 # Var for eval return value
3431 #
3432 3 my $ret;
3433  
3434  
3435 # Wrap in anon CR, eval for syntax
3436 #
3437 3 if (WEBDYNE_EVAL_SAFE) {
3438  
3439  
3440 # Safe mode, vars don't matter so much
3441 #
3442 my $safe_or=$self->{'_eval_safe'} || do {
3443 debug('safe init (perl_init)');
3444 require Safe;
3445 require Opcode;
3446  
3447 #Safe->new($self->{'_inode'});
3448 Safe->new();
3449 };
3450 $self->{'_eval_safe'} ||= do {
3451 $safe_or->permit_only(@{$WEBDYNE_EVAL_SAFE_OPCODE_AR});
3452 $safe_or;
3453 };
3454  
3455  
3456 # Run safe eval
3457 #
3458 $ret=$safe_or->reval(${$perl_sr}, $WebDyne::WEBDYNE_EVAL_USE_STRICT);
3459  
3460  
3461 }
3462 else {
3463  
3464  
3465 # Now run eval after getting eval string;
3466 #
3467 3 debug("running perl_init_eval on $perl_sr now, line $perl_line_no");
3468 3 $ret=&perl_init_eval($inode, $perl_sr, $perl_line_no);
3469  
3470 }
3471  
3472  
3473 # Check for errors
3474 #
3475 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
3476 0 $error_cr->();
3477 0 eval {}; #Clear $@
3478 0 return $self->err_eval("error in __PERL__block: $err", $perl_sr, $inode);
3479 }
3480 elsif (!$ret) {
3481 0 $error_cr->();
3482 0 return err("eval of perl_init did not return a true value");
3483 }
3484  
3485 }
3486  
3487  
3488 # Done. Undef self ref sub but leave error handler and autoload
3489 #
3490 3 undef *{"WebDyne::${inode}::self"};
3491 3 debug('perl_init complete');
3492 3 return \undef;
3493  
3494 }
3495  
3496  
3497 6 ▶sub subst {
Subroutine subst: called CC=4 SCAR=15.4
Pod undocumented
3498  
3499  
3500 # Called to eval text block, replace params
3501 #
3502 6 my ($self, $data_ar, $attr_hr, $param_data_hr, $text)=@_;
3503  
3504  
3505 # Debug
3506 #
3507 6 debug("eval $text %s", Dumper($param_data_hr));
3508  
3509  
3510 # Get eval code refs for subst
3511 #
3512 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
3513 return err('unable to get eval code ref table');
3514  
3515  
3516 # Do we have to replace something in the text, look for pattern. We
3517 # should always find something, as subst tag is only inserted at
3518 # compile time in front of text with one of theses patterns
3519 #
3520 6 my $index;
3521 6 ▶ my $cr=set_subname('subst_cr_anon', sub {
Subroutine __ANON__: called CC=2 SCAR=10.1
3522  
3523 # Used to be this
3524 #
3525 #my $sr=$eval_cr->{$_[0]}($self, $data_ar, $param_data_hr, $_[1], $_[2]) ||
3526 # return err();
3527 #(ref($sr) eq 'SCALAR') ||
3528 # return err("eval of '$_[1]' returned %s ref, should return SCALAR ref", ref($sr));
3529 #return $sr;
3530
3531 # But doesn't have to be scalar ref, as long as represents as scalar
3532 #
3533 6 debug('running subst');
3534 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
3535 0 debug('subst_cr_anon returning error');
3536 0 return err();
3537 };
3538 6 });
3539 6 $text=~s/([\$!+*^])\{(\1?)(.*?)\2}/
3540 6 my $oper=$1;
3541 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
3542 0 debug('subst returning error');
3543 0 return err();
3544 };
3545 6 ▶ my $value=(ref($sr) eq 'SCALAR') ? ${$sr} : $sr;
Branch: 1 branch
BranchTrueFalseTotal
ref $sr eq 'SCALAR' ? : 6 0 6
3546 6 $self->subst_escape($oper, $value);
3547 /gex;
3548  
3549  
3550 # Done
3551 #
3552 6 debug("return *$text*");
3553 6 return \$text;
3554  
3555  
3556 }
3557  
3558  
3559 6 ▶sub subst_escape {
Subroutine subst_escape: called CC=6 SCAR=25.2
Pod undocumented
3560  
3561  
3562 # Escape request-derived text substitutions when autoescape is enabled.
3563 # Attribute output is handled later by HTML::Tiny.
3564 #
3565 6 my ($self, $oper, $value)=@_;
3566 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
3567 unless defined($value) && WEBDYNE_CGI_AUTOESCAPE && (($oper eq '+') || ($oper eq '*') || ($oper eq '^'));
3568  
3569 0 return $self->html_tiny()->entity_encode($value);
3570  
3571 }
3572  
3573  
3574 6 ▶sub subst_attr {
Subroutine subst_attr: called CC=9 SCAR=30.5
Pod undocumented
3575  
3576  
3577 # Called to eval tag attributes
3578 #
3579 6 my ($self, $data_ar, $attr_hr, $param_hr)=@_;
3580  
3581  
3582 # Debug
3583 #
3584 6 debug('subst_attr %s', Dumper({%{$attr_hr}, perl => undef}));
3585  
3586  
3587 # Get eval code refs for subst
3588 #
3589 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
3590 return err('unable to get eval code ref table');
3591  
3592  
3593 # Hash to hold results
3594 #
3595 6 my %attr=%{$attr_hr};
3596  
3597  
3598 # Go through each attribute and value. *MUST BE DETERMINISTIC AND IN SAME ORDER EACH RUN*. If not the eval cached using
3599 # $index may change ! So don't use while.
3600 #
3601 # Actually can use while - but have to use attribute name as index so always deterministic
3602 #
3603 #my $index;
3604 #foreach my $attr_name (sort keys %attr) {
3605 6 ▶ while (my ($attr_name, $attr_value)=each %attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %attr) 9 6 15
3606  
3607  
3608 # Get value
3609 #
3610 #my $attr_value=$attr{$attr_name};
3611  
3612  
3613 # Skip perl attr, as that is perl code, do not do any regexp on perl code, as we will
3614 # probably botch it.
3615 #
3616 9 debug("subst_attr $attr_name: $attr_value");
3617 9 ▶ next if ($attr_name eq 'perl');
Branch: 1 branch
BranchTrueFalseTotal
if $attr_name eq "perl" 0 9 9
3618  
3619  
3620 # Look for attribute value strings that need substitution. First and second attemps did'nt work as single regexp
3621 #
3622 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
3623  
3624 # Straightforward $@%!+^ operator, must be only content of value (can't be mixed
3625 # with string, e.g. <popup_list values="foo=@{qw(bar)}" dont make sense
3626 #
3627 0 my ($oper, $eval_text)=($1, $3);
3628 0 debug("subst_attr $attr_name path 1: oper:$oper, eval_text: $eval_text");
3629  
3630 #my $eval=$eval_cr->{$oper}->($self, $data_ar, $param_hr, $eval_text, $index++, 1) ||
3631 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
3632 return err();
3633 0 ▶ $attr{$attr_name}=(ref($eval) eq 'SCALAR') ? ${$eval} : $eval;
Branch: 1 branch
BranchTrueFalseTotal
ref $eval eq 'SCALAR' ? : 0 0 0
3634  
3635 }
3636 else {
3637  
3638 # Trickier - might be interspersed in strings, e.g <submit name="foo=1&${bar}=2&car=${dar}"/>
3639 # Substitution needed
3640 #
3641 9 debug("subst_attr path 2: $attr_name, $attr_value");
3642 0 ▶ my $cr=set_subname('subst_attr_cr_anon', sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
3643 0 ▶ my $sr=$eval_cr->{$_[0]}($self, $data_ar, $param_hr, $_[1], $_[2]) ||
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
3644 return err();
3645 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
3646 return err("eval of '$_[1]' returned %s ref, should return SCALAR ref", ref($sr));
3647 0 $sr;
3648 9 });
3649  
3650 #$attr_value=~s/([\$!+*^]){1}{(\1?)(.*?)\2}/${$cr->($1,$3,$index++) || return err()}/ge;
3651 0 ▶ $attr_value=~s/([\$!+*^]){1}{(\1?)(.*?)\2}/${$cr->($1,$3,$attr_name) || return err()}/ge;
Condition0%0/2
&$cr($1, $3, $attr_name) || (return err())
l!l
00
MC/DC0%0/1
&$cr($1, $3, $attr_name) || (return err())
&$cr($1, $3, $attr_name)
Truth table0%0/2
A
A= &$cr($1, $3, $attr_name)
Aresult
11
00
3652 9 $attr{$attr_name}=$attr_value;
3653  
3654 }
3655  
3656 }
3657  
3658  
3659 # Debug
3660 #
3661 6 debug('returning attr hash %s', Dumper({%attr, perl => undef}));
3662  
3663  
3664 # Return new attribute hash
3665 #
3666 6 \%attr;
3667  
3668 }
3669  
3670  
3671 0 ▶sub include {
Subroutine include: not called CC=37 SCAR=72.5
Pod undocumented
3672  
3673  
3674 # Called to include text/psp block. Can be called from <include> tag or
3675 # perl code, so need to massage params appropriatly.
3676 #
3677 0 my $self=shift();
3678 0 my ($data_ar, $param_hr, $param_data_hr, $text);
3679  
3680  
3681 # Normally get:
3682 #
3683 # my ($self, $data_ar, $attr_hr, $param_data_hr, $text)=@_;
3684 #
3685 # from tag, but in this case param_hr subs for attr_hr because
3686 # we use that for code called from perl. Check what called us
3687 # now - if first param (after self) is array ref, called from
3688 # tag
3689 #
3690 0 ▶ if (ref($_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 0 0
3691  
3692 # Called from <include> tag
3693 #
3694 0 ($data_ar, $param_hr, $param_data_hr, $text)=@_;
3695 }
3696 else {
3697  
3698 # Called from perl code, massage params into hr if not already there
3699 #
3700 0 $param_hr=shift();
3701 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
3702  
3703 }
3704  
3705  
3706 # Debug
3707 #
3708 0 debug('in include, param %s, %s', Dumper($param_hr, $param_data_hr));
3709  
3710  
3711 # Get CWD
3712 #
3713 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
3714 #my $dn=(File::Spec->splitpath($r->filename()))[1] ||
3715 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
3716 return err('unable to determine cwd for requested file %s', $r->filename());
3717 0 debug("dn: $dn");
3718  
3719  
3720 # Any param must supply a file name as an attribute
3721 #
3722 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
3723 return err('no file name supplied with include tag');
3724 0 ▶ unless (ref($fn_ar) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fn_ar eq "ARRAY") 0 0 0
3725 0 $fn_ar=[$fn_ar]
3726 }
3727 0 debug('fn_ar: %s', Dumper($fn_ar));
3728
3729
3730 # Array for HTML results
3731 #
3732 0 my @html;
3733 0 my $count=0;
3734
3735
3736 # Iterate
3737 #
3738 0 foreach my $fn (@{$fn_ar}) {
3739
3740
3741 # Get full path name
3742 #
3743 0 my $pn=File::Spec->rel2abs($fn, $dn);
3744 0 $count++;
3745 0 debug("processing fn: $fn, pn: $pn");
3746  
3747  
3748 # Check what user wants to do
3749 #
3750 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
3751  
3752  
3753 # They want to include the head or body section of an existing pure HTML
3754 # file.
3755 #
3756 0 debug('head or body render');
3757 0 my %option=(
3758  
3759 no_filter => 1,
3760 no_perl => 1,
3761 stage0 => 1,
3762 srce => $pn,
3763
3764 # Note this - don't want implicit <p> tags for included files at body start,
3765 # i.e. <body><p>Some Text in included file may end up as <body><p><p> in initiator file
3766 implicit_body_p_tag => 0,
3767  
3768 );
3769
3770
3771 # Bring in WebDyne::Compile - going to need it
3772 #
3773 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
3774 || return $self->err_html(
3775 errsubst('unable to load WebDyne:Compile, %s', $@ || 'undefined error'));
3776
3777  
3778 # compile spec'd file
3779 #
3780 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
3781 return err();
3782 #$self->data_ar_err_pop();
3783 0 my $block_data_ar=$container_ar->[1];
3784 0 debug('compiled to data_ar %s', Dumper($block_data_ar));
3785
3786
3787 # Any perl code in content ? Initialize it
3788 #
3789 0 ▶ if (my $meta_hr=$container_ar->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meta_hr = $container_ar->[0]) 0 0 0
3790 0 ▶ if (my $perl_ar=$meta_hr->{'perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $perl_ar = $meta_hr->{"perl"}) 0 0 0
3791 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
3792 return err('unable to load perl_debug array reference');
3793 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
3794 }
3795 }
3796  
3797  
3798 # Find the head or body tag
3799 #
3800 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
3801 {
3802  
3803 data_ar => $block_data_ar,
3804 tag => $node,
3805  
3806 }) || return err();
3807 0 ▶ @{$block_ar} ||
Branch: 1 branch
BranchTrueFalseTotal
@{$block_ar;} or return err("unable to find block '${node}' in include file '${fn}'") 0 0 0
3808 return err("unable to find block '$node' in include file '$fn'");
3809 0 debug('found block_ar %s', Dumper($block_ar));
3810  
3811  
3812 # Find_node returns array of blocks that match - we only want first
3813 #
3814 0 $block_ar=$block_ar->[0];
3815  
3816  
3817 # Need to finish compiling now found
3818 #
3819 0 ▶ $self->optimise_one($block_ar) || return err();
Branch: 1 branch
BranchTrueFalseTotal
$self->optimise_one($block_ar) or return err() 0 0 0
3820 0 ▶ $self->optimise_two($block_ar) || return err();
Branch: 1 branch
BranchTrueFalseTotal
$self->optimise_two($block_ar) or return err() 0 0 0
3821 0 debug('optimised data now %s', Dumper($block_ar));
3822  
3823  
3824 # Need to encapsulate into <block display=1> tag, so alter tag name, attr
3825 #
3826 0 $block_ar->[WEBDYNE_NODE_NAME_IX]='block';
3827 0 $block_ar->[WEBDYNE_NODE_ATTR_IX]={name => $node, display => 1};
3828  
3829  
3830 # Incorporate into top level data so we don't have to do this again if
3831 # called from tag
3832 #
3833 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
3834  
3835  
3836 # Render included block and return after stripping <p></p>
3837 #
3838 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
3839 return err();
3840 #return $html_sr;
3841 0 push @html, ${$html_sr}
3842
3843  
3844 }
3845 elsif (my $block=$param_hr->{'block'}) {
3846  
3847 # Wants to include a paticular block from a psp library file
3848 #
3849 0 debug('block render');
3850 0 my %option=(
3851  
3852 no_filter => 1,
3853 #no_perl => 1,
3854 stage1 => 1,
3855 srce => $pn,
3856 implicit_body_p_tag => 0,
3857  
3858 );
3859  
3860  
3861 # Bring in WebDyne::Compile - going to need it
3862 #
3863 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
3864 || return $self->err_html(
3865 errsubst('unable to load WebDyne:Compile, %s', $@ || 'undefined error'));
3866  
3867  
3868 # compile spec'd file
3869 #
3870 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
3871 return err();
3872 0 my $block_data_ar=$container_ar->[1];
3873 0 debug('block data %s', Dumper($block_data_ar));
3874  
3875  
3876 # Find the block node with name we want
3877 #
3878 0 debug("looking for block name $block");
3879 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
3880 {
3881  
3882 data_ar => $block_data_ar,
3883 tag => 'block',
3884 attr_hr => {name => $block},
3885  
3886 }) || return err();
3887 0 ▶ @{$block_ar} ||
Branch: 1 branch
BranchTrueFalseTotal
@{$block_ar;} or return err("unable to find block '${block}' in include file '${fn}'") 0 0 0
3888 return err("unable to find block '$block' in include file '$fn'");
3889 0 debug('found block_ar %s', Dumper($block_ar));
3890  
3891  
3892 # Find_node returns array of blocks that match - we only want first
3893 #
3894 0 $block_ar=$block_ar->[0];
3895  
3896  
3897 # Set to attr always display
3898 #
3899 0 $block_ar->[WEBDYNE_NODE_ATTR_IX]{'display'}=1;
3900  
3901  
3902 # Incorporate into top level data so we don't have to do this again if
3903 # called from tag
3904 #
3905 # COMMENTED OUT FOR NOW: Doesn't work in terms of stripping <p></p> tags
3906 #
3907 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
3908 #@{$data_ar}=@{$block_ar} if $data_ar;
3909  
3910  
3911 # We don't want to render <block> tags, so start at
3912 # child of results [WEBDYNE_NODE_CHLD_IX].
3913 #
3914 0 debug('calling render');
3915 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
3916 return err();
3917 #return $html_sr;
3918 0 push @html, ${$html_sr};
3919  
3920  
3921 }
3922 else {
3923  
3924  
3925 # Plain vanilla file include, no mods
3926 #
3927 0 debug('vanilla file include');
3928 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
3929 0 local $/;
3930 0 my $html = <$fh>;
3931 0 $fh->close();
3932
3933  
3934 # Wrap ?
3935 #
3936 0 ▶ if (my $tag=$param_hr->{'wrap'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tag = $param_hr->{"wrap"}) 0 0 0
3937 0 debug("wrapping in tag: $tag");
3938 0 my $html_or=HTML::Element->new($tag);
3939 0 $html_or->push_content($html);
3940 0 $html=$html_or->as_HTML();
3941 }
3942
3943
3944 # Need to create fake <block> tag to hold this if want to cache
3945 #
3946 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
3947
3948 # Yes, want to cache this file, create fake block tag and force display
3949 #
3950 0 my @block=('block', { name=>"file_${count}", display=>1 }, [$html], undef, 1, 1, \$pn);
3951 0 push @{$data_ar}, \@block;
3952
3953 }
3954
3955
3956 # And return HTML
3957 #
3958 #return \$html;
3959 0 push @html, $html;
3960  
3961 }
3962 }
3963  
3964 # Done
3965 #
3966 0 my $html=join(undef, grep {$_} @html);
3967 0 debug("returning html: $html");
3968 0 return \$html;
3969  
3970 }
3971  
3972  
3973 6 ▶sub find_node {
Subroutine find_node: called CC=2 SCAR=7.2
Pod undocumented
3974  
3975  
3976 # Find a particular node in the tree
3977 #
3978 6 my ($self, $param_hr)=@_;
3979  
3980  
3981 # Get max depth we can descend to, zero out in params
3982 #
3983 6 my ($data_ar, $tag, $attr_hr, $depth_max, $prnt_fg, $all_fg)=@{$param_hr}{
3984 6 qw(data_ar tag attr_hr depth prnt_fg all_fg)
3985 };
3986 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
3987 6 debug("find_node looking for tag $tag in data_ar $data_ar, %s", Dumper($data_ar));
3988  
3989  
3990 # Array to hold results, depth
3991 #
3992 6 my @node;
3993  
3994  
3995 # Create recursive anon sub
3996 #
3997 18 ▶ my $find_cr=set_subname('find_node_cr_anon', sub {
Subroutine __ANON__: called CC=15 SCAR=30.1
3998  
3999  
4000 # Get params
4001 #
4002 18 my ($find_cr, $data_ar, $data_prnt_ar, $depth)=@_;
4003 18 debug("find_cr, data_ar $data_ar, data_prnt_ar $data_prnt_ar");
4004  
4005  
4006 # Do we match at this level ?
4007 #
4008 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
4009  
4010  
4011 # Match for tag name, now check any attrs
4012 #
4013 9 my $tag_attr_hr=$data_ar->[WEBDYNE_NODE_ATTR_IX];
4014  
4015  
4016 # Debug
4017 #
4018 9 debug("tag '$tag' match, $data_ar_tag, checking attr %s", Dumper($tag_attr_hr));
4019  
4020  
4021 # Check only the attributes the caller asked to match. Missing
4022 # attr_hr means "tag name only", so the empty filter below matches
4023 # any node with the requested tag. Iterate over the filter rather
4024 # than the node's full attr hash to avoid accepting partial
4025 # matches accidentally and to keep the work proportional to the
4026 # requested search criteria.
4027 #
4028 9 my $attr_match_fg=1;
4029 9 foreach my $attr (keys %{$attr_hr}) {
4030 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
4031 0 $attr_match_fg=0;
4032 0 last;
4033 }
4034 }
4035 9 ▶ if ($attr_match_fg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_match_fg) 9 0 9
4036  
4037  
4038 # Match, debug
4039 #
4040 9 debug("$data_ar_tag attr match, saving");
4041  
4042  
4043 # Tag name and attribs match, push onto node
4044 #
4045 9 ▶ push @node, $prnt_fg ? $data_prnt_ar : $data_ar;
Branch: 1 branch
BranchTrueFalseTotal
$prnt_fg ? : 0 9 9
4046 9 ▶ return $node[0] unless $all_fg;
Branch: 1 branch
BranchTrueFalseTotal
unless $all_fg 3 6 9
4047  
4048  
4049 }
4050  
4051 }
4052 else {
4053  
4054 9 debug("mismatch on tag $data_ar_tag for tag '$tag'");
4055  
4056 }
4057  
4058  
4059 # Return if out of depth
4060 #
4061 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
4062  
4063  
4064 # Start looking through current node
4065 #
4066 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
4067 15 foreach my $data_child_ar (@data_child_ar) {
4068  
4069  
4070 # Only check and/or recurse through children that are child nodes, (ie
4071 # are refs), ignor non-ref (text) nodes
4072 #
4073 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
4074  
4075  
4076 # We have a ref, recurse look for match
4077 #
4078 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
4079  
4080  
4081 # Found match during recursion, return
4082 #
4083 3 ▶ return $data_match_ar unless $all_fg;
Branch: 1 branch
BranchTrueFalseTotal
unless $all_fg 3 0 3
4084  
4085 }
4086  
4087 }
4088  
4089 }
4090  
4091 6 });
4092  
4093  
4094 # Start it running with our top node
4095 #
4096 6 $find_cr->($find_cr, $data_ar, undef, 0);
4097  
4098  
4099 # Debug
4100 #
4101 6 debug('find complete, return node %s', \@node);
4102  
4103  
4104 # Return results
4105 #
4106 6 return \@node;
4107  
4108 }
4109  
4110  
4111 0 ▶sub delete_node {
Subroutine delete_node: not called CC=2 SCAR=17.9
Pod undocumented
4112  
4113  
4114 # Delete a particular node from the tree
4115 #
4116 0 my ($self, $param_hr)=@_;
4117  
4118  
4119 # Get max depth we can descend to, zero out in params
4120 #
4121 0 my ($data_ar, $node_ar)=@{$param_hr}{qw(data_ar node_ar)};
4122 0 debug("delete node $node_ar starting from data_ar $data_ar");
4123  
4124  
4125 # Create recursive anon sub
4126 #
4127 0 ▶ my $find_cr=set_subname('delete_node_cr_anon', sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
4128  
4129  
4130 # Get params
4131 #
4132 0 my ($find_cr, $data_ar)=@_;
4133  
4134  
4135 # Iterate through child nodes
4136 #
4137 0 foreach my $data_chld_ix (0..$#{$data_ar->[WEBDYNE_NODE_CHLD_IX]}) {
4138  
4139 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
4140 return err("unable to get chld node from $data_ar");
4141 0 debug("looking at chld node $data_chld_ar");
4142  
4143 0 ▶ if ($data_chld_ar eq $node_ar) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_chld_ar eq $node_ar) { } 0 0 0
4144  
4145 # Found node we want to delete. Get rid of it, all done
4146 #
4147 0 debug("match - splicing at chld $data_chld_ix from array %s", Dumper($data_ar));
4148 0 splice(@{$data_ar->[WEBDYNE_NODE_CHLD_IX]}, $data_chld_ix, 1);
4149 0 return \1;
4150  
4151 }
4152 else {
4153  
4154  
4155 # Non-ref children are text nodes, not subtrees.
4156 #
4157 0 ▶ next unless ref($data_chld_ar);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data_chld_ar 0 0 0
4158  
4159  
4160 # Not target node - recurse
4161 #
4162 0 debug("no match - recursing to chld $data_chld_ar");
4163 0 ▶ ${$find_cr->($find_cr, $data_chld_ar) || return err()} &&
Branch: 1 branch
BranchTrueFalseTotal
${&$find_cr($find_cr, $data_chld_ar) or return err();} and return \1 0 0 0
Condition0%0/2
&$find_cr($find_cr, $data_chld_ar) || (return err())
l!l
00
MC/DC0%0/1
&$find_cr($find_cr, $data_chld_ar) || (return err())
&$find_cr($find_cr, $data_chld_ar)
Truth table0%0/2
A
A= &$find_cr($find_cr, $data_chld_ar)
Aresult
11
00
4164 return \1;
4165  
4166 }
4167 }
4168  
4169  
4170 # All done, but no cigar
4171 #
4172 0 return \undef;
4173  
4174 0 });
4175  
4176  
4177 # Start
4178 #
4179 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
4180  
4181 }
4182  
4183  
4184 8 ▶sub CGI {
Subroutine CGI: called CC=4 SCAR=14.4
Pod undocumented
4185  
4186  
4187 # Return WebDyne::CGI::Simple wrapper object
4188 #
4189 8 my $self=shift();
4190 8 debug("$self get WebDyne::CGI object, caller: %s", Dumper([caller(0)]));
4191  
4192  
4193 # Accessor method for CGI::Simple object
4194 #
4195 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
4196  
4197  
4198 # CGI good practice
4199 #
4200 8 debug('creating new object');
4201  
4202  
4203 # And create it. CGI::Simple looks for mod_perl in an eval
4204 # block and we don't want to trigger an error so be careful
4205 #
4206 8 ▶ local $SIG{'__DIE__'}=sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
4207 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
4208 return err('unable to get WebDyne::CGI object');
4209 8 $self->CGI_param_expand($cgi_or);
4210 8 debug("cgi_or: $cgi_or");
4211 8 ▶ eval {} if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 8 8
4212  
4213  
4214 # Return new CGI object
4215 #
4216 8 $cgi_or;
4217  
4218 };
4219  
4220 }
4221  
4222  
4223 8 ▶sub html_tiny {
Subroutine html_tiny: called CC=3 SCAR=13.3
Pod undocumented
4224  
4225 8 my $self=shift();
4226 8 debug("$self get HTML::Tiny object");
4227 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
4228 err('unable to instantiate new WebDybe::HTTP::Tiny object')));
4229  
4230 }
4231  
4232  
4233 8 ▶sub CGI_param_expand {
Subroutine CGI_param_expand: called CC=5 SCAR=26.7
Pod undocumented
4234  
4235 # Expand CGI params if the form "foo&a=b" into "foo=param", "a=b", so if we
4236 # have HTML like <submit name="foo&bar=1"> it will expand out to params as
4237 # foo=>Submit, bar=>1
4238 #
4239 8 my ($self, $cgi_or)=@_;
4240 8 ▶ $cgi_or ||
Branch: 1 branch
BranchTrueFalseTotal
$cgi_or or return err("unable to get CGI object") 8 0 8
4241 return err('unable to get CGI object');
4242 8 debug("$cgi_or param_expand");
4243 8 foreach my $param (grep /=/, $cgi_or->param()) {
4244 0 my (@pairs)=split(/&/, $param);
4245 0 debug('pairs: %s', Dumper(\@pairs));
4246 0 foreach my $pair (@pairs) {
4247 0 my ($key, $value)=split('=', $pair, 2);
4248 0 ▶ defined($value) || ($value=$cgi_or->param($param));
Branch: 1 branch
BranchTrueFalseTotal
defined $value or $value = $cgi_or->param($param) 0 0 0
4249 0 my @value=$cgi_or->param($key);
4250 0 push @value, $value;
4251 0 debug("$cgi_or param splt $key => $value");
4252 0 $cgi_or->param($key, @value);
4253 }
4254 0 $cgi_or->delete($param);
4255 }
4256 }
4257  
4258  
4259 2 ▶sub request {
Subroutine request: called CC=2 SCAR=7.2
Pod undocumented
4260  
4261  
4262 # Accessor method for Apache request object
4263 #
4264 2 my $self=shift();
4265 2 ▶ return @_ ? $self->{'_r'}=shift() : $self->{'_r'};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 2 2
4266  
4267 }
4268  
4269  
4270 0 ▶sub dump {
Subroutine dump: not called CC=16 SCAR=56.1
Pod undocumented
4271  
4272  
4273 # Run the dump CGI dump routine. Is here because it produces different output each
4274 # time it is run, and if not a WebDyne tag it would be optimised to static text by
4275 # the compiler
4276 #
4277 0 my ($self, $data_ar, $attr_hr)=@_;
4278 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
4279 return err();
4280 0 my @html;
4281 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
4282
4283  
4284 # Always do CGI vars
4285 #
4286 0 push @html, Data::Dumper->Dump([scalar $cgi_or->Vars()], ['WebDyne::CGI::Simple']);
4287
4288
4289 # Others are optional. Environment
4290 #
4291 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
4292
4293  
4294 # Environment
4295 #
4296 0 push @html, Data::Dumper->Dump([\%ENV], ['WebDyne::ENV']);
4297
4298 }
4299
4300
4301 # @INC Library path
4302 #
4303 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
4304
4305
4306 # @INC wanted
4307 #
4308 0 push @html, Data::Dumper->Dump([\@INC], ['WebDyne::INC']);
4309  
4310 # %INC wanted
4311 #
4312 0 push @html, Data::Dumper->Dump([\%INC], ['WebDyne::INC']);
4313
4314 }
4315
4316
4317  
4318 # WebDyne constants
4319 #
4320 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
4321
4322  
4323 # Constant
4324 #
4325 #my %constant=map { $_=> encode_entities($WebDyne::Constant::Constant{$_}) } keys(%WebDyne::Constant::Constant);
4326 #push @html, Data::Dumper->Dump([\%constant], ['WebDyne::Constant']);
4327  
4328  
4329 # Update - take from WebDyne module vars, don't trust hasn't changed from Constants file
4330 #
4331 0 my %constant;
4332 0 ▶ while (my ($k, $cv) = each %WebDyne::Constant::Constant) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %WebDyne::Constant::Constant) 0 0 0
4333 0 my $wv=${"WebDyne::${k}"};
4334 0 ▶ $constant{$k}=($cv eq $wv) ? $wv : "$wv [$cv]";
Branch: 1 branch
BranchTrueFalseTotal
$cv eq $wv ? : 0 0 0
4335 }
4336 0 my $constant_dumper=Data::Dumper->Dump([\%constant], ['WebDyne::Constant']);
4337 0 $constant_dumper=$cgi_or->escapeHTML($constant_dumper);
4338 0 push @html, $constant_dumper;
4339
4340 }
4341
4342
4343 # Dir_config
4344 #
4345 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
4346
4347  
4348 # Yes, wanted
4349 #
4350 0 push @html, Data::Dumper->Dump([$self->r->dir_config()], ['WebDyne::Dir_Config']);
4351
4352 }
4353
4354  
4355  
4356 # Version mandatory
4357 #
4358 0 my %version=(
4359 VERSION => $VERSION,
4360 VERSION_GIT_SHA => $VERSION_GIT_SHA
4361 );
4362 0 push @html, Data::Dumper->Dump([\%version], ['WebDyne::VERSION']);
4363
4364  
4365 # Render time
4366 #
4367 0 push @html, sprintf('Render time: %.3f sec', $self->render_time());
4368
4369
4370 # Wrap in a pre tag and return
4371 #
4372 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
4373 0 return \($html_or->pre(join("\n", @html)));
4374
4375 }
4376 else {
4377
4378 # Not wanted, return nothing
4379 #
4380 0 return \undef;
4381 }
4382  
4383 }
4384  
4385  
4386 11 ▶sub cwd {
Subroutine cwd: called CC=4 SCAR=15.0
Pod undocumented
4387  
4388 # Return cwd of current psp file
4389 #
4390 11 my $self=shift();
4391 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
4392 8 debug("$self, fn: %s", $self->{'_r'}->filename());
4393 8 my $fn=$self->{'_r'}->filename();
4394 8 my $dn;
4395 8 ▶ unless (-d ($dn=File::Spec->rel2abs($fn))) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d ($dn = 'File::Spec'->rel2abs($fn))) { } 0 8 8
4396 # Not a directory, must be file
4397 #
4398 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
4399 8 debug("return calculated dn: $dn");
4400 8 $dn;
4401 }
4402 else {
4403 0 debug("return existing dn: $dn");
4404 0 $dn;
4405 }
4406
4407 }
4408  
4409 }
4410  
4411  
4412 0 ▶sub filename {
Subroutine filename: not called CC=1 SCAR=6.9
Pod undocumented
4413  
4414 # Return the full filename from the request handler
4415 #
4416 0 return shift()->{'_r'}->filename();
4417  
4418 }
4419  
4420  
4421 0 ▶sub rel2abs {
Subroutine rel2abs: not called CC=1 SCAR=6.9
Pod undocumented
4422  
4423  
4424 # Concatenate cwd onto supplied file
4425 #
4426 0 my ($self, $fn)=@_;
4427 0 return File::Spec->rel2abs($fn, $self->cwd());
4428  
4429 }
4430  
4431  
4432 8 ▶sub source_mtime {
Subroutine source_mtime: called CC=1 SCAR=0.0
Pod undocumented
4433  
4434 # Get mtime of source file. Is a no-op here so can be subclassed by other handlers. We
4435 # return undef, means engine will use original source mtime
4436 #
4437 8 \undef;
4438  
4439 }
4440  
4441  
4442 0 ▶sub cache_mtime {
Subroutine cache_mtime: not called CC=3 SCAR=24.8
Pod undocumented
4443  
4444 # Mtime accessor - will return mtime of srce inode (default), or mtime of supplied
4445 # inode if given
4446 #
4447 0 my $self=shift();
4448 0 debug("self: $self");
4449 my $inode_pn=${
4450 0 ▶ $self->cache_filename(@_) || return err()};
Condition0%0/2
$self->cache_filename(@_) || (return err())
l!l
00
MC/DC0%0/1
$self->cache_filename(@_) || (return err())
$self->cache_filename(@_)
Truth table0%0/2
A
A= $self->cache_filename(@_)
Aresult
11
00
4451 0 debug("inode_pn: $inode_pn");
4452 0 ▶ my $mtime=$inode_pn ? (stat($inode_pn))[9] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$inode_pn ? : 0 0 0
4453 0 return \$mtime;
4454  
4455 }
4456  
4457  
4458 0 ▶sub render_time {
Subroutine render_time: not called CC=1 SCAR=6.9
Pod undocumented
4459  
4460 # Time so far in render
4461 #
4462 0 my $self=shift();
4463 0 return time()-$self->{'_time'}
4464
4465 }
4466  
4467  
4468 0 ▶sub cache_filename {
Subroutine cache_filename: not called CC=2 SCAR=17.9
Pod undocumented
4469  
4470 # Get cache fq filename given inode or using srce inode if not supplied
4471 #
4472 0 my $self=shift();
4473 0 ▶ my $inode=@_ ? shift() : $self->{'_inode'};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
4474 0 my $inode_pn=File::Spec->catfile(WEBDYNE_CACHE_DN, $inode) if WEBDYNE_CACHE_DN;
4475 0 \$inode_pn;
4476  
4477 }
4478  
4479  
4480 0 ▶sub cache_html {
Subroutine cache_html: not called CC=5 SCAR=34.0
Pod undocumented
4481  
4482 # Write an inode that is fully HTML out to disk to we dispatch it as a subrequest
4483 # next time. This is a &register_cleanup callback
4484 #
4485 0 my ($cache_pn, $html_sr)=@_;
4486 0 debug("cache_html @_");
4487  
4488 # If there was an error no html_sr will be supplied
4489 #
4490 0 ▶ if ($html_sr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html_sr) 0 0 0
4491  
4492 # Write to a temporary file in the same directory, then rename into
4493 # place so other workers never see a partially written cache file.
4494 #
4495 0 my $cache_tmp_pn="${cache_pn}.$$";
4496 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
4497 return warn("unable to open cache file $cache_tmp_pn for write, $!");
4498 0 CORE::print $cache_fh ${$html_sr};
4499 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
4500 return warn("unable to close cache file $cache_tmp_pn, $!");
4501 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
4502 return warn("unable to rename cache file $cache_tmp_pn to $cache_pn, $!");
4503 }
4504 0 \undef;
4505  
4506 }
4507  
4508  
4509 0 ▶sub cache_compile {
Subroutine cache_compile: not called CC=2 SCAR=17.9
Pod undocumented
4510  
4511 # Compile flag accessor - if set will force inode recompile, regardless of mtime
4512 #
4513 0 my $self=shift();
4514 0 ▶ @_ && ($self->{'_compile'}=shift());
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"_compile"} = shift() 0 0 0
4515 0 debug("cache_compile set to %s", $self->{'_compile'});
4516 0 \$self->{'_compile'};
4517  
4518 }
4519  
4520  
4521 0 ▶sub filter {
Subroutine filter: not called CC=1 SCAR=6.9
Pod undocumented
4522  
4523  
4524 # No op
4525 #
4526 0 my ($self, $data_ar)=@_;
4527 0 debug('in filter');
4528 0 $data_ar;
4529  
4530 }
4531  
4532  
4533 0 ▶sub meta {
Subroutine meta: not called CC=5 SCAR=34.0
Pod undocumented
4534  
4535 # Return/read/update meta info hash
4536 #
4537 0 my ($self, @param)=@_;
4538 0 my $inode=$self->{'_inode'};
4539 0 debug("get meta data for inode $inode");
4540 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
4541 0 debug("existing meta $meta_hr %s", Dumper($meta_hr));
4542 0 ▶ if (@param == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (@param == 2) { } 0 0 0
elsif (@param) { } 0 0 0
4543 0 return $meta_hr->{$param[0]}=$param[1];
4544 }
4545 elsif (@param) {
4546 0 return $meta_hr->{$param[0]};
4547 }
4548 else {
4549 0 return $meta_hr;
4550 }
4551  
4552 }
4553  
4554  
4555 0 ▶sub static {
Subroutine static: not called CC=4 SCAR=30.0
Pod undocumented
4556  
4557  
4558 # Set/get static flag for this instance only. If all instances wanted
4559 # set in meta data. This method used by WebDyne::Static module
4560 #
4561 0 my ($self, $static)=@_;
4562 0 debug("self: $self, static: $static");
4563
4564
4565 # Set or get
4566 #
4567 0 ▶ if (defined($static)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $static) { } 0 0 0
4568
4569  
4570 # Set
4571 #
4572 0 $self->meta()->{'static'}=$static;
4573 0 return $self->{'_static'}=$static;
4574
4575 }
4576 else {
4577
4578 # Get
4579 #
4580 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
4581
4582 }
4583  
4584 }
4585  
4586  
4587 0 ▶sub cache {
Subroutine cache: not called CC=2 SCAR=17.9
Pod undocumented
4588  
4589 # Set cache handler for this instance only. If all instances wanted
4590 # set in meta data. This method used by WebDyne::Cache module
4591 #
4592 0 my $self=shift();
4593 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
4594 return err('cache code ref or method name must be supplied');
4595  
4596 }
4597  
4598  
4599 0 ▶sub set_filter {
Subroutine set_filter: not called CC=2 SCAR=17.9
Pod undocumented
4600  
4601 # Set cache handler for this instance only. If all instances wanted
4602 # set in meta data. This method used by WebDyne::Cache module
4603 #
4604 0 my $self=shift();
4605 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
4606 return err('filter name must be supplied');
4607  
4608 }
4609  
4610  
4611 0 ▶sub set_handler {
Subroutine set_handler: not called CC=3 SCAR=24.8
Pod undocumented
4612  
4613  
4614 # Set/return internal handler. Only good in __PERL__ block, after
4615 # that is too late !
4616 #
4617 0 my $self=shift();
4618 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
4619 0 ▶ @_ && ($meta_hr->{'handler'}=shift());
Branch: 1 branch
BranchTrueFalseTotal
@_ and $meta_hr->{"handler"} = shift() 0 0 0
4620 0 \$meta_hr->{'handler'};
4621  
4622 }
4623  
4624  
4625 0 ▶sub select {
Subroutine select: not called CC=1 SCAR=6.9
Pod undocumented
4626  
4627  
4628 # If we are in select mode where print output is redirected to handler output
4629 #
4630 0 shift->{'_select'};
4631  
4632 }
4633  
4634  
4635 0 ▶sub inode {
Subroutine inode: not called CC=4 SCAR=30.0
Pod undocumented
4636  
4637 # Return or set inode name
4638 #
4639 0 my $self=shift();
4640 0 debug("self: $self, inode: %s", Dumper(\@_));
4641 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
4642 return err('unable to get request handler');
4643 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
4644 0 $self->{'_inode'}=md5_hex(ref($self), $r->location, $r->filename(), @_);
4645 }
4646 else {
4647 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
4648 md5_hex(ref($self), $r->location, $r->filename());
4649 }
4650 0 return $self->{'_inode'};
4651  
4652 }
4653  
4654  
4655 0 ▶sub data_ar_err {
Subroutine data_ar_err: not called CC=1 SCAR=6.9
Pod undocumented
4656  
4657 # Return last data_ar block off error hint stack
4658 #
4659 0 my $self=shift();
4660 0 debug("self: $self");
4661 0 return $self->{'_data_ar_err'}[-1];
4662
4663 }
4664  
4665  
4666 0 ▶sub data_ar_html_srce_fn {
Subroutine data_ar_html_srce_fn: not called CC=3 SCAR=24.8
Pod undocumented
4667  
4668  
4669 # The file name that this data node was sourced from
4670 #
4671 0 my ($self, $data_ar)=@_;
4672 0 debug("self: $self, data_ar: $data_ar");
4673 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
4674 0 return ${$data_ar->[WEBDYNE_NODE_SRCE_IX]}
4675 }
4676  
4677 }
4678  
4679  
4680 0 ▶sub data_ar_html_line_no {
Subroutine data_ar_html_line_no: not called CC=4 SCAR=30.0
Pod undocumented
4681  
4682  
4683 # 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
4684 #
4685 0 my ($self, $data_ar)=@_;
4686 0 debug("self: $self, data_ar: $data_ar");
4687 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
4688 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
4689 }
4690  
4691  
4692 }
4693  
4694  
4695 0 ▶sub print {
Subroutine print: not called CC=5 SCAR=34.0
Pod undocumented
4696  
4697 0 my $self=shift();
4698 0 ▶ debug("$self in print, autonewline: %d, %s", $self->autonewline() ? 1 : 0, Dumper(\@_));
Branch: 1 branch
BranchTrueFalseTotal
$self->autonewline ? : 0 0 0
4699 0 ▶ return $self->say(@_) if $self->{'_autonewline'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_autonewline"} 0 0 0
4700 #push @{$self->{'_print_ar'} ||= []}, [map {(ref($_) eq 'ARRAY') ? @{$_} : $_ } @_];
4701 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
4702 0 return \undef;
4703  
4704 }
4705  
4706  
4707 0 ▶sub printf {
Subroutine printf: not called CC=2 SCAR=17.9
Pod undocumented
4708  
4709 0 my $self=shift();
4710 0 debug("$self in printf, %s", Dumper(\@_));
4711 #push @{$self->{'_print_ar'} ||= []}, [sprintf(shift(), @_)];
4712 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
4713 0 return \undef;
4714  
4715 }
4716  
4717  
4718 14 ▶sub autonewline {
Subroutine autonewline: called CC=3 SCAR=11.2
Pod undocumented
4719  
4720 14 my $self=shift();
4721 14 debug("$self in autonewline");
4722 14 my $autonewline=$self->{'_autonewline'};
4723 14 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 0 14
4724 14 ▶ $self->{'_autonewline'}=($_[0] ? "\n" : '');
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 14 14
4725 }
4726 14 return $autonewline;
4727 #return @_ ? $self->{'_autonewline'}=($_[0] ? "\n" : 0) : $self->{'_autonewline'};
4728
4729 }
4730  
4731  
4732 0 ▶sub say {
Subroutine say: not called CC=5 SCAR=34.0
Pod undocumented
4733  
4734 0 my $self=shift();
4735 0 debug("$self in say, %s", Dumper(\@_));
4736 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
4737 0 foreach my $item (@_) {
4738 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
4739 0 push @{$print_ar}, join("\n", @{$item})
4740 }
4741 elsif (ref($item) eq 'SCALAR') {
4742 0 push @{$print_ar}, ${$item}."\n";
4743 }
4744 else {
4745 0 push @{$print_ar}, $item."\n";
4746 }
4747 }
4748 0 return \undef;
4749  
4750 }
4751  
4752  
4753 8 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.0
4754  
4755  
4756 # Stops AUTOLOAD chucking wobbly at end of request because no DESTROY method
4757 # found, logs total page cycle time
4758 #
4759 8 my $self=shift();
4760  
4761  
4762 # Call CGI reset_globals if we created a CGI object
4763 #
4764 8 ▶ $self->{'_CGI'} && (&CGI::Simple::_reset_globals);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_CGI"} and &CGI::Simple::_reset_globals 8 0 8
4765  
4766  
4767 # Work out complete request cylcle time
4768 #
4769 8 debug("in destroy self $self, param %s", Dumper(\@_));
4770 8 my $time_request=sprintf('%0.4f', time()-$self->{'_time'});
4771 8 debug("page request cycle time , $time_request sec");
4772  
4773  
4774 # Destroy object
4775 #
4776 8 %{$self}=();
4777 8 undef $self;
4778  
4779 }
4780  
4781  
4782 0 ▶sub webdyne_status {
Subroutine webdyne_status: not called CC=1 SCAR=6.9
Pod undocumented
4783  
4784 0 return \%Package;
4785  
4786 }
4787  
4788  
4789 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=4 SCAR=30.0
4790  
4791  
4792 # Get self ref
4793 #
4794 0 my $self=$_[0];
4795 0 debug("AUTOLOAD $self, $AUTOLOAD");
4796  
4797  
4798 # Get method user was looking for
4799 #
4800 0 my $method=(reverse split(/\:+/, $AUTOLOAD))[0];
4801  
4802  
4803 # Vars for iterator, call stack
4804 #
4805 0 my $i; my @caller;
4806  
4807  
4808 # Start going backwards through call stack, looking for package that can
4809 # run method, pass control to it if found
4810 #
4811 0 my %caller;
4812 0 ▶ while (my $caller=(caller($i++))[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $caller = (caller $i++)[0]) 0 0 0
4813 0 ▶ next if ($caller{$caller}++);
Branch: 1 branch
BranchTrueFalseTotal
if $caller{$caller}++ 0 0 0
4814 0 push @caller, $caller;
4815 0 ▶ if (my $cr=UNIVERSAL::can($caller, $method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cr = UNIVERSAL::can($caller, $method)) 0 0 0
4816  
4817 # POLLUTE is virtually useless - no speedup in real life ..
4818 0 if (WEBDYNE_AUTOLOAD_POLLUTE) {
4819 my $class=ref($self);
4820 *{"${class}::${method}"}=$cr;
4821 }
4822  
4823 #return $cr->($self, @_);
4824 0 goto &{$cr}
4825 }
4826 }
4827  
4828  
4829 # If we get here, we could not find the method in any caller. Error
4830 #
4831 0 err("unable to find method '$method' in call stack: %s", join(', ', @caller));
4832 0 goto RENDER_ERROR;
4833  
4834 }
4835  
4836  
4837 # Package to tie select()ed output handle to so we can override print() command
4838 #
4839 package WebDyne::TieHandle;
4840 3 *debug=\&WebDyne::Util::debug;
4841  
4842  
4843 8 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
4844  
4845 8 my ($class, $self)=@_;
4846 8 debug("$self TIEHANDLE class: $class");
4847 8 bless \$self, $class;
4848 }
4849  
4850  
4851 0 ▶sub PRINT {
Subroutine PRINT: not called CC=1 SCAR=6.9
4852  
4853 0 my $self=shift();
4854 0 debug("$self PRINT %s", join('*', @_));
4855 0 return ${$self}->print(@_);
4856  
4857 }
4858  
4859  
4860 0 ▶sub PRINTF {
Subroutine PRINTF: not called CC=1 SCAR=6.9
4861  
4862 0 my $self=shift();
4863 0 debug("$self PRINTF %s", join('*', @_));
4864 0 return ${$self}->printf(@_);
4865  
4866 }
4867  
4868  
4869 8 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
4870 8 my $self=shift();
4871 8 debug("$self DESTROY");
4872 8 delete ${$self}->{'_print_ar'};
4873 }
4874  
4875  
4876 8 ▶sub UNTIE {
Subroutine UNTIE: called CC=1 SCAR=0.0
4877 8 my $self=shift();
4878 8 debug("$self UNTIE");
4879 8 delete ${$self}->{'_print_ar'};
4880 }
4881  
4882  
4883 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
4884 0 debug("AUTOLOAD %s", join('*', @_));
4885 }
4886  
4887  
4888 __END__
« blib/lib/WebDyne/Install/Apache.pm ↑ Summary lib/WebDyne/Err.pm »