lib/Apache/TestConfigPerl.pm

filter: Statementstmt 13.9% 41 / 295 Branchbran 0.0% 0 / 126 Conditioncond 0.0% 0 / 31 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 29.0% 9 / 31 Podpod 0.0% 0 / 21 totaltotal 9.5% 50 / 523 CC 82 SCAR 46.2
CC
82
Cov
9%
add_module_config
240.0
configure_pm_tests
240.0
configure_libmodperl
156.0
CRAP 101.7
« lib/Apache/TestServer.pm ↑ Summary lib/Apache/TestConfig.pm »
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 package Apache::TestConfig; #not TestConfigPerl on purpose
17  
18 #things specific to mod_perl
19  
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use File::Spec::Functions qw(catfile splitdir abs2rel file_name_is_absolute);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use File::Find qw(finddepth);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Apache::TestTrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Apache::TestRequest;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 my %libmodperl = (1 => 'libperl.so', 2 => 'mod_perl.so');
29  
30 0 ▶sub configure_libmodperl {
Subroutine configure_libmodperl: not called CC=12 SCAR=50.5
Pod undocumented
31 0 my $self = shift;
32  
33 0 my $server = $self->{server};
34 0 my $libname = $server->version_of(\%libmodperl);
35 0 my $vars = $self->{vars};
36  
37 0 ▶ if ($vars->{libmodperl}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($vars->{'libmodperl'}) { } 0 0 0
elsif ($server->{'rev'} >= 2 and 0) { } 0 0 0
38 # if set, libmodperl was specified from the command line and
39 # should be used instead of the one that is looked up
40  
41 # resolve a non-absolute path
42 $vars->{libmodperl} = $self->find_apache_module($vars->{libmodperl})
43 0 ▶ unless file_name_is_absolute($vars->{libmodperl});
Branch: 1 branch
BranchTrueFalseTotal
unless file_name_is_absolute($vars->{"libmodperl"}) 0 0 0
44 }
45 # $server->{rev} could be set to 2 as a fallback, even when
46 # the wanted version is 1. So check that we use mod_perl 2
47 ▶ elsif ($server->{rev} >= 2 && IS_MOD_PERL_2) {
Condition0%0/2
$server->{"rev"} >= 2 and 0
!ll
00
MC/DC0%0/1
$server->{"rev"} >= 2 and 0
$server->{"rev"} >= 2
Truth table0%0/2
A
A= $server->{"rev"} >= 2
Aresult
00
11
48  
49 0 ▶ if (my $build_config = $self->modperl_build_config()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $build_config = $self->modperl_build_config) { } 0 0 0
50 0 ▶ if ($build_config->{MODPERL_LIB_SHARED}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($build_config->{'MODPERL_LIB_SHARED'}) { } 0 0 0
51 0 $libname = $build_config->{MODPERL_LIB_SHARED};
52 0 ▶ $vars->{libmodperl} ||= $self->find_apache_module($libname);
Condition0%0/3
$vars->{"libmodperl"} ||= $self->find_apache_module($libname)
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{"libmodperl"} ||= $self->find_apache_module($libname)
$vars->{"libmodperl"} $self->find_apache_module($libname)
Truth table0%0/3
A ||= B
A= $vars->{"libmodperl"}B= $self->find_apache_module($libname)
ABresult
1X1
011
000
53 } else {
54 0 ▶ $vars->{libmodperl} ||= $self->find_apache_module('mod_perl.so');
Condition0%0/3
$vars->{"libmodperl"} ||= $self->find_apache_module("mod_perl.so")
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{"libmodperl"} ||= $self->find_apache_module("mod_perl.so")
$vars->{"libmodperl"} $self->find_apache_module("mod_perl.so")
Truth table0%0/3
A ||= B
A= $vars->{"libmodperl"}B= $self->find_apache_module("mod_perl.so")
ABresult
1X1
011
000
55 }
56 # XXX: we have a problem with several perl trees pointing
57 # to the same httpd tree. So it's possible that we
58 # configure the test suite to run with mod_perl.so built
59 # against perl which it wasn't built with. Should we use
60 # something like ldd to check the match?
61 #
62 # For now, we'll default to the first mod_perl.so found.
63 }
64 else {
65 # XXX: can we test whether mod_perl was linked statically
66 # so we don't need to preload it
67 # if (!linked statically) {
68 # die "can't find mod_perl built for perl version $]"
69 # }
70 0 error "can't find mod_perl.so built for perl version $]";
71 }
72 # don't use find_apache_module or we may end up with the wrong
73 # shared object, built against different perl
74 }
75 else {
76 # mod_perl 1.0
77 0 ▶ $vars->{libmodperl} ||= $self->find_apache_module($libname);
Condition0%0/3
$vars->{"libmodperl"} ||= $self->find_apache_module($libname)
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{"libmodperl"} ||= $self->find_apache_module($libname)
$vars->{"libmodperl"} $self->find_apache_module($libname)
Truth table0%0/3
A ||= B
A= $vars->{"libmodperl"}B= $self->find_apache_module($libname)
ABresult
1X1
011
000
78 # XXX: how do we find out whether we have a static or dynamic
79 # mod_perl build? die if its dynamic and can't find the module
80 }
81  
82 0 my $cfg = '';
83  
84 0 ▶ if ($vars->{libmodperl} && -e $vars->{libmodperl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{'libmodperl'} and -e $vars->{'libmodperl'}) { } 0 0 0
Condition0%0/3
$vars->{"libmodperl"} and -e $vars->{"libmodperl"}
!ll&&!rl&&r
000
MC/DC0%0/2
$vars->{"libmodperl"} and -e $vars->{"libmodperl"}
$vars->{"libmodperl"} -e $vars->{"libmodperl"}
Truth table0%0/3
A and B
A= $vars->{"libmodperl"}B= -e $vars->{"libmodperl"}
ABresult
0X0
100
111
85 0 if (Apache::TestConfig::WIN32) {
86 my $lib = "$Config{installbin}\\$Config{libperl}";
87 $lib =~ s/lib$/dll/;
88 $cfg = 'LoadFile ' . qq("$lib"\n) if -e $lib;
89 }
90 # add the module we found to the cached modules list
91 # otherwise have_module('mod_perl') doesn't work unless
92 # we have a LoadModule in our base config
93 0 $self->{modules}->{'mod_perl.c'} = $vars->{libmodperl};
94  
95 0 $cfg .= 'LoadModule ' . qq(perl_module "$vars->{libmodperl}"\n);
96 }
97 else {
98 0 my $msg = "unable to locate $libname (could be a static build)\n";
99 0 $cfg = "#$msg";
100 0 debug $msg;
101 }
102  
103 0 $self->preamble(IfModule => '!mod_perl.c', $cfg);
104  
105 }
106  
107 0 ▶sub configure_inc {
Subroutine configure_inc: not called CC=8 SCAR=42.8
Pod undocumented
108 0 my $self = shift;
109  
110 0 my $top = $self->{vars}->{top_dir};
111  
112 0 my $inc = $self->{inc};
113  
114 0 for (catdir($top, qw(blib lib)), catdir($top, qw(blib arch))) {
115 0 ▶ if (-d $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $_) 0 0 0
116 0 push @$inc, $_;
117 }
118 }
119  
120 # try ../blib as well for Apache::Reload & Co
121 0 for (catdir($top, qw(.. blib lib)), catdir($top, qw(.. blib arch))) {
122 0 ▶ push @$inc, $_ if -d $_;
Branch: 1 branch
BranchTrueFalseTotal
if -d $_ 0 0 0
123 }
124  
125 # spec: If PERL5LIB is defined, PERLLIB is not used.
126 0 for (qw(PERL5LIB PERLLIB)) {
127 0 ▶ next unless exists $ENV{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ENV{$_} 0 0 0
128 0 push @$inc, split /$Config{path_sep}/, $ENV{$_};
129 0 last;
130 }
131  
132 # enable live testing of the Apache-Test dev modules if they are
133 # located at the project's root dir
134 0 my $apache_test_dev_dir = catfile($top, 'Apache-Test', 'lib');
135 0 ▶ unshift @$inc, $apache_test_dev_dir if -d $apache_test_dev_dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $apache_test_dev_dir 0 0 0
136 }
137  
138 0 ▶sub write_pm_test {
Subroutine write_pm_test: not called CC=3 SCAR=24.8
Pod undocumented
139 0 my($self, $module, $sub, @base) = @_;
140  
141 0 my $dir = catfile $self->{vars}->{t_dir}, @base;
142 0 my $t = catfile $dir, "$sub.t";
143 0 ▶ return if -e $t;
Branch: 1 branch
BranchTrueFalseTotal
if -e $t 0 0 0
144  
145 0 $self->gendir($dir);
146 0 my $fh = $self->genfile($t);
147  
148 0 my $path = Apache::TestRequest::module2path($module);
149  
150 0 print $fh <<EOF;
151 use Apache::TestRequest 'GET_BODY_ASSERT';
152 print GET_BODY_ASSERT "/$path";
153 EOF
154  
155 0 ▶ close $fh or die "close $t: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "close ${t}: $!" 0 0 0
156 }
157  
158 # propogate PerlPassEnv settings to the server
159 0 ▶sub configure_env {
Subroutine configure_env: not called CC=1 SCAR=6.9
Pod undocumented
160 0 my $self = shift;
161 0 $self->preamble(IfModule => 'mod_perl.c',
162 [ qw(PerlPassEnv APACHE_TEST_TRACE_LEVEL
163 PerlPassEnv HARNESS_PERL_SWITCHES
164 PerlPassEnv APACHE_TEST_NO_STICKY_PREFERENCES)
165 ]);
166 }
167  
168 0 ▶sub startup_pl_code {
Subroutine startup_pl_code: not called CC=1 SCAR=6.9
Pod undocumented
169 0 my $self = shift;
170 0 my $serverroot = $self->{vars}->{serverroot};
171  
172 0 my $cover = <<'EOF';
173 if (($ENV{HARNESS_PERL_SWITCHES}||'') =~ m/Devel::Cover/) {
174 eval {
175 # 0.48 is the first version of Devel::Cover that can
176 # really generate mod_perl coverage statistics
177 require Devel::Cover;
178 Devel::Cover->VERSION(0.48);
179  
180 # this ignores coverage data for some generated files
181 Devel::Cover->import('+inc' => 't/response/',);
182  
183 1;
184 } or die "Devel::Cover error: $@";
185 }
186 EOF
187  
188 0 return <<"EOF";
189 BEGIN {
190 use lib '$serverroot';
191 for my \$file (qw(modperl_inc.pl modperl_extra.pl)) {
192 eval { require "conf/\$file" } or
193 die if grep { -e "\$_/conf/\$file" } \@INC;
194 }
195  
196 $cover
197 }
198  
199 1;
200 EOF
201 }
202  
203 0 ▶sub configure_startup_pl {
Subroutine configure_startup_pl: not called CC=10 SCAR=47.0
Pod undocumented
204 0 my $self = shift;
205  
206 #for 2.0 we could just use PerlSwitches -Mlib=...
207 #but this will work for both 2.0 and 1.xx
208 0 ▶ if (my $inc = $self->{inc}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $inc = $self->{"inc"}) 0 0 0
209 0 my $include_pl = catfile $self->{vars}->{t_conf}, 'modperl_inc.pl';
210 0 my $fh = $self->genfile($include_pl);
211 0 for (reverse @$inc) {
212 0 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
213 0 print $fh "use lib '$_';\n";
214 }
215 0 my $tlib = catdir $self->{vars}->{t_dir}, 'lib';
216 0 ▶ if (-d $tlib) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $tlib) 0 0 0
217 0 print $fh "use lib '$tlib';\n";
218 }
219  
220 # directory for temp packages which can change during testing
221 # we use require here since a circular dependency exists
222 # between Apache::TestUtil and Apache::TestConfigPerl, so
223 # use does not work here
224 0 eval { require Apache::TestUtil; };
225 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
226 0 die "could not require Apache::TestUtil: $@";
227 } else {
228 0 print $fh "use lib '" . Apache::TestUtil::_temp_package_dir() . "';\n";
229 }
230  
231 # if Apache::Test is used to develop a project, we want the
232 # project/lib directory to be first in @INC (loaded last)
233 0 ▶ if ($ENV{APACHE_TEST_LIVE_DEV}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"APACHE_TEST_LIVE_DEV"}) 0 0 0
234 0 my $dev_lib = catdir $self->{vars}->{top_dir}, "lib";
235 0 ▶ print $fh "use lib '$dev_lib';\n" if -d $dev_lib;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dev_lib 0 0 0
236 }
237  
238 0 print $fh "1;\n";
239 }
240  
241 0 ▶ if ($self->server->{rev} >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->server->{"rev"} >= 2) 0 0 0
242 0 $self->postamble(IfModule => 'mod_perl.c',
243 "PerlSwitches -Mlib=$self->{vars}->{serverroot}\n");
244 }
245  
246 0 my $startup_pl = catfile $self->{vars}->{t_conf}, 'modperl_startup.pl';
247  
248 0 ▶ unless (-e $startup_pl) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $startup_pl) 0 0 0
249 0 my $fh = $self->genfile($startup_pl);
250 0 print $fh $self->startup_pl_code;
251 0 close $fh;
252 }
253  
254 0 $self->postamble(IfModule => 'mod_perl.c',
255 "PerlRequire $startup_pl\n");
256 }
257  
258 1 my %sethandler_modperl = (1 => 'perl-script', 2 => 'modperl');
259  
260 0 ▶sub set_handler {
Subroutine set_handler: not called CC=2 SCAR=17.9
Pod undocumented
261 0 my($self, $module, $args) = @_;
262 0 ▶ return if grep { $_ eq 'SetHandler' } @$args;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "SetHandler";} @$args 0 0 0
263  
264 0 push @$args,
265 SetHandler =>
266 $self->server->version_of(\%sethandler_modperl);
267 }
268  
269 0 ▶sub set_connection_handler {
Subroutine set_connection_handler: not called CC=1 SCAR=6.9
Pod undocumented
270 0 my($self, $module, $args) = @_;
271 0 my $port = $self->new_vhost($module);
272 0 my $vars = $self->{vars};
273 0 $self->postamble(Listen => '0.0.0.0:' . $port);
274 }
275  
276 1 my %add_hook_config = (
277 Response => \&set_handler,
278 ProcessConnection => \&set_connection_handler,
279 PreConnection => \&set_connection_handler,
280 );
281  
282 1 my %container_config = (
283 ProcessConnection => \&vhost_container,
284 PreConnection => \&vhost_container,
285 );
286  
287 0 ▶sub location_container {
Subroutine location_container: not called CC=1 SCAR=6.9
Pod undocumented
288 0 my($self, $module) = @_;
289 0 my $path = Apache::TestRequest::module2path($module);
290 0 Location => "/$path";
291 }
292  
293 0 ▶sub vhost_container {
Subroutine vhost_container: not called CC=2 SCAR=17.9
Pod undocumented
294 0 my($self, $module) = @_;
295 0 my $port = $self->{vhosts}->{$module}->{port};
296 0 my $namebased = $self->{vhosts}->{$module}->{namebased};
297  
298 0 ▶ VirtualHost => ($namebased ? '*' : '_default_') . ":$port";
Branch: 1 branch
BranchTrueFalseTotal
$namebased ? : 0 0 0
299 }
300  
301 0 ▶sub new_vhost {
Subroutine new_vhost: not called CC=4 SCAR=30.0
Pod undocumented
302 0 my($self, $module, $namebased) = @_;
303 0 my($port, $servername, $vhost);
304  
305 0 ▶ unless ($namebased and exists $self->{vhosts}->{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($namebased and exists $self->{'vhosts'}{$module}) { } 0 0 0
Condition0%0/3
$namebased and exists $self->{"vhosts"}{$module}
!ll&&!rl&&r
000
MC/DC0%0/2
$namebased and exists $self->{"vhosts"}{$module}
$namebased exists $self->{"vhosts"}{$module}
Truth table0%0/3
A and B
A= $namebasedB= exists $self->{"vhosts"}{$module}
ABresult
0X0
100
111
306 0 $port = $self->server->select_next_port;
307 0 $vhost = $self->{vhosts}->{$module} = {};
308  
309 0 $vhost->{port} = $port;
310 0 ▶ $vhost->{namebased} = $namebased ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$namebased ? : 0 0 0
311 }
312 else {
313 0 $vhost = $self->{vhosts}->{$module};
314 0 $port = $vhost->{port};
315 # remember the already configured Listen/NameVirtualHost
316 0 $vhost->{namebased}++;
317 }
318  
319 0 $servername = $self->{vars}->{servername};
320  
321 0 $vhost->{servername} = $servername;
322 0 $vhost->{name} = join ':', $servername, $port;
323 0 $vhost->{hostport} = $self->hostport($vhost, $module);
324  
325 0 $port;
326 }
327  
328 1 my %outside_container = map { $_, 1 } qw{
329 Alias AliasMatch AddType
330 PerlChildInitHandler PerlTransHandler PerlPostReadRequestHandler
331 PerlSwitches PerlRequire PerlModule
332 };
333  
334 1 my %strip_tags = map { $_ => 1} qw(base noautoconfig);
335  
336 #test .pm's can have configuration after the __DATA__ token
337 0 ▶sub add_module_config {
Subroutine add_module_config: not called CC=15 SCAR=54.8
Pod undocumented
338 0 my($self, $module, $args) = @_;
339 0 my $fh = Symbol::gensym();
340 0 ▶ open($fh, $module) or return;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, $module or return 0 0 0
341  
342 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
343 0 ▶ last if /^(__(DATA|END)__|\#if CONFIG_FOR_HTTPD_TEST)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^(__(DATA|END)__|\#if CONFIG_FOR_HTTPD_TEST)/ 0 0 0
344 }
345  
346 0 my %directives;
347  
348 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
349 0 ▶ last if /^\#endif/; #for .c modules
Branch: 1 branch
BranchTrueFalseTotal
if /^\#endif/ 0 0 0
350 0 ▶ next unless /\S+/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\S+/ 0 0 0
351 0 chomp;
352 0 s/^\s+//;
353 0 $self->replace;
354 0 ▶ if (/^#/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^#/) 0 0 0
355 # preserve comments
356 0 $self->postamble($_);
357 0 next;
358 }
359 0 my($directive, $rest) = split /\s+/, $_, 2;
360 0 ▶ $directives{$directive}++ unless $directive =~ /^</;
Branch: 1 branch
BranchTrueFalseTotal
unless $directive =~ /^</ 0 0 0
361 0 ▶ $rest = '' unless defined $rest;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rest 0 0 0
362  
363 0 ▶ if ($outside_container{$directive}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($outside_container{$directive}) { } 0 0 0
elsif ($directive =~ /IfModule/) { } 0 0 0
elsif ($directive =~ /^<(\w+)/) { } 0 0 0
364 0 $self->postamble($directive => $rest);
365 }
366 elsif ($directive =~ /IfModule/) {
367 0 $self->postamble($_);
368 }
369 elsif ($directive =~ m/^<(\w+)/) {
370 # strip special container directives like <Base> and </Base>
371 0 ▶ my $strip_container = exists $strip_tags{lc $1} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $strip_tags{lc $1} ? : 0 0 0
372  
373 0 ▶ $directives{noautoconfig}++ if lc($1) eq 'noautoconfig';
Branch: 1 branch
BranchTrueFalseTotal
if lc $1 eq "noautoconfig" 0 0 0
374  
375 0 my $indent = '';
376 0 $self->process_container($_, $fh, lc($1),
377 $strip_container, $indent);
378 }
379 else {
380 0 push @$args, $directive, $rest;
381 }
382 }
383  
384 0 \%directives;
385 }
386  
387  
388 # recursively process the directives including nested containers,
389 # re-indent 4 and ucfirst the closing tags letter
390 0 ▶sub process_container {
Subroutine process_container: not called CC=4 SCAR=30.0
Pod undocumented
391 0 my($self, $first_line, $fh, $directive, $strip_container, $indent) = @_;
392  
393 0 my $new_indent = $indent;
394  
395 0 ▶ unless ($strip_container) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($strip_container) 0 0 0
396 0 $new_indent .= " ";
397  
398 0 local $_ = $first_line;
399 0 s/^\s*//;
400 0 $self->replace;
401  
402 0 ▶ if (/<VirtualHost/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/<VirtualHost/) { } 0 0 0
403 0 $self->process_vhost_open_tag($_, $indent);
404 }
405 else {
406 0 $self->postamble($indent . $_);
407 }
408 }
409  
410 0 $self->process_container_remainder($fh, $directive, $new_indent);
411  
412 0 ▶ unless ($strip_container) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($strip_container) 0 0 0
413 0 $self->postamble($indent . "</\u$directive>");
414 }
415  
416 }
417  
418  
419 # processes the body of the container without the last line, including
420 # the end tag
421 0 ▶sub process_container_remainder {
Subroutine process_container_remainder: not called CC=4 SCAR=30.0
Pod undocumented
422 0 my($self, $fh, $directive, $indent) = @_;
423  
424 0 my $end_tag = "</$directive>";
425  
426 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
427 0 chomp;
428 0 ▶ last if m|^\s*\Q$end_tag|i;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*\Q$end_tag\E/i 0 0 0
429 0 s/^\s*//;
430 0 $self->replace;
431  
432 0 ▶ if (m/^\s*<(\w+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*<(\w+)/) { } 0 0 0
433 0 $self->process_container($_, $fh, $1, 0, $indent);
434 }
435 else {
436 0 $self->postamble($indent . $_);
437 }
438 }
439 }
440  
441 # does the necessary processing to create a vhost container header
442 0 ▶sub process_vhost_open_tag {
Subroutine process_vhost_open_tag: not called CC=2 SCAR=17.9
Pod undocumented
443 0 my($self, $line, $indent) = @_;
444  
445 0 my $cfg = $self->parse_vhost($line);
446  
447 0 ▶ if ($cfg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfg) { } 0 0 0
448 0 my $port = $cfg->{port};
449 0 $cfg->{out_postamble}->();
450 0 $self->postamble($cfg->{line});
451 0 $cfg->{in_postamble}->();
452 } else {
453 0 $self->postamble("$indent$line");
454 }
455 }
456  
457 #the idea for each group:
458 # Response: there will be many of these, mostly modules to test the API
459 # that plan tests => ... and output with ok()
460 # the naming allows grouping, making it easier to run an
461 # individual set of tests, e.g. t/TEST t/apr
462 # the PerlResponseHandler and SetHandler modperl is auto-configured
463 # Hooks: for testing the simpler Perl*Handlers
464 # auto-generates the Perl*Handler config
465 # Protocol: protocol modules need their own port/vhost to listen on
466  
467 #@INC is auto-modified so each test .pm can be found
468 #modules can add their own configuration using __DATA__
469  
470 1 my %hooks = map { $_, ucfirst $_ }
471 qw(init trans headerparser access authen authz type fixup log);
472 1 $hooks{Protocol} = 'ProcessConnection';
473 1 $hooks{Filter} = 'OutputFilter';
474  
475 1 my @extra_subdirs = qw(Response Protocol PreConnection Hooks Filter);
476  
477 # add the subdirs to @INC early, in case mod_perl is started earlier
478 0 ▶sub configure_pm_tests_inc {
Subroutine configure_pm_tests_inc: not called CC=3 SCAR=24.8
Pod undocumented
479 0 my $self = shift;
480 0 for my $subdir (@extra_subdirs) {
481 0 my $dir = catfile $self->{vars}->{t_dir}, lc $subdir;
482 0 ▶ next unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
483  
484 0 push @{ $self->{inc} }, $dir;
485 }
486 }
487  
488 # @status fields
489 1 ▶use constant APACHE_TEST_CONFIGURE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
490 1 ▶use constant APACHE_TEST_CONFIG_ORDER => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
491  
492 0 ▶sub configure_pm_tests_pick {
Subroutine configure_pm_tests_pick: not called CC=3 SCAR=24.8
Pod undocumented
493 0 my($self, $entries) = @_;
494  
495 0 for my $subdir (@extra_subdirs) {
496 0 my $dir = catfile $self->{vars}->{t_dir}, lc $subdir;
497 0 ▶ next unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
498  
499 0 ▶ finddepth(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
500 0 ▶ return unless /\.pm$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\.pm$/ 0 0 0
501  
502 0 my $file = catfile $File::Find::dir, $_;
503 0 my $module = abs2rel $file, $dir;
504 0 my $status = $self->run_apache_test_config_scan($file);
505 0 push @$entries, [$file, $module, $subdir, $status];
506 0 }, $dir);
507 }
508 }
509  
510  
511 # a simple numerical order is performed and configuration sections are
512 # inserted using that order. If the test package specifies no special
513 # token that matches /APACHE_TEST_CONFIG_ORDER\s+([+-]?\d+)/ anywhere
514 # in the file, 0 is assigned as its order. If the token is specified,
515 # config section with negative values will be inserted first, with
516 # positive last. By using different values you can arrange for the
517 # test configuration sections to be inserted in any desired order
518 0 ▶sub configure_pm_tests_sort {
Subroutine configure_pm_tests_sort: not called CC=1 SCAR=6.9
Pod undocumented
519 0 my($self, $entries) = @_;
520  
521 @$entries = sort {
522 0 $a->[3]->[APACHE_TEST_CONFIG_ORDER] <=>
523 $b->[3]->[APACHE_TEST_CONFIG_ORDER]
524 } @$entries;
525  
526 }
527  
528 0 ▶sub configure_pm_tests {
Subroutine configure_pm_tests: not called CC=15 SCAR=54.8
Pod undocumented
529 0 my $self = shift;
530  
531 0 my @entries = ();
532 0 $self->configure_pm_tests_pick(\@entries);
533 0 $self->configure_pm_tests_sort(\@entries);
534  
535 0 for my $entry (@entries) {
536 0 my ($file, $module, $subdir, $status) = @$entry;
537 0 my @args = ();
538  
539 0 my $file_display;
540 {
541 0 $file_display=$file;
542 0 my $topdir=$self->{vars}->{top_dir};
543 0 $file_display=~s!^\Q$topdir\E(.)(?:\1)*!!;
544 }
545 0 $self->postamble("\n# included from $file_display");
546 0 my $directives = $self->add_module_config($file, \@args);
547 0 $module =~ s,\.pm$,,;
548 0 $module =~ s/^[a-z]://i; #strip drive if any
549 0 $module = join '::', splitdir $module;
550  
551 0 $self->run_apache_test_configure($file, $module, $status);
552  
553 my @base =
554 0 map { s/^test//i; $_ } split '::', $module;
555  
556 0 my $sub = pop @base;
557  
558 my $hook = ($subdir eq 'Hooks' ? $hooks{$sub} : '')
559 0 ▶ || $hooks{$subdir} || $subdir;
Branch: 1 branch
BranchTrueFalseTotal
$subdir eq 'Hooks' ? : 0 0 0
Condition0%0/6
($subdir eq 'Hooks' ? $hooks{$sub} : '') || $hooks{$subdir} || $subdir
l!l&&r!l&&!r
000
$subdir eq "Hooks" ? $hooks{$sub} : "" or $hooks{$subdir}
l!l&&r!l&&!r
000
MC/DC0%0/3
($subdir eq 'Hooks' ? $hooks{$sub} : '') || $hooks{$subdir} || $subdir
$subdir eq "Hooks" ? $hooks{$sub} : "" $hooks{$subdir} $subdir
Truth table0%0/4
A or B || C
A= $subdir eq "Hooks" ? $hooks{$sub} : ""B= $hooks{$subdir}C= $subdir
ABCresult
1XX1
01X1
0011
0000
560  
561 0 ▶ if ($hook eq 'OutputFilter' and $module =~ /::i\w+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hook eq "OutputFilter" and $module =~ /::i\w+$/) 0 0 0
Condition0%0/3
$hook eq "OutputFilter" and $module =~ /::i\w+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$hook eq "OutputFilter" and $module =~ /::i\w+$/
$hook eq "OutputFilter" $module =~ /::i\w+$/
Truth table0%0/3
A and B
A= $hook eq "OutputFilter"B= $module =~ /::i\w+$/
ABresult
0X0
100
111
562 #XXX: tmp hack
563 0 $hook = 'InputFilter';
564 }
565  
566 0 my $handler = join $hook, qw(Perl Handler);
567  
568 0 ▶ if ($self->server->{rev} < 2 and lc($hook) eq 'response') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->server->{"rev"} < 2 and lc $hook eq "response") 0 0 0
Condition0%0/3
$self->server->{"rev"} < 2 and lc $hook eq "response"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->server->{"rev"} < 2 and lc $hook eq "response"
$self->server->{"rev"} < 2 lc $hook eq "response"
Truth table0%0/3
A and B
A= $self->server->{"rev"} < 2B= lc $hook eq "response"
ABresult
0X0
100
111
569 0 $handler =~ s/response//i; #s/PerlResponseHandler/PerlHandler/
570 }
571  
572 0 debug "configuring $module";
573  
574 0 ▶ unless ($directives->{noautoconfig}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($directives->{"noautoconfig"}) 0 0 0
575 0 ▶ if (my $cv = $add_hook_config{$hook}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cv = $add_hook_config{$hook}) 0 0 0
576 0 $self->$cv($module, \@args);
577 }
578  
579 0 ▶ my $container = $container_config{$hook} || \&location_container;
Condition0%0/2
$container_config{$hook} || \&Apache::TestConfig::location_container
l!l
00
MC/DC0%0/1
$container_config{$hook} || \&Apache::TestConfig::location_container
$container_config{$hook}
Truth table0%0/2
A
A= $container_config{$hook}
Aresult
11
00
580  
581 #unless the .pm test already configured the Perl*Handler
582 0 ▶ unless ($directives->{$handler}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($directives->{$handler}) 0 0 0
583 0 my @handler_cfg = ($handler => $module);
584  
585 0 ▶ if ($outside_container{$handler}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outside_container{$handler}) { } 0 0 0
586 0 my $cfg = $self->massage_config_args(@handler_cfg);
587 0 $self->postamble(IfModule => 'mod_perl.c', $cfg);
588 } else {
589 0 push @args, @handler_cfg;
590 }
591 }
592  
593 0 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
594 0 my $cfg = $self->massage_config_args($self->$container($module), \@args);
595 0 $self->postamble(IfModule => 'mod_perl.c', $cfg);
596 }
597 }
598 0 $self->postamble("# end of $file_display\n");
599  
600 0 $self->write_pm_test($module, lc $sub, map { lc } @base);
601 }
602 }
603  
604 # scan tests for interesting information
605 0 ▶sub run_apache_test_config_scan {
Subroutine run_apache_test_config_scan: not called CC=4 SCAR=30.0
Pod undocumented
606 0 my ($self, $file) = @_;
607  
608 0 my @status = ();
609 0 $status[APACHE_TEST_CONFIGURE] = 0;
610 0 $status[APACHE_TEST_CONFIG_ORDER] = 0;
611  
612 0 my $fh = Symbol::gensym();
613 0 ▶ if (open $fh, $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, $file) { } 0 0 0
614 0 local $/;
615 0 my $content = <$fh>;
616 0 close $fh;
617 # XXX: optimize to match once?
618 0 ▶ if ($content =~ /APACHE_TEST_CONFIGURE/m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /APACHE_TEST_CONFIGURE/m) 0 0 0
619 0 $status[APACHE_TEST_CONFIGURE] = 1;
620 }
621 0 ▶ if ($content =~ /APACHE_TEST_CONFIG_ORDER\s+([+-]?\d+)/m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /APACHE_TEST_CONFIG_ORDER\s+([+-]?\d+)/m) 0 0 0
622 0 $status[APACHE_TEST_CONFIG_ORDER] = int $1;
623 }
624 }
625 else {
626 0 error "cannot open $file: $!";
627 }
628  
629 0 return \@status;
630 }
631  
632 # We have to test whether tests have APACHE_TEST_CONFIGURE() in them
633 # and run it if found at this stage, so when the server starts
634 # everything is ready.
635 # XXX: however we cannot use a simple require() because some tests
636 # won't require() outside of mod_perl environment. Therefore we scan
637 # the slurped file in. and if APACHE_TEST_CONFIGURE has been found we
638 # require the file and run this function.
639 0 ▶sub run_apache_test_configure {
Subroutine run_apache_test_configure: not called CC=5 SCAR=34.0
Pod undocumented
640 0 my ($self, $file, $module, $status) = @_;
641  
642 0 ▶ return unless $status->[APACHE_TEST_CONFIGURE];
Branch: 1 branch
BranchTrueFalseTotal
unless $status->[0] 0 0 0
643  
644 0 eval { require $file };
645 0 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
646 # double check that it's a real sub
647 0 ▶ if ($module->can('APACHE_TEST_CONFIGURE')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module->can("APACHE_TEST_CONFIGURE")) 0 0 0
648 0 eval { $module->APACHE_TEST_CONFIGURE($self); };
649 0 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
650 }
651 }
652  
653  
654 1 1;
« lib/Apache/TestServer.pm ↑ Summary lib/Apache/TestConfig.pm »