bin/wdrender

filter: Statementstmt 61.6% 201 / 326 Branchbran 46.9% 62 / 132 Conditioncond 32.2% 19 / 59 MC/DCmcdc 5.5% 2 / 36 Subroutinesub 75.6% 28 / 37 Podpod n/a totaltotal 52.8% 312 / 590 CC 93 SCAR 50.0
CC
93
Cov
55%
main
276.3
request_mod_perl_postamble
90.0
html_colour
30.0
CRAP 148.5
« blib/lib/WebDyne/Util.pm ↑ Summary lib/WebDyne/Install/Apache/Constant.pm »
1 #!/usr/bin/env perl
2 #
3 # This file is part of WebDyne.
4 #
5 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
6 #
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 #
10 # Full license text is available at:
11 #
12 # <http://dev.perl.org/licenses/>
13 #
14 BEGIN {
15  
16 # Get in before module load
17 #
18 7 ▶ $ENV{'WEBDYNE_HTML_NEWLINE'}=0;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 $ENV{'WEBDYNE_ERROR_TEXT'}=1;
20
21 }
22  
23  
24 #
25 # Compile and/or show compiled version of WebDyne HTML scripts
26 #
27 package main;
28  
29  
30 # Compiler pragma
31 #
32 7 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 7 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
34 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 7 ▶no warnings qw(once);
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37  
38 # Use the base module for err()
39 #
40 7 ▶use WebDyne::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42  
43 # Other external modules
44 #
45 7 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 7 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 7 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 7 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 7 ▶use IO::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 7 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 7 ▶use FindBin qw($Script);
Subroutine BEGIN: called CC=1 SCAR=0.0
52 #use URI::Escape;
53 7 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 7 ▶use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 7 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 7 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 7 ▶use HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 7 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 7 ▶use Cwd qw(fastcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61  
62 # Error handling and environment
63 #
64 #use Carp;
65 #local $SIG{__DIE__}=\&Carp::confess;
66 #sub err { croak(@_) }
67  
68  
69 # Local customisation
70 #
71 7 local $Data::Dumper::Indent=1;
72 7 local $Data::Dumper::Sortkeys=1;
73  
74  
75 # Version Info, must be all one line for MakeMaker, CPAN.
76 #
77 7 $VERSION='3.027';
78  
79  
80 # Run main
81 #
82 7 ▶exit ${&main(\@ARGV) || die errdump()};
Branch: 1 branch
BranchTrueFalseTotal
&main(\@ARGV) or die errdump() 0 6 6
83  
84 #===================================================================================================
85  
86  
87 sub main {
88  
89  
90 # Get argv array ref
91 #
92 7 ▶ my $argv_ar=shift();
Subroutine main: called CC=65 SCAR=56.2
93  
94  
95 # Default options
96 #
97 my %opt=(
98  
99 handler => $ENV{'WebDyneHandler'} || 'WebDyne',
100 error => 'text',
101 header => 0,
102 tidy => 1,
103 colour => 1,
104 lineno => 1,
105 no_head_insert => 1,
106 theme => 'light',
107 #request => ['fake'],
108 method => 'GET',
109 root => fastcwd(),
110 keep_tmp => 0,
111 warn => 1,
112 apache_stdout => 0,
113 7 ▶ %{do(glob(sprintf('~/.%s.opt', basename(__FILE__)))) || {}}
Branch: 1 branch
BranchTrueFalseTotal
do (glob(sprintf("~/.%s.opt", basename(__FILE__)))) or {} 7 0 7
Condition50%1/2
$ENV{'WebDyneHandler'} || 'WebDyne'
l!l
07
MC/DC0%0/1
$ENV{'WebDyneHandler'} || 'WebDyne'
$ENV{'WebDyneHandler'}
Truth table50%1/2
A
A= $ENV{'WebDyneHandler'}
Aresult
11
00
114  
115 );
116  
117  
118 # Get command line options
119 #
120 GetOptions(
121 \%opt,
122 my @opt=(
123 'all',
124 'colour|color!',
125 'compare',
126 'conf|config=s',
127 0 ▶ 'no_conf|no_config|no-conf|no-config' => sub { $opt{'no_conf'}=1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
128 7 ▶ 'delay|sleep=i',
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%opt, my(@opt) = ("all", "colour|color!", "compare", "conf|config=s", "no_conf|no_config|no-conf|no-config", sub { $opt{"no_conf"} = 1; } , "delay|sleep=i", "fake", "get=s\@", "handler=s", "head", "head_insert|head-insert!", "header|headers!", "header_only|header-only|headers_only|headers-only|headersonly", "headers_in|header_in|headers-in|header-in=s\@", "htmx", "lineno!", "loop", "method=s", "mod_perl|mod-perl|apache", "apache_stdout|apache-stdout!", "dump_postamble|dump-postamble", "dump_opt|dump-opt|opt", "options=s\@", "outfile=s", "pagi", "param=s\@", "patch=s\@", "post=s\@", "psgi", "psgi_server|psgi-server", "put=s\@", "raw", "repeat|num|n=s", "request|r=s\@", "root|docroot|doc_root|doc-root|document_root|document-root=s", "sse", "silent|quiet!", "test", "theme=s", "tidy|pretty!", "keep_tmp|keep-tmp!", "help|?", "warn!", "man", "version")) or pod2usage(2) 0 7 7
129 # 'error=s', # Not applied
130 'fake',
131 'get=s@',
132 'handler=s',
133 'head',
134 'head_insert|head-insert!',
135 'header|headers!',
136 'header_only|header-only|headers_only|headers-only|headersonly',
137 'headers_in|header_in|headers-in|header-in=s@',
138 'htmx',
139 'lineno!',
140 'loop',
141 'method=s',
142 'mod_perl|mod-perl|apache',
143 'apache_stdout|apache-stdout!',
144 'dump_postamble|dump-postamble',
145 'dump_opt|dump-opt|opt',
146 'options=s@',
147 'outfile=s',
148 'pagi',
149 'param=s@',
150 'patch=s@',
151 'post=s@',
152 'psgi',
153 'psgi_server|psgi-server',
154 'put=s@',
155 'raw',
156 'repeat|num|n=s',
157 'request|r=s@',
158 'root|docroot|doc_root|doc-root|document_root|document-root=s',
159 'sse',
160 'silent|quiet!',
161 #'status=s', # Not applied
162 'test',
163 'theme=s',
164 'tidy|pretty!',
165 'keep_tmp|keep-tmp!',
166 'help|?',
167 'warn!',
168 'man',
169 'version'
170 ),
171 ) || pod2usage(2);
172 7 ▶ pod2usage(-verbose => 99, -sections => 'SYNOPSIS|OPTIONS', -exitval => 1) if $opt{'help'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"help"} 0 7 7
173 7 ▶ pod2usage(-verbose => 2) if $opt{'man'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"man"} 0 7 7
174 7 ▶ $opt{'version'} && do {
Branch: 1 branch
BranchTrueFalseTotal
$opt{"version"} and do { require WebDyne; print "$main::Script version: $main::VERSION\n"; print "WebDyne version: $WebDyne::VERSION ($WebDyne::VERSION_GIT_SHA)\n"; exit 0 } 1 6 7
175 1 require WebDyne;
176 1 print "$Script version: $VERSION\n";
177 1 print "WebDyne version: $WebDyne::VERSION ($WebDyne::VERSION_GIT_SHA)\n";
178 1 exit 0
179 };
180  
181  
182 # Convert negative flags
183 #
184 #map {$opt{"no_${_}"}=!($opt{$_})} qw(head_insert);
185 6 map {$opt{"no_${_}"}=!($opt{$_})} map { /^([^|!:=+]+)/ } grep {/\!$/} @opt;
186 6 ▶ $opt{'warn'}=0 if $opt{'silent'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"silent"} 1 5 6
187
188  
189 # Special config ?
190 #
191 6 ▶ if (my $conf_fn=$opt{'conf'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $conf_fn = $opt{'conf'}) { } 0 6 6
elsif ($opt{'no_conf'} or $opt{'raw'}) { } 0 6 6
192 0 $ENV{'WEBDYNE_CONF'}=$opt{'conf'};
193 }
194 ▶ elsif($opt{'no_conf'} || $opt{'raw'}) {
Condition33%1/3
$opt{"no_conf"} or $opt{"raw"}
l!l&&r!l&&!r
006
MC/DC0%0/2
$opt{"no_conf"} or $opt{"raw"}
$opt{"no_conf"} $opt{"raw"}
Truth table33%1/3
A or B
A= $opt{"no_conf"}B= $opt{"raw"}
ABresult
1X1
011
000
195 0 $ENV{'WEBDYNE_CONF'}='.';
196 }
197  
198  
199 # Dump options for debugging
200 #
201 6 ▶ die Dumper(\%opt) if $opt{'dump_opt'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"dump_opt"} 0 6 6
202  
203
204 # Is dest file set ? If so open
205 #
206 6 my ($html, $html_fh);
207 6 ▶ if (my $dest_fn=$opt{'outfile'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dest_fn = $opt{"outfile"}) 1 5 6
208 1 ▶ $html_fh=IO::File->new($dest_fn, O_CREAT | O_TRUNC | O_WRONLY) ||
Condition50%1/2
'IO::File'->new($dest_fn, 577) || (return err("unable to open file $dest_fn for output, $!"))
l!l
10
MC/DC0%0/1
'IO::File'->new($dest_fn, 577) || (return err("unable to open file $dest_fn for output, $!"))
'IO::File'->new($dest_fn, 577)
Truth table50%1/2
A
A= 'IO::File'->new($dest_fn, 577)
Aresult
11
00
209 return err("unable to open file $dest_fn for output, $!");
210 }
211 #else {
212 # $html_fh=IO::String->new($html);
213 #}
214 #$opt{'select'}=$html_fh;
215  
216  
217 # Get srce file, add to options
218 #
219 6 ▶ my $srce_fn=$opt{'test'} ? $WEBDYNE_DEFAULT_TEST_FN : shift(@{$argv_ar});
Branch: 1 branch
BranchTrueFalseTotal
$opt{'test'} ? : 2 4 6
220 6 ▶ $srce_fn ||
Branch: 1 branch
BranchTrueFalseTotal
$srce_fn or pod2usage("$main::Script: no source file specified !") 0 6 6
221 pod2usage("$Script: no source file specified !");
222 6 ▶ (-f $srce_fn) || do { (-f File::Spec->catfile($opt{'root'}, $srce_fn)) if $opt{'mod_perl'} } ||
Branch: 2 branches
BranchTrueFalseTotal
-f $srce_fn or do { -f "File::Spec"->catfile($opt{"root"}, $srce_fn) if $opt{"mod_perl"} } or pod2usage("$main::Script: input file not found !") 0 6 6
if $opt{"mod_perl"} 0 0 0
Condition33%1/3
-f $srce_fn or do { -f "File::Spec"->catfile($opt{"root"}, $srce_fn) if $opt{"mod_perl"} }
l!l&&r!l&&!r
600
MC/DC0%0/2
-f $srce_fn or do { -f "File::Spec"->catfile($opt{"root"}, $srce_fn) if $opt{"mod_perl"} }
-f $srce_fn do { -f "File::Spec"->catfile($opt{"root"}, $srce_fn) if $opt{"mod_perl"} }
Truth table33%1/3
A or B
A= -f $srce_fnB= do { -f "File::Spec"->catfile($opt{"root"}, $srce_fn) if $opt{"mod_perl"} }
ABresult
1X1
011
000
223 pod2usage("$Script: input file not found !");
224  
225  
226 # Consolidate backend request handler options into one multiplexer option
227 #
228 6 my @request_type=qw(fake psgi psgi_server pagi mod_perl);
229 6 ▶ my $request_ar=ref($opt{'request'}) eq 'ARRAY' ? $opt{'request'} : [ grep { defined } $opt{'request'} ];
Branch: 1 branch
BranchTrueFalseTotal
ref $opt{'request'} eq 'ARRAY' ? : 0 6 6
230 #my %request_type=map { $_=>1 } @{$opt{'request'}};
231 6 my %request_type=map { $_=>1 } @{$request_ar};
232 6 map { $request_type{$_}=1 } grep { $opt{$_} } @request_type;
233 6 ▶ unless ($request_type{'all'} || $opt{'all'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($request_type{"all"} or $opt{"all"}) 6 0 6
Condition33%1/3
$request_type{"all"} or $opt{"all"}
l!l&&r!l&&!r
006
MC/DC0%0/2
$request_type{"all"} or $opt{"all"}
$request_type{"all"} $opt{"all"}
Truth table33%1/3
A or B
A= $request_type{"all"}B= $opt{"all"}
ABresult
1X1
011
000
234 6 ▶ @request_type=grep {$request_type{$_} || $opt{$_}} @request_type;
Branch: 1 branch
BranchTrueFalseTotal
$request_type{$_} or $opt{$_} 30 0 30
235 }
236 6 ▶ @request_type=('fake') unless @request_type;
Branch: 1 branch
BranchTrueFalseTotal
unless @request_type 6 0 6
237  
238  
239 # Santy check to make sure no invalid request types
240 #
241 6 delete @request_type{(@request_type, 'all')};
242 6 ▶ return err('invalid or missing request type \'%s\', must be one of fake,psgi,psgi_server,pagi,mod_perl,all', join(',', sort keys %request_type))
Branch: 1 branch
BranchTrueFalseTotal
if keys %request_type 0 6 6
243 if keys %request_type;
244
245
246 # Get request method wanted
247 #
248 6 ▶ my $method=lc((grep{exists $opt{$_}} qw(get post patch put options head))[0] || $opt{'method'});
Condition33%1/3
(grep {exists $opt{$_};} 'get', 'post', 'patch', 'put', 'options', 'head')[0] || $opt{'method'}
l!l&&r!l&&!r
060
MC/DC0%0/2
(grep {exists $opt{$_};} 'get', 'post', 'patch', 'put', 'options', 'head')[0] || $opt{'method'}
(grep {exists $opt{$_};} 'get', 'post', 'patch', 'put', 'options', 'head')[0] $opt{'method'}
Truth table33%1/3
A || B
A= (grep {exists $opt{$_};} 'get', 'post', 'patch', 'put', 'options', 'head')[0]B= $opt{'method'}
ABresult
1X1
011
000
249
250  
251 # Convert any headers into a HTTP::Header object
252 #
253 6 my @headers_in=map { split(/[:=]/, $_, 2) } @{$opt{'headers_in'}};
254 6 my $headers_in_or=HTTP::Headers->new(@headers_in);
255
256  
257 # Get any headers from environment vars
258 #
259 6 foreach my $env (qw(CONTENT_TYPE CONTENT_LENGTH), grep {/^HTTP_/} keys %ENV) {
260 12 my $value=$ENV{$env};
261 12 (my $header=$env)=~s/^HTTP_//;
262 12 $header=~s/\-/_/;
263 12 $headers_in_or->header(lc($header), $value);
264 }
265
266
267 # If htmx option add hx-request header
268 #
269 6 ▶ if ($opt{'htmx'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"htmx"}) 0 6 6
270 0 $headers_in_or->header('hx-request', 'true');
271 }
272 6 ▶ if ($opt{'sse'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"sse"}) 0 6 6
273 0 $headers_in_or->header('accept', 'text/event-stream');
274 }
275  
276  
277 # Pull out query or post params
278 #
279 6 my @query_string;
280 6 ▶ if (my $query_opt_ar=$opt{$method}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $query_opt_ar = $opt{$method}) 0 6 6
281 0 my @query_opt=map { split(/[;&]/, $_) } @{$query_opt_ar};
282 0 foreach my $query_opt (@query_opt) {
283 0 my ($key, $value)=split(/[:=]/, $query_opt, 2);
284 0 push @query_string, $key, $value
285 }
286 };
287 6 $opt{'query_string'}=\@query_string;
288
289
290 # And parameters we want to supply to the handler for use in perl blocks ?
291 #
292 6 my %param;
293 6 ▶ if (my $param_opt_ar=$opt{'param'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $param_opt_ar = $opt{"param"}) 2 4 6
294 2 my @param_opt=map { split(/[;&]/) } @{$param_opt_ar};
295 2 foreach my $param (@param_opt) {
296 2 my ($key, $value)=split(/[:=]/, $param, 2);
297 2 ▶ if (ref($param{$key}) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $param{$key} eq 'ARRAY') { } 0 2 2
elsif (exists $param{$key}) { } 0 2 2
298 # Array already, push
299 0 push @{$param{$key}}, $value;
300 }
301 elsif (exists $param{$key}) {
302 # Duplicate, create array
303 0 $param{$key}=[$param{$key}, $value];
304 }
305 else {
306 # Vanilla
307 2 $param{$key}=$value;
308 }
309 }
310 };
311 6 $opt{'param'}=\%param;
312  
313  
314 # Construct the HTTP::Request object
315 #
316 6 my $req_or;
317 6 my $uri_or=URI->new($srce_fn);
318 6 ▶ if ($method eq 'get') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq 'get') { } 6 0 6
319 6 $uri_or->query_form(\@query_string);
320 6 $req_or=HTTP::Request->new('GET', $uri_or, $headers_in_or);
321 }
322 else {
323 #$req_or=HTTP::Request->new(uc($method), $uri_or, $headers_in_or, \@query_string);
324 0 my $method_uc=uc($method);
325 0 require HTTP::Request::Common;
326 0 $req_or=&{"HTTP::Request::Common::${method_uc}"}($uri_or, \@query_string, $headers_in_or->flatten );
327 }
328
329
330 # If we're running apache backend start server now
331 #
332 6 my $apache_runner;
333 6 ▶ if ($opt{'mod_perl'} || $opt{'all'} || (grep {/^(?:mod_perl|apache)$/} @request_type)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"mod_perl"} or $opt{"all"} or grep {/^(?:mod_perl|apache)$/;} @request_type) 0 6 6
Condition33%2/6
$opt{"mod_perl"} or $opt{"all"} or grep {/^(?:mod_perl|apache)$/;} @request_type
l!l&&r!l&&!r
006
$opt{"mod_perl"} or $opt{"all"}
l!l&&r!l&&!r
006
MC/DC0%0/3
$opt{"mod_perl"} or $opt{"all"} or grep {/^(?:mod_perl|apache)$/;} @request_type
$opt{"mod_perl"} $opt{"all"} grep {/^(?:mod_perl|apache)$/;} @request_type
Truth table25%1/4
A or B or C
A= $opt{"mod_perl"}B= $opt{"all"}C= grep {/^(?:mod_perl|apache)$/;} @request_type
ABCresult
1XX1
01X1
0011
0000
334 0 $apache_runner=&request_mod_perl_startup(\%opt);
335 }
336  
337  
338 # Run main routine to call appropriate handler
339 #
340 6 LOOP: while (1) {
341
342  
343 # Request type is PSGI, PAGI, Fake etc.
344 #
345 6 foreach my $request_type (@request_type) {
346
347
348 # If different request types (more than one) identify
349 #
350 6 ▶ if ((@request_type > 1) && !$opt{'silent'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@request_type > 1 and not $opt{"silent"}) 0 6 6
Condition33%1/3
@request_type > 1 and not $opt{"silent"}
!ll&&!rl&&r
600
MC/DC0%0/2
@request_type > 1 and not $opt{"silent"}
@request_type > 1 not $opt{"silent"}
Truth table33%1/3
A and not(B)
A= @request_type > 1B= not $opt{"silent"}
ABresult
0X0
100
111
351 0 print "Request type: $request_type\n";
352 }
353  
354
355 # Run as many repeats as nominated
356 #
357 6 ▶ for (1..($opt{'repeat'} || 1)) {
Condition50%1/2
$opt{'repeat'} || 1
l!l
06
MC/DC0%0/1
$opt{'repeat'} || 1
$opt{'repeat'}
Truth table50%1/2
A
A= $opt{'repeat'}
Aresult
11
00
358
359
360 # Send out to backend for render
361 #
362 6 my $res_or=&{sprintf('request_%s', $request_type)}($req_or, \%opt);
363 6 my $html=$res_or->decoded_content;
364
365  
366 # If headers wanted strip them out
367 #
368 6 my $header;
369 6 ▶ if ($opt{'header'} || $opt{'header_only'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"header"} or $opt{"header_only"}) 2 4 6
Condition66%2/3
$opt{"header"} or $opt{"header_only"}
l!l&&r!l&&!r
204
MC/DC50%1/2
$opt{"header"} or $opt{"header_only"}
$opt{"header"} $opt{"header_only"}
Truth table66%2/3
A or B
A= $opt{"header"}B= $opt{"header_only"}
ABresult
1X1
011
000
370 2 $header=$res_or->status_line(). "\n";
371 2 $header.=$res_or->headers->as_string();
372 }
373 6 ▶ if ($opt{'header_only'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"header_only"}) 0 6 6
374 0 print $header, "\n";
375 0 next;
376 }
377
378  
379 # Don't colourise or format if --raw optoion given
380 #
381 6 ▶ unless ($opt{'raw'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt{"raw"}) 6 0 6
382  
383  
384 # Tidy ?
385 #
386 6 ▶ if ($opt{'tidy'} && ($res_or->content_type eq 'text/html') && !$opt{'htmx'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"tidy"} and $res_or->content_type eq "text/html" and not $opt{"htmx"}) 1 5 6
Condition66%4/6
$opt{"tidy"} and $res_or->content_type eq "text/html" and not $opt{"htmx"}
!ll&&!rl&&r
501
$opt{"tidy"} and $res_or->content_type eq "text/html"
!ll&&!rl&&r
501
MC/DC33%1/3
$opt{"tidy"} and $res_or->content_type eq "text/html" and not $opt{"htmx"}
$opt{"tidy"} $res_or->content_type eq "text/html" not $opt{"htmx"}
Truth table50%2/4
A and B and not(C)
A= $opt{"tidy"}B= $res_or->content_type eq "text/html"C= not $opt{"htmx"}
ABCresult
0XX0
10X0
1100
1111
387 1 $html=&html_tidy($html, \%opt);
388 }
389  
390  
391 # Send to syntax higlighter ?
392 #
393 6 ▶ unless ($opt{'outfile'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt{"outfile"}) 5 1 6
394 5 ▶ if ($opt{'colour'} && ($res_or->content_type eq 'text/html')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"colour"} and $res_or->content_type eq "text/html") 0 5 5
Condition33%1/3
$opt{"colour"} and $res_or->content_type eq "text/html"
!ll&&!rl&&r
500
MC/DC0%0/2
$opt{"colour"} and $res_or->content_type eq "text/html"
$opt{"colour"} $res_or->content_type eq "text/html"
Truth table33%1/3
A and B
A= $opt{"colour"}B= $res_or->content_type eq "text/html"
ABresult
0X0
100
111
395 0 $html=&html_colour($html, $header, \%opt);
396 0 undef $header;
397 }
398 }
399
400 }
401  
402 6 ▶ if ($header) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header) 2 4 6
403 2 $html=join("\n", $header, $html);
404 }
405
406
407 # Defensive revert select in case very weird/bad error
408 #
409 6 ▶ select STDOUT if defined(fileno(STDOUT));
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno STDOUT 6 0 6
410
411
412 # Print it
413 #
414 6 ▶ $html_fh ? CORE::print $html_fh $html, $/ : CORE::print $html, $/;
Branch: 1 branch
BranchTrueFalseTotal
$html_fh ? : 1 5 6
415
416
417 6 ▶ if ($opt{'compare'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"compare"}) 0 6 6
418 0 ▶ unless ($html eq ($_{'html'} ||= $html)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($html eq ($_{"html"} ||= $html)) 0 0 0
Condition0%0/3
$_{"html"} ||= $html
l!l&&r!l&&!r
000
MC/DC0%0/2
$_{"html"} ||= $html
$_{"html"} $html
Truth table0%0/3
A ||= B
A= $_{"html"}B= $html
ABresult
1X1
011
000
419 0 ▶ eval { require Text::Diff } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Text::Diff } } or do { die sprintf("compare mismatch:\n\n$html\n\n%s", $_{"html"}) } 0 0 0
420 0 die(sprintf("compare mismatch:\n\n$html\n\n%s",$_{'html'}));
421 };
422 my $diff=Text::Diff::diff(
423 #\Data::Dumper->Dump([\$html], ['$ACTUAL']),
424 #\Data::Dumper->Dump([\$_{'html'}], ['$EXPECT']),
425 0 \$_{'html'},
426 \$html,
427 { STYLE => 'Unified', FILENAME_A=>'EXPECT', FILENAME_B=>'ACTUAL' }
428 );
429 0 local $SIG{'__DIE__'};
430 0 CORE::die("compare mismatch:\n$diff");
431 }
432 }
433
434
435 # If looking for leak
436 #
437 #my $gladiator_ar=Devel::Gladiator::walk_arena();
438  
439  
440 # Manual cleanup
441 #
442 #my $r;
443 #$r->DESTROY();
444
445
446 # Leak detection
447 #
448 #print("SV: ", scalar @{$gladiator_ar}, "\n") if $opt{'leak'};
449 #@{$gladiator_ar} = ();
450
451  
452 # Delay (presumably to test caching code)
453 #
454 6 ▶ if (my $delay=$opt{'delay'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $delay = $opt{"delay"}) 0 6 6
455 0 sleep $delay
456 }
457  
458 }
459
460 # Reinit WebDyne for next run to clear cache etc
461 #
462 6 ▶ WebDyne->init() if defined(&WebDyne::init);
Branch: 1 branch
BranchTrueFalseTotal
if defined &WebDyne::init 6 0 6
463  
464 }
465
466
467 # Run again ?
468 #
469 6 ▶ last LOOP unless $opt{'loop'};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt{"loop"} 6 0 6
470  
471 }
472  
473  
474 # Shutdown server if using Apache backend
475 #
476 6 ▶ if ($apache_runner) {
Branch: 1 branch
BranchTrueFalseTotal
if ($apache_runner) 0 6 6
477 0 &apache_shutdown($apache_runner);
478 }
479
480  
481 # Done, return success
482 #
483 6 return \0;
484  
485 }
486  
487  
488  
489 sub request_psgi {
490  
491  
492 # Use PSGI mock handler. Get filename we want to render
493 #
494 0 ▶ my ($req_or, $opt_hr)=@_;
Subroutine request_psgi: not called CC=3 SCAR=24.8
495  
496  
497 # Load modules we need
498 #
499 0 require WebDyne::PSGI;
500 0 require Plack::Test;
501  
502 # Create new instance of WebDyne PSGI handler
503 #
504 0 my $source_fn=File::Spec->rel2abs($req_or->uri->path());
505 my $app_cr=($_{'psgi_app_cr'} ||=
506 0 ▶ WebDyne::PSGI->new(root=>$opt_hr->{'root'}, no_head_insert=>$opt_hr->{'no_head_insert'}, filename=>$source_fn )->to_app());
Condition0%0/3
$_{"psgi_app_cr"} ||= "WebDyne::PSGI"->new("root", $opt_hr->{"root"}, "no_head_insert", $opt_hr->{"no_head_insert"}, "filename", $source_fn)->to_app
l!l&&r!l&&!r
000
MC/DC0%0/2
$_{"psgi_app_cr"} ||= "WebDyne::PSGI"->new("root", $opt_hr->{"root"}, "no_head_insert", $opt_hr->{"no_head_insert"}, "filename", $source_fn)->to_app
$_{"psgi_app_cr"} "WebDyne::PSGI"->new("root", $opt_hr->{"root"}, "no_head_insert", $opt_hr->{"no_head_insert"}, "filename", $source_fn)->to_app
Truth table0%0/3
A ||= B
A= $_{"psgi_app_cr"}B= "WebDyne::PSGI"->new("root", $opt_hr->{"root"}, "no_head_insert", $opt_hr->{"no_head_insert"}, "filename", $source_fn)->to_app
ABresult
1X1
011
000
507  
508  
509 # Now run. For some reason PSGI manipulates request object so clone first and restore
510 #
511 0 my $uri_or=$req_or->uri->clone();
512 0 ▶ my $test_or=($_{'psgi_test_or'} ||=
Condition0%0/3
$_{"psgi_test_or"} ||= "Plack::Test"->create($app_cr)
l!l&&r!l&&!r
000
MC/DC0%0/2
$_{"psgi_test_or"} ||= "Plack::Test"->create($app_cr)
$_{"psgi_test_or"} "Plack::Test"->create($app_cr)
Truth table0%0/3
A ||= B
A= $_{"psgi_test_or"}B= "Plack::Test"->create($app_cr)
ABresult
1X1
011
000
513 Plack::Test->create($app_cr));
514 0 my $res_or=$test_or->request($req_or);
515 0 $req_or->uri($uri_or);
516
517
518 # Return results
519 #
520 0 return $res_or;
521
522 }
523  
524  
525 sub request_psgi_server {
526  
527 7 ▶ no warnings qw(once);
Subroutine BEGIN: called CC=1 SCAR=0.0
528 0 ▶ local $Plack::Test::Impl='Server';
Subroutine request_psgi_server: not called CC=1 SCAR=6.9
529 0 return &request_psgi(@_);
530
531 }
532  
533  
534 sub request_pagi {
535  
536  
537 # Use PSGI mock handler. Get filename we want to render
538 #
539 0 ▶ my ($req_or, $opt_hr)=@_;
Subroutine request_pagi: not called CC=3 SCAR=24.8
540
541  
542 # Load modules we need
543 #
544 0 require WebDyne::PAGI;
545 0 require PAGI::Test::Client;
546 #use Future::AsyncAwait;
547 #use Sub::Util qw(set_subname);
548  
549  
550 # Create new instance of WebDyne::PAGI handler
551 #
552 0 my $source_fn=File::Spec->rel2abs($req_or->uri->path());
553 my $app_cr=($_{'pagi_app_cr'} ||=
554 0 ▶ WebDyne::PAGI->new(root=>$opt_hr->{'root'}, no_head_insert=>$opt_hr->{'no_head_insert'}, filename=>$source_fn)->to_app());
Condition0%0/3
$_{"pagi_app_cr"} ||= "WebDyne::PAGI"->new("root", $opt_hr->{"root"}, "no_head_insert", $opt_hr->{"no_head_insert"}, "filename", $source_fn)->to_app
l!l&&r!l&&!r
000
MC/DC0%0/2
$_{"pagi_app_cr"} ||= "WebDyne::PAGI"->new("root", $opt_hr->{"root"}, "no_head_insert", $opt_hr->{"no_head_insert"}, "filename", $source_fn)->to_app
$_{"pagi_app_cr"} "WebDyne::PAGI"->new("root", $opt_hr->{"root"}, "no_head_insert", $opt_hr->{"no_head_insert"}, "filename", $source_fn)->to_app
Truth table0%0/3
A ||= B
A= $_{"pagi_app_cr"}B= "WebDyne::PAGI"->new("root", $opt_hr->{"root"}, "no_head_insert", $opt_hr->{"no_head_insert"}, "filename", $source_fn)->to_app
ABresult
1X1
011
000
555 0 ▶ my $test_or=($_{'pagi_test_or'} ||=
Condition0%0/3
$_{"pagi_test_or"} ||= "PAGI::Test::Client"->new("app", $app_cr, "headers", {$req_or->headers->flatten})
l!l&&r!l&&!r
000
MC/DC0%0/2
$_{"pagi_test_or"} ||= "PAGI::Test::Client"->new("app", $app_cr, "headers", {$req_or->headers->flatten})
$_{"pagi_test_or"} "PAGI::Test::Client"->new("app", $app_cr, "headers", {$req_or->headers->flatten})
Truth table0%0/3
A ||= B
A= $_{"pagi_test_or"}B= "PAGI::Test::Client"->new("app", $app_cr, "headers", {$req_or->headers->flatten})
ABresult
1X1
011
000
556 PAGI::Test::Client->new(app => $app_cr, headers=>{$req_or->headers->flatten}));
557  
558  
559 # Extract method wanted and run
560 #
561 0 my $method=lc($req_or->method());
562 0 my $pagi_res_or=$test_or->$method($req_or->uri->path(), query=>{ @{ $opt_hr->{'query_string'}} });
563
564  
565 # Xlate to HTTP::Response object
566 #
567 my $res_or=HTTP::Response->new(
568 $pagi_res_or->status(),
569 HTTP::Status->status_message($pagi_res_or->status()),
570 0 HTTP::Headers->new(%{$pagi_res_or->headers()}),
571 $pagi_res_or->content()
572 );
573
574  
575 # Return
576 #
577 0 return $res_or;
578
579 }
580  
581  
582 sub request_apache {
583  
584 0 ▶ return goto &request_mod_perl;
Subroutine request_apache: not called CC=1 SCAR=6.9
585
586 }
587  
588  
589 sub request_mod_perl {
590  
591  
592 # Spin up Apache and use that
593 #
594 0 ▶ my ($req_or, $opt_hr)=@_;
Subroutine request_mod_perl: not called CC=3 SCAR=24.8
595
596
597 # Load modules we need
598 #
599 0 require Apache::TestRequest;
600  
601  
602 # Get response object
603 #
604 0 my $res_or;
605 0 my $method=uc($req_or->method());
606 0 ▶ if (grep { $method eq $_ } qw(GET PUT HEAD)) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$method eq $_;} 'GET', 'PUT', 'HEAD') { } 0 0 0
elsif ($method eq 'POST') { } 0 0 0
607 0 $res_or=&{"Apache::TestRequest::${method}"}($req_or->uri(), $req_or->headers->flatten());
608 }
609 elsif ($method eq 'POST') {
610 #$res_or=&{"Apache::TestRequest::${method}"}($req_or->uri, content => [$req_or->content], $req_or->headers->flatten());
611 0 $res_or=&{"Apache::TestRequest::${method}"}($req_or->uri(), $opt_hr->{'query_string'}, $req_or->headers->flatten());
612 }
613 else {
614 0 return err('method %s not supported for mod_perl/apache request type', $method);
615 }
616  
617  
618 # Done
619 #
620 0 return $res_or;
621
622 }
623  
624  
625 sub request_mod_perl_startup {
626  
627  
628 # Startup Apache test instance
629 #
630 0 ▶ my $opt_hr=shift();
Subroutine request_mod_perl_startup: not called CC=1 SCAR=6.9
631  
632  
633 # Get postamble with WebDyne config
634 #
635 0 my $postamble=&request_mod_perl_postamble($opt_hr);
636  
637  
638 # Start Apache using Apache::Test.
639 #
640 return apache_startup({
641 port => 'select',
642 documentroot => $opt_hr->{'root'},
643 postamble => $postamble,
644 0 keep_tmp => $opt_hr->{'keep_tmp'},
645 });
646  
647 }
648  
649  
650 sub request_mod_perl_postamble {
651  
652  
653 # Create postamble suitable for running Apache and interpreting .psp files
654 #
655 0 ▶ my $opt_hr=shift();
Subroutine request_mod_perl_postamble: not called CC=9 SCAR=45.0
656  
657  
658 # Need to work out if stderr writable. If not need to use alternate log file (prob running in container)
659 #
660 0 ▶ my $stderr_fn=$opt_hr->{'apache_stdout'} ? '/dev/stderr' : File::Spec->devnull();
Branch: 1 branch
BranchTrueFalseTotal
$opt_hr->{'apache_stdout'} ? : 0 0 0
661 0 ▶ my $stdout_fn=$opt_hr->{'apache_stdout'} ? '/dev/stdout' : File::Spec->devnull();
Branch: 1 branch
BranchTrueFalseTotal
$opt_hr->{'apache_stdout'} ? : 0 0 0
662 0 ▶ if (! open(my $fh, '>>', $stderr_fn)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open my $fh, ">>", $stderr_fn) 0 0 0
663  
664 # Not writable, probably running under docker, revert to traditional
665 #
666 0 print STDERR "unable to write to stderr,stdout - reverting to log files\n";
667 0 $stderr_fn='logs/error.log';
668 0 $stdout_fn='logs/access.log';
669
670 }
671  
672  
673 # Get any additional library paths we want
674 #
675 0 my @perl_inc_dn=@{&perl_inc_dn()};
676  
677  
678 # Ok - proceed to build postamble
679 #
680 0 my @PerlSetEnv=map { sprintf('PerlSetEnv %s %s', $_, $ENV{$_}) }
681 0 ▶ grep { defined($ENV{$_}) && $ENV{$_} ne '' }
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{$_} and $ENV{$_} ne "" 0 0 0
682 0 grep { /^WEBDYNE_/ } keys %ENV;
683 0 ▶ push (@PerlSetEnv, "PerlSetEnv WEBDYNE_ERROR_TEXT 1") unless defined($ENV{'WEBDYNE_ERROR_TEXT'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{"WEBDYNE_ERROR_TEXT"} 0 0 0
684 0 ▶ push (@PerlSetEnv, sprintf("PerlSetEnv WEBDYNE_REQUEST_NO_HEAD_INSERT %s", $opt_hr->{'no_head_insert'} ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
$opt_hr->{'no_head_insert'} ? : 0 0 0
685 0 ▶ push (@PerlSetEnv, "PerlSetEnv WEBDYNE_REQUEST_FILENAME \"$WEBDYNE_DEFAULT_TEST_FN\"") if $opt_hr->{'test'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt_hr->{"test"} 0 0 0
686 0 my $PerlSetEnv=join("\n", @PerlSetEnv);
687 0 my $PerlSwitches=join("\n", map { sprintf('PerlSwitches -I%s', $_) } @perl_inc_dn);
688 0 my $postamble= <<"END"
689 $PerlSwitches
690 $PerlSetEnv
691 PerlModule WebDyne
692 AddHandler modperl .psp
693 PerlResponseHandler WebDyne
694 <Location "/">
695 SetHandler modperl
696 PerlResponseHandler WebDyne
697 </Location>
698 ErrorLog $stderr_fn
699 LogLevel debug
700 LogFormat "%h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-Agent}i\\"" combined
701 CustomLog $stdout_fn combined
702 END
703 ;
704 0 ▶ exit print $postamble if $opt_hr->{'dump_postamble'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt_hr->{"dump_postamble"} 0 0 0
705 0 return $postamble;
706  
707 }
708  
709  
710 sub request_fake {
711  
712  
713 # Use fake request handler
714 #
715 6 ▶ my ($req_or, $opt_hr)=@_;
Subroutine request_fake: called CC=9 SCAR=22.4
716  
717  
718 # Open file hanldle to receive HTML
719 #
720 6 my $html;
721 6 my $html_fh=IO::String->new($html);
722
723
724 # Setup environment to emulate CGI param if needed
725 #
726  
727 my %env=(
728 6 ▶ QUERY_STRING => sub { $req_or->uri->query },
Subroutine __ANON__: called CC=1 SCAR=0.0
729 6 ▶ REQUEST_METHOD => sub { $req_or->method },
Subroutine __ANON__: called CC=1 SCAR=0.0
730 6 ▶ CONTENT_TYPE => sub { $req_or->content_type },
Subroutine __ANON__: called CC=1 SCAR=0.0
731 6 ▶ CONTENT_LENGTH => sub { $req_or->content_length }
Subroutine __ANON__: called CC=1 SCAR=0.0
732 6 );
733 6 local %ENV = %ENV;
734 6 ▶ while (my($key, $cr)=each %env) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %env) 24 6 30
735 24 ▶ if (defined(my $value=$cr->($key))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = &$cr($key))) 12 12 24
736 12 $ENV{$key}=$value;
737 }
738 }
739
740
741 # Setup stdin if there is a content length
742 #
743 6 my $io_fh;
744 6 ▶ if (defined($ENV{'CONTENT_LENGTH'}) && ($ENV{'CONTENT_LENGTH'} > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"CONTENT_LENGTH"} and $ENV{"CONTENT_LENGTH"} > 0) 0 6 6
Condition33%1/3
defined $ENV{"CONTENT_LENGTH"} and $ENV{"CONTENT_LENGTH"} > 0
!ll&&!rl&&r
600
MC/DC0%0/2
defined $ENV{"CONTENT_LENGTH"} and $ENV{"CONTENT_LENGTH"} > 0
defined $ENV{"CONTENT_LENGTH"} $ENV{"CONTENT_LENGTH"} > 0
Truth table33%1/3
A and B
A= defined $ENV{"CONTENT_LENGTH"}B= $ENV{"CONTENT_LENGTH"} > 0
ABresult
0X0
100
111
745 0 $io_fh=IO::String->new($req_or->content());
746 }
747 6 ▶ local *STDIN=$io_fh if $io_fh;
Branch: 1 branch
BranchTrueFalseTotal
if $io_fh 0 6 6
748
749
750 # Get new request handler
751 #
752 6 require WebDyne::Request::Fake;
753 my $r=WebDyne::Request::Fake->new(
754  
755 filename => $req_or->uri->path(),
756 select => $html_fh,
757 input => $io_fh,
758 6 ▶ no_head_insert => $opt_hr->{'no_head_insert'},
Condition50%1/2
'WebDyne::Request::Fake'->new('filename', $req_or->uri->path, 'select', $html_fh, 'input', $io_fh, 'no_head_insert', $opt_hr->{'no_head_insert'}) || (return err())
l!l
60
MC/DC0%0/1
'WebDyne::Request::Fake'->new('filename', $req_or->uri->path, 'select', $html_fh, 'input', $io_fh, 'no_head_insert', $opt_hr->{'no_head_insert'}) || (return err())
'WebDyne::Request::Fake'->new('filename', $req_or->uri->path, 'select', $html_fh, 'input', $io_fh, 'no_head_insert', $opt_hr->{'no_head_insert'})
Truth table50%1/2
A
A= 'WebDyne::Request::Fake'->new('filename', $req_or->uri->path, 'select', $html_fh, 'input', $io_fh, 'no_head_insert', $opt_hr->{'no_head_insert'})
Aresult
11
00
759  
760 ) || return err();
761
762  
763 # Set headers
764 #
765 6 $r->headers_in($req_or->headers->flatten);
766  
767  
768 # Get handler
769 #
770 6 my $handler=$opt_hr->{'handler'};
771  
772  
773 # Load up whichever handler we are using
774 #
775 6 (my $handler_pm = $handler) =~ s{::}{/}g;
776 6 $handler_pm.='.pm';
777 6 ▶ eval {require $handler_pm} ||
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $handler_pm } } or return err("$main::Script: unable to load handler $handler, $@") 0 6 6
778 return err("$Script: unable to load handler $handler, $@");
779  
780  
781 # Set text errors only
782 #
783 #$WebDyne::Err::WEBDYNE_ERROR_TEXT=1 if ($opt{'error'} eq 'text');
784  
785  
786 # Set header, warning output
787 #
788 #$r->notes('noheader', $opt{'header'} ? 0 : 1);
789 #$r->notes('nowarn', $opt{'warn'} ? 0 : 1);
790  
791  
792 # Run it and display results, or any error generated
793 #
794 #defined(my $status=$handler->handler(grep {$_} $r, $opt_hr)) || return err();
795 6 ▶ defined(my $status=$handler->handler(grep {$_} $r, $opt_hr->{'param'})) || return err();
Branch: 1 branch
BranchTrueFalseTotal
defined(my $status = $handler->handler(grep({$_;} $r, $opt_hr->{"param"}))) or return err() 0 6 6
796
797
798 # Close file handle
799 #
800 6 $html_fh->close();
801
802  
803 # Construct HTTP::Response and return it
804 #
805 my $res_or=HTTP::Response->new(
806 $status,
807 HTTP::Status->status_message($status),
808 6 HTTP::Headers->new(%{$r->headers_out()}),
809 $html
810 );
811
812  
813 # Return response obkect
814 #
815 6 return $res_or;
816
817 }
818  
819  
820 sub html_colour {
821  
822  
823 # Colouris HTML
824 #
825 0 ▶ my ($html, $header, $opt_hr)=@_;
Subroutine html_colour: not called CC=5 SCAR=34.0
826  
827  
828 # Try to load colour module
829 #
830 0 eval { require Syntax::Highlight::Engine::Kate } ||
831 0 ▶ return do { warn("install Syntax::Highlight::Engine::Kate to colourise output.\n") if $opt_hr->{'warn'}; $html };
Branch: 2 branches
BranchTrueFalseTotal
eval { do { require Syntax::Highlight::Engine::Kate } } or return do { warn "install Syntax::Highlight::Engine::Kate to colourise output.\n" if $opt_hr->{"warn"}; $html } 0 0 0
if $opt_hr->{"warn"} 0 0 0
832  
833
834 # Var to hold output
835 #
836 0 my $html_colour;
837  
838  
839 # Parse optional theme argument
840 #
841 0 my $theme = $opt_hr->{'theme'};
842  
843  
844 # Theme definitions
845 #
846 0 my %themes = (
847 dark => {
848 Alert => [ color('bold red'), color('reset') ],
849 Error => [ color('bold red'), color('reset') ],
850 Warning => [ color('red'), color('reset') ],
851  
852 Comment => [ color('bright_black'), color('reset') ],
853 Documentation => [ color('bright_black'), color('reset') ],
854  
855 Keyword => [ color('bold yellow'), color('reset') ],
856 ControlFlow => [ color('bold yellow'), color('reset') ],
857 Operator => [ color('blue'), color('reset') ],
858  
859 DataType => [ color('cyan'), color('reset') ],
860 DecVal => [ color('cyan'), color('reset') ],
861 Float => [ color('cyan'), color('reset') ],
862 BaseN => [ color('cyan'), color('reset') ],
863 Constant => [ color('cyan'), color('reset') ],
864  
865 String => [ color('green'), color('reset') ],
866 Char => [ color('green'), color('reset') ],
867 SpecialString => [ color('green'), color('reset') ],
868  
869 Function => [ color('magenta'), color('reset') ],
870 Variable => [ color('white'), color('reset') ],
871  
872 Others => [ color('blue'), color('reset') ],
873 Normal => [ '', '' ],
874 BString => [ '', '' ],
875 Reserved => [ '', '' ],
876  
877 LineNum => color('bright_black'),
878 },
879  
880 light => {
881 Alert => [ color('red'), color('reset') ],
882 Error => [ color('red'), color('reset') ],
883 Warning => [ color('magenta'), color('reset') ],
884  
885 Comment => [ color('bright_black'), color('reset') ],
886 Documentation => [ color('bright_black'), color('reset') ],
887  
888 Keyword => [ color('bold blue'), color('reset') ],
889 ControlFlow => [ color('bold blue'), color('reset') ],
890 Operator => [ color('cyan'), color('reset') ],
891  
892 DataType => [ color('magenta'), color('reset') ],
893 DecVal => [ color('magenta'), color('reset') ],
894 Float => [ color('magenta'), color('reset') ],
895 BaseN => [ color('magenta'), color('reset') ],
896 Constant => [ color('magenta'), color('reset') ],
897  
898 String => [ color('bold green'), color('reset') ],
899 Char => [ color('bold green'), color('reset') ],
900 SpecialString => [ color('bold green'), color('reset') ],
901  
902 Function => [ color('bold red'), color('reset') ],
903 Variable => [ color('black'), color('reset') ],
904  
905 Others => [ color('cyan'), color('reset') ],
906 Normal => [ '', '' ],
907 BString => [ '', '' ],
908 Reserved => [ '', '' ],
909  
910 LineNum => color('bright_black'),
911 }
912 );
913 0 my $colors = $themes{$theme};
914  
915  
916 # Set up Kate highlighter
917 #
918 my $hl = Syntax::Highlight::Engine::Kate->new(
919 language => 'HTML',
920 substitutions => {
921 0 map { $_ => $colors->{$_}[0] } keys %{ $themes{$theme} }
922 },
923 format_table => {
924 0 map { $_ => $colors->{$_} } keys %{ $themes{$theme} }
925 },
926 );
927  
928 # Highlight
929 #
930 0 my $html_highlighted = $hl->highlightText($html);
931  
932  
933 # Print with line numbers if wanted
934 #
935 0 ▶ if ($opt_hr->{'lineno'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_hr->{'lineno'}) { } 0 0 0
936 0 my @lines = split /\n/, (join("\n", grep {$_} $header, $html_highlighted));
937 0 my $width = length(scalar @lines);
938 0 for my $i (0..$#lines) {
939 0 my $num = sprintf("%*d", $width, $i + 1);
940 0 $html_colour.=join('', $colors->{LineNum}, "$num | ", color('reset'), "$lines[$i]\n");
941 }
942 }
943 else {
944
945 # Or just raw
946 #
947 0 $html_colour=$html_highlighted
948 }
949
950
951 # Done
952 #
953 0 return $html_colour;
954  
955 }
956  
957  
958 sub html_tidy {
959  
960 1 ▶ my ($html, $opt_hr)=@_;
Subroutine html_tidy: called CC=3 SCAR=12.3
961 1 eval { require HTML::Tidy5 } ||
962 1 ▶ return do { warn("install system libtidy-devel package and HTML::Tidy5 to tidy output.\n") if $opt_hr->{'warn'}; $html };
Branch: 2 branches
BranchTrueFalseTotal
eval { do { require HTML::Tidy5 } } or return do { warn "install system libtidy-devel package and HTML::Tidy5 to tidy output.\n" if $opt_hr->{"warn"}; $html } 1 0 1
if $opt_hr->{"warn"} 0 1 1
963 0 $html=HTML::Tidy5->new($WEBDYNE_HTML_TIDY_CONFIG_HR)->clean($html);
964 0 return $html;
965  
966 }
967  
968  
969 __END__
« blib/lib/WebDyne/Util.pm ↑ Summary lib/WebDyne/Install/Apache/Constant.pm »