| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||
| 4 | # This file is part of WebDyne. | ||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||
| 6 | # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>. | ||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||
| 8 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||
| 9 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||
| 11 | # Full license text is available at: | ||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||
| 13 | # <http://dev.perl.org/licenses/> | ||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | # Pragma | ||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||
| 19 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 20 | 11 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 21 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 22 | 11 | ▶ | no warnings qw(once); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | # External modules | ||||||||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||||||||
| 27 | 11 | ▶ | use Cwd qw(fastcwd); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 28 | 11 | ▶ | use Config; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 29 | 11 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 30 | 11 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 31 | 11 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 32 | 11 | ▶ | use Fcntl; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 33 | 11 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 34 | 11 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 35 | 11 | ▶ | use POSIX qw(pause); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | # Local customisation | ||||||||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||||||||
| 40 | 11 | local $Data::Dumper::Indent=1; | |||||||||||||||||||||||||||||||||
| 41 | 11 | local $Data::Dumper::Sortkeys=1; | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | # WebDyne modules | ||||||||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||||||||
| 46 | 11 | ▶ | use WebDyne::Constant; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 47 | 11 | ▶ | use WebDyne::Util qw(:all); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | # Version information | ||||||||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||||||||
| 52 | 11 | $VERSION='3.029'; | |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | # Check for supporting modules | ||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||
| 57 | 11 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=6 SCAR=25.0
| |||||||||||||||||||||||||||||||||||
| 58 | 11 | ▶ | eval ("require Apache2::Build; 1") || do { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($@=~/Module::CoreList/i) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 60 | 0 | print STDERR ("Apache2::Build found but needs rebuild/reinstall of Module::CoreList. Please install/upgrade Module::CoreList\n"); | |||||||||||||||||||||||||||||||||
| 61 | 0 | exit 1; | |||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||||||||
| 64 | 11 | my @missing; | |||||||||||||||||||||||||||||||||
| 65 | 11 | for my $module (qw(Apache2::Build Apache::Test Module::CoreList)) { | |||||||||||||||||||||||||||||||||
| 66 | 33 | ▶ | eval "require $module; 1" or push @missing, $module; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | 11 | ▶ | if (@missing) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 69 | 0 | printf STDERR ("Please install missing CPAN modules (you may need mod_perl-devel packages also): %s \n", join(', ', @missing)); | |||||||||||||||||||||||||||||||||
| 70 | 0 | exit 1; | |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | # Run main | ||||||||||||||||||||||||||||||||||
| 77 | # | ||||||||||||||||||||||||||||||||||
| 78 | 11 | ▶ | exit ${&main(\@ARGV) || die errdump()}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
&main(\@ARGV) || die(errdump())
MC/DC0%0/1
&main(\@ARGV) || die(errdump())
&main(\@ARGV)
Truth table0%0/2
A
A= &main(\@ARGV)
| |||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | #================================================================================================== | ||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 11 | ▶ | sub main { | ||||||||||||||||||||||||||||||||
|
Subroutine
main: called CC=18 SCAR=31.5
| |||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | # Get argv array ref | ||||||||||||||||||||||||||||||||||
| 88 | # | ||||||||||||||||||||||||||||||||||
| 89 | 11 | my $argv_ar=shift(); | |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | # Defaults | ||||||||||||||||||||||||||||||||||
| 93 | # | ||||||||||||||||||||||||||||||||||
| 94 | my %opt=( | ||||||||||||||||||||||||||||||||||
| 95 | index => defined($ENV{'DOCUMENT_DEFAULT'}) ? $ENV{'DOCUMENT_DEFAULT'} : 0, | ||||||||||||||||||||||||||||||||||
| 96 | keep_tmp => 0, | ||||||||||||||||||||||||||||||||||
| 97 | port => ($^O eq 'darwin') ? 5001 : 5000, | ||||||||||||||||||||||||||||||||||
| 98 | 11 | ▶ | %{do(glob(sprintf('~/.%s.opt', basename(__FILE__)))) || {}} | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
do (glob(sprintf('~/.%s.opt', basename(__FILE__)))) || {}
MC/DC100%1/1
do (glob(sprintf('~/.%s.opt', basename(__FILE__)))) || {}
do (glob(sprintf('~/.%s.opt', basename(__FILE__))))
Truth table100%2/2
A
A= do (glob(sprintf('~/.%s.opt', basename(__FILE__))))
| |||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||
| 100 | 11 | ▶ | if (delete $opt{'no_index'}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 101 | 2 | $opt{'index'}=0; | |||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | # Process | ||||||||||||||||||||||||||||||||||
| 106 | # | ||||||||||||||||||||||||||||||||||
| 107 | 11 | Getopt::Long::Configure('pass_through'); | |||||||||||||||||||||||||||||||||
| 108 | 11 | @{$argv_ar}=grep { | |||||||||||||||||||||||||||||||||
| 109 | 27 | ▶ | if ($_ eq '--no-index') { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 110 | 3 | $opt{'index'}=0; | |||||||||||||||||||||||||||||||||
| 111 | 3 | 0; | |||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||
| 113 | elsif (/^--index=(.*)$/) { | ||||||||||||||||||||||||||||||||||
| 114 | 0 | $opt{'index'}=$1; | |||||||||||||||||||||||||||||||||
| 115 | 0 | 0; | |||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||
| 117 | else { | ||||||||||||||||||||||||||||||||||
| 118 | 24 | 1; | |||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | 11 | } @{$argv_ar}; | |||||||||||||||||||||||||||||||||
| 121 | GetOptions( | ||||||||||||||||||||||||||||||||||
| 122 | \%opt, | ||||||||||||||||||||||||||||||||||
| 123 | my @opt=( | ||||||||||||||||||||||||||||||||||
| 124 | 3 | ▶ | 'index!' => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||
| 125 | 3 | my ($name, $value)=@_; | |||||||||||||||||||||||||||||||||
| 126 | 3 | ▶ | $opt{'index'}=$value ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 127 | }, | ||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | 'no_index' => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 129 | 0 | $opt{'index'}=0 | |||||||||||||||||||||||||||||||||
| 130 | }, | ||||||||||||||||||||||||||||||||||
| 131 | 11 | ▶ | 'view_source|view-source!', | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 132 | 'root|docroot|doc_root|doc-root|document_root|document-root=s', | ||||||||||||||||||||||||||||||||||
| 133 | 'port=s', | ||||||||||||||||||||||||||||||||||
| 134 | 'keep_tmp|keep-tmp!', | ||||||||||||||||||||||||||||||||||
| 135 | 'test!', | ||||||||||||||||||||||||||||||||||
| 136 | 'dump_postamble|dump-postamble', | ||||||||||||||||||||||||||||||||||
| 137 | 'dump_opt|dump-opt|opt', | ||||||||||||||||||||||||||||||||||
| 138 | 'argv=s', | ||||||||||||||||||||||||||||||||||
| 139 | 'help|?' | ||||||||||||||||||||||||||||||||||
| 140 | ) | ||||||||||||||||||||||||||||||||||
| 141 | ) || return err('bad options'); | ||||||||||||||||||||||||||||||||||
| 142 | 11 | ▶ | map {$opt{"no_${_}"} = $opt{$_} ? 0 : 1} map { /^([^|!:=+]+)/ } grep {!ref($_) && /\!$/} @opt; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
!ref($_) && /\!$/
MC/DC100%2/2
!ref($_) && /\!$/
!ref($_)
/\!$/
Truth table100%3/3
not(A) && B
A= !ref($_)B= /\!$/
| |||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | # Last argument is root directory | ||||||||||||||||||||||||||||||||||
| 146 | # | ||||||||||||||||||||||||||||||||||
| 147 | 11 | ▶ | if (@{$argv_ar} && $argv_ar->[-1] !~ /^--?/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@{$argv_ar;} and not $argv_ar->[-1] =~ /^--?/
MC/DC50%1/2
@{$argv_ar;} and not $argv_ar->[-1] =~ /^--?/
@{$argv_ar;}
not $argv_ar->[-1] =~ /^--?/
Truth table66%2/3
A and not(B)
A= @{$argv_ar;}B= not $argv_ar->[-1] =~ /^--?/
| |||||||||||||||||||||||||||||||||||
| 148 | 3 | $opt{'root'} = pop @{$argv_ar}; | |||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||
| 150 | 11 | ▶ | $opt{'root'} ||=($ENV{'DOCUMENT_ROOT'} || fastcwd()); | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
$opt{"root"} ||= $ENV{"DOCUMENT_ROOT"} || fastcwd()
$ENV{'DOCUMENT_ROOT'} || fastcwd()
MC/DC0%0/3
$opt{"root"} ||= $ENV{"DOCUMENT_ROOT"} || fastcwd()
$opt{"root"}
$ENV{'DOCUMENT_ROOT'}
fastcwd()
Truth table0%0/4
A ||= B || C
A= $opt{"root"}B= $ENV{'DOCUMENT_ROOT'}C= fastcwd()
| |||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | # File or dir ? If file Apache won't like as DOCUMENT_ROOT so need to set | ||||||||||||||||||||||||||||||||||
| 154 | # as Perl environment var in httpd.conf (later) and handle differently | ||||||||||||||||||||||||||||||||||
| 155 | # | ||||||||||||||||||||||||||||||||||
| 156 | 11 | ▶ | if (-f ($opt{'root'}=File::Spec->rel2abs($opt{'root'}))) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 157 | 2 | $opt{'root_pn'}=$opt{'root'}; | |||||||||||||||||||||||||||||||||
| 158 | 2 | $opt{'root'}=dirname($opt{'root'}); | |||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||
| 160 | elsif($opt{'test'}) { | ||||||||||||||||||||||||||||||||||
| 161 | 0 | $opt{'root_pn'}=$WEBDYNE_DEFAULT_TEST_FN; | |||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||
| 164 | # Dump options for debugging | ||||||||||||||||||||||||||||||||||
| 165 | # | ||||||||||||||||||||||||||||||||||
| 166 | 11 | &view_source_apply(\%opt); | |||||||||||||||||||||||||||||||||
| 167 | 11 | ▶ | die Dumper(\%opt) if $opt{'dump_opt'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||
| 170 | # Startup server | ||||||||||||||||||||||||||||||||||
| 171 | # | ||||||||||||||||||||||||||||||||||
| 172 | 2 | printf("Starting server on localhost (127.0.0.1), port: %s\n", $opt{'port'}); | |||||||||||||||||||||||||||||||||
| 173 | 2 | ▶ | my $runner=request_mod_perl_startup(\%opt) || return err(); | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
request_mod_perl_startup(\%opt) || (return err())
MC/DC0%0/1
request_mod_perl_startup(\%opt) || (return err())
request_mod_perl_startup(\%opt)
Truth table0%0/2
A
A= request_mod_perl_startup(\%opt)
| |||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||
| 176 | # Shutdown on signal | ||||||||||||||||||||||||||||||||||
| 177 | # | ||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | my $shutdown_cr=sub { apache_shutdown($runner); exit 0 }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 179 | 0 | $SIG{'INT'}=$shutdown_cr; | |||||||||||||||||||||||||||||||||
| 180 | 0 | $SIG{'TERM'}=$shutdown_cr; | |||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||
| 183 | # Block forever | ||||||||||||||||||||||||||||||||||
| 184 | # | ||||||||||||||||||||||||||||||||||
| 185 | 0 | while (1) { | |||||||||||||||||||||||||||||||||
| 186 | 0 | pause(); | |||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||
| 192 | 11 | ▶ | sub view_source_apply { | ||||||||||||||||||||||||||||||||
|
Subroutine
view_source_apply: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | # Source viewing is an extra opt-in on top of built-in index handling. | ||||||||||||||||||||||||||||||||||
| 196 | # | ||||||||||||||||||||||||||||||||||
| 197 | 11 | my $opt_hr=shift(); | |||||||||||||||||||||||||||||||||
| 198 | 11 | ▶ | if ($opt_hr->{'index'} && $opt_hr->{'view_source'}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opt_hr->{"index"} and $opt_hr->{"view_source"}
MC/DC100%2/2
$opt_hr->{"index"} and $opt_hr->{"view_source"}
$opt_hr->{"index"}
$opt_hr->{"view_source"}
Truth table100%3/3
A and B
A= $opt_hr->{"index"}B= $opt_hr->{"view_source"}
| |||||||||||||||||||||||||||||||||||
| 199 | 2 | $ENV{'WEBDYNE_INDEX_SOURCE_ENABLE'}=1; | |||||||||||||||||||||||||||||||||
| 200 | 2 | $WebDyne::WEBDYNE_INDEX_SOURCE_ENABLE=1; | |||||||||||||||||||||||||||||||||
| 201 | 2 | $WebDyne::Constant::Constant{'WEBDYNE_INDEX_SOURCE_ENABLE'}=1; | |||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||||||||
| 204 | 9 | $opt_hr->{'view_source'}=0; | |||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||
| 206 | 11 | return \undef; | |||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||
| 211 | 2 | ▶ | sub request_mod_perl_startup { | ||||||||||||||||||||||||||||||||
|
Subroutine
request_mod_perl_startup: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||
| 214 | # Startup Apache test instance | ||||||||||||||||||||||||||||||||||
| 215 | # | ||||||||||||||||||||||||||||||||||
| 216 | 2 | my $opt_hr=shift(); | |||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | # Get postamble with WebDyne config | ||||||||||||||||||||||||||||||||||
| 220 | # | ||||||||||||||||||||||||||||||||||
| 221 | 2 | my $postamble=request_mod_perl_postamble($opt_hr->{'root'}, $opt_hr); | |||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||
| 224 | # Start Apache using Apache::Test. | ||||||||||||||||||||||||||||||||||
| 225 | # | ||||||||||||||||||||||||||||||||||
| 226 | return apache_startup({ | ||||||||||||||||||||||||||||||||||
| 227 | port => $opt_hr->{'port'}, | ||||||||||||||||||||||||||||||||||
| 228 | documentroot => $opt_hr->{'root'}, | ||||||||||||||||||||||||||||||||||
| 229 | postamble => $postamble, | ||||||||||||||||||||||||||||||||||
| 230 | 2 | keep_tmp => $opt_hr->{'keep_tmp'}, | |||||||||||||||||||||||||||||||||
| 231 | cache_dn_env => 1, | ||||||||||||||||||||||||||||||||||
| 232 | }); | ||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||
| 237 | 2 | ▶ | sub request_mod_perl_postamble { | ||||||||||||||||||||||||||||||||
|
Subroutine
request_mod_perl_postamble: called CC=14 SCAR=32.4
| |||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||
| 240 | # Get all WEBDYNE_CONF env vars and setup config file | ||||||||||||||||||||||||||||||||||
| 241 | # | ||||||||||||||||||||||||||||||||||
| 242 | 2 | my ($document_root, $opt_hr)=@_; | |||||||||||||||||||||||||||||||||
| 243 | 2 | $document_root=File::Spec->rel2abs($document_root); | |||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||
| 246 | # Need to work out if stderr writable. If not need to use alternate log file (prob running in container) | ||||||||||||||||||||||||||||||||||
| 247 | # | ||||||||||||||||||||||||||||||||||
| 248 | 2 | my $stderr_fn='/dev/stderr'; | |||||||||||||||||||||||||||||||||
| 249 | 2 | my $stdout_fn='/dev/stdout'; | |||||||||||||||||||||||||||||||||
| 250 | 2 | ▶ | if (! open(my $fh, '>>', $stderr_fn)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||
| 252 | # Not writable, probably running under docker, revert to traditional | ||||||||||||||||||||||||||||||||||
| 253 | # | ||||||||||||||||||||||||||||||||||
| 254 | 0 | print STDERR "unable to write to stderr,stdout - reverting to log files\n"; | |||||||||||||||||||||||||||||||||
| 255 | 0 | $stderr_fn='logs/error.log'; | |||||||||||||||||||||||||||||||||
| 256 | 0 | $stdout_fn='logs/access.log'; | |||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||
| 261 | # Kept for reference, but disabled for now. WebDyne::Util::apache_startup() | ||||||||||||||||||||||||||||||||||
| 262 | # already sets APACHE_TEST_ULIMIT_SET before Apache::TestRunPerl is loaded, | ||||||||||||||||||||||||||||||||||
| 263 | # and this shell probe emits noisy stderr on restricted CPAN smoke hosts | ||||||||||||||||||||||||||||||||||
| 264 | # where raising the core-file ulimit is not permitted. | ||||||||||||||||||||||||||||||||||
| 265 | # | ||||||||||||||||||||||||||||||||||
| 266 | # if (my $out = qx{sh -c 'ulimit -c unlimited 2>&1'}) { | ||||||||||||||||||||||||||||||||||
| 267 | # my $rc = $? >> 8; | ||||||||||||||||||||||||||||||||||
| 268 | # if ($rc != 0) { | ||||||||||||||||||||||||||||||||||
| 269 | # print STDERR "unable alter ulimit, stubbing Apache::TestRun::ulimit\n"; | ||||||||||||||||||||||||||||||||||
| 270 | # no warnings qw(once redefine); | ||||||||||||||||||||||||||||||||||
| 271 | # *Apache::TestRun::set_ulimit=sub {}; | ||||||||||||||||||||||||||||||||||
| 272 | # } | ||||||||||||||||||||||||||||||||||
| 273 | # } | ||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||
| 276 | # Running on Mac ? Need to load mod_rewrite manually. | ||||||||||||||||||||||||||||||||||
| 277 | # | ||||||||||||||||||||||||||||||||||
| 278 | 2 | my $module_load_rewrite=''; | |||||||||||||||||||||||||||||||||
| 279 | 2 | ▶ | if ($^O eq 'darwin') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | my $apxs = $ENV{APXS} || $ENV{APACHE_TEST_APXS} || 'apxs'; | ||||||||||||||||||||||||||||||||
|
Condition0%0/5
$ENV{'APXS'} || $ENV{'APACHE_TEST_APXS'} || 'apxs'
$ENV{"APXS"} or $ENV{"APACHE_TEST_APXS"}
MC/DC0%0/2
$ENV{'APXS'} || $ENV{'APACHE_TEST_APXS'} || 'apxs'
$ENV{"APXS"}
$ENV{"APACHE_TEST_APXS"}
Truth table0%0/3
A or B
A= $ENV{"APXS"}B= $ENV{"APACHE_TEST_APXS"}
| |||||||||||||||||||||||||||||||||||
| 281 | 0 | my $libexecdir = qx{"$apxs" -q 'libexecdir' 2>/dev/null}; | |||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | die "Unable to query 'libexecdir' using $apxs\n" if $? != 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 283 | 0 | chomp $libexecdir; | |||||||||||||||||||||||||||||||||
| 284 | 0 | $module_load_rewrite= <<"END" | |||||||||||||||||||||||||||||||||
| 285 | <IfModule !rewrite_module> | ||||||||||||||||||||||||||||||||||
| 286 | LoadModule rewrite_module $libexecdir/mod_rewrite.so | ||||||||||||||||||||||||||||||||||
| 287 | </IfModule> | ||||||||||||||||||||||||||||||||||
| 288 | END | ||||||||||||||||||||||||||||||||||
| 289 | ; | ||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||
| 293 | # Get any additional library paths we want | ||||||||||||||||||||||||||||||||||
| 294 | # | ||||||||||||||||||||||||||||||||||
| 295 | 2 | my @perl_inc_dn=@{&perl_inc_dn()}; | |||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||
| 298 | # Ok - proceed to build postamble | ||||||||||||||||||||||||||||||||||
| 299 | # | ||||||||||||||||||||||||||||||||||
| 300 | 2 | my $index_postamble=''; | |||||||||||||||||||||||||||||||||
| 301 | 2 | ▶ | if (my $document_default=$opt_hr->{'index'}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 302 | 1 | ▶ | if ($document_default eq '1') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 303 | 1 | ▶ | $document_default=File::Spec->rel2abs($WEBDYNE_DEFAULT_INDEX_FN || File::Spec->catfile($document_root, 'index.psp')); | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$main::WEBDYNE_DEFAULT_INDEX_FN || 'File::Spec'->catfile($document_root, 'index.psp')
MC/DC0%0/2
$main::WEBDYNE_DEFAULT_INDEX_FN || 'File::Spec'->catfile($document_root, 'index.psp')
$main::WEBDYNE_DEFAULT_INDEX_FN
'File::Spec'->catfile($document_root, 'index.psp')
Truth table33%1/3
A || B
A= $main::WEBDYNE_DEFAULT_INDEX_FNB= 'File::Spec'->catfile($document_root, 'index.psp')
| |||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||
| 305 | 1 | ▶ | if (File::Spec->file_name_is_absolute($document_default)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 306 | 1 | my $default_index_fn=File::Spec->rel2abs($document_default); | |||||||||||||||||||||||||||||||||
| 307 | 1 | my $default_index_dn=dirname($default_index_fn); | |||||||||||||||||||||||||||||||||
| 308 | 1 | $index_postamble= <<"END"; | |||||||||||||||||||||||||||||||||
| 309 | PerlSetEnv DOCUMENT_DEFAULT $default_index_fn | ||||||||||||||||||||||||||||||||||
| 310 | DirectoryIndex index.psp | ||||||||||||||||||||||||||||||||||
| 311 | Alias /index.psp $default_index_fn | ||||||||||||||||||||||||||||||||||
| 312 | AliasMatch ^/(.+)/index\\.psp\$ $default_index_fn | ||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||
| 314 | <Directory "$default_index_dn"> | ||||||||||||||||||||||||||||||||||
| 315 | Require all granted | ||||||||||||||||||||||||||||||||||
| 316 | </Directory> | ||||||||||||||||||||||||||||||||||
| 317 | RewriteEngine On | ||||||||||||||||||||||||||||||||||
| 318 | RewriteCond %{REQUEST_URI} !^/index\\.psp\$ | ||||||||||||||||||||||||||||||||||
| 319 | RewriteCond %{REQUEST_FILENAME} -d | ||||||||||||||||||||||||||||||||||
| 320 | RewriteRule ^ /index.psp [L,PT] | ||||||||||||||||||||||||||||||||||
| 321 | END | ||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||
| 323 | else { | ||||||||||||||||||||||||||||||||||
| 324 | 0 | $index_postamble= <<"END"; | |||||||||||||||||||||||||||||||||
| 325 | PerlSetEnv DOCUMENT_DEFAULT $document_default | ||||||||||||||||||||||||||||||||||
| 326 | DirectoryIndex $document_default | ||||||||||||||||||||||||||||||||||
| 327 | END | ||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||
| 330 | 1 | my @PerlSetEnv=map { sprintf('PerlSetEnv %s %s', $_, $ENV{$_}) } | |||||||||||||||||||||||||||||||||
| 331 | 1 | ▶ | grep { defined($ENV{$_}) && $ENV{$_} ne '' } | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $ENV{$_} && $ENV{$_} ne ''
MC/DC0%0/2
defined $ENV{$_} && $ENV{$_} ne ''
defined $ENV{$_}
$ENV{$_} ne ''
Truth table33%1/3
A && B
A= defined $ENV{$_}B= $ENV{$_} ne ''
| |||||||||||||||||||||||||||||||||||
| 332 | 2 | grep { /^WEBDYNE_/ } keys %ENV; | |||||||||||||||||||||||||||||||||
| 333 | 2 | ▶ | push (@PerlSetEnv, sprintf('PerlSetEnv DOCUMENT_ROOT %s', $opt_hr->{'root_pn'})) if $opt_hr->{'root_pn'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 334 | 2 | ▶ | push (@PerlSetEnv, "PerlSetEnv WEBDYNE_ERROR_TEXT 1") unless defined($ENV{'WEBDYNE_ERROR_TEXT'}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 335 | 2 | my $PerlSetEnv=join("\n", @PerlSetEnv); | |||||||||||||||||||||||||||||||||
| 336 | 2 | my $PerlSwitches=join("\n", map { sprintf('PerlSwitches -I%s', $_) } @perl_inc_dn); | |||||||||||||||||||||||||||||||||
| 337 | 2 | my $postamble= <<"END" | |||||||||||||||||||||||||||||||||
| 338 | $module_load_rewrite | ||||||||||||||||||||||||||||||||||
| 339 | $PerlSetEnv | ||||||||||||||||||||||||||||||||||
| 340 | $PerlSwitches | ||||||||||||||||||||||||||||||||||
| 341 | PerlModule WebDyne | ||||||||||||||||||||||||||||||||||
| 342 | AddHandler modperl .psp | ||||||||||||||||||||||||||||||||||
| 343 | PerlResponseHandler WebDyne | ||||||||||||||||||||||||||||||||||
| 344 | $index_postamble | ||||||||||||||||||||||||||||||||||
| 345 | #PerlOptions +GlobalRequest | ||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||
| 347 | ErrorLog $stderr_fn | ||||||||||||||||||||||||||||||||||
| 348 | LogLevel debug | ||||||||||||||||||||||||||||||||||
| 349 | CustomLog $stdout_fn combined | ||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||
| 351 | <Directory "$document_root"> | ||||||||||||||||||||||||||||||||||
| 352 | Require all granted | ||||||||||||||||||||||||||||||||||
| 353 | </Directory> | ||||||||||||||||||||||||||||||||||
| 354 | END | ||||||||||||||||||||||||||||||||||
| 355 | ; | ||||||||||||||||||||||||||||||||||
| 356 | 2 | ▶ | exit print $postamble if $opt_hr->{'dump_postamble'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 357 | 2 | return $postamble; | |||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||
| 361 | __END__ | ||||||||||||||||||||||||||||||||||