| 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::TestRunPerl; | ||
| 17 | |||
| 18 | use strict; | ||
| 19 | use warnings FATAL => 'all'; | ||
| 20 | |||
| 21 | use Apache::TestRun (); | ||
| 22 | use Apache::TestConfigParse (); | ||
| 23 | use Apache::TestTrace; | ||
| 24 | |||
| 25 | use vars qw($VERSION); | ||
| 26 | $VERSION = '1.00'; # make CPAN.pm's r() version scanner happy | ||
| 27 | |||
| 28 | use File::Spec::Functions qw(catfile); | ||
| 29 | |||
| 30 | #subclass of Apache::TestRun that configures mod_perlish things | ||
| 31 | use vars qw(@ISA); | ||
| 32 | @ISA = qw(Apache::TestRun); | ||
| 33 | |||
| 34 | sub pre_configure { | ||
| 35 | my $self = shift; | ||
| 36 | |||
| 37 | # Apache::TestConfigPerl already configures mod_perl.so | ||
| 38 | Apache::TestConfig::autoconfig_skip_module_add('mod_perl.c'); | ||
| 39 | |||
| 40 | # skip over Embperl.so - it's funky | ||
| 41 | Apache::TestConfig::autoconfig_skip_module_add('Embperl.c'); | ||
| 42 | } | ||
| 43 | |||
| 44 | sub configure_modperl { | ||
| 45 | my $self = shift; | ||
| 46 | |||
| 47 | my $test_config = $self->{test_config}; | ||
| 48 | |||
| 49 | my $rev = $test_config->server->{rev}; | ||
| 50 | my $ver = $test_config->server->{version}; | ||
| 51 | |||
| 52 | # sanity checking and loading the right mod_perl version | ||
| 53 | |||
| 54 | # remove mod_perl.pm from %INC so that the below require() | ||
| 55 | # calls accurately populate $mp_ver | ||
| 56 | delete $INC{'mod_perl.pm'}; | ||
| 57 | |||
| 58 | if ($rev == 2) { | ||
| 59 | eval { require mod_perl2 }; | ||
| 60 | } else { | ||
| 61 | eval { require mod_perl }; | ||
| 62 | } | ||
| 63 | |||
| 64 | my $mp_ver = $mod_perl::VERSION; | ||
| 65 | if ($@) { | ||
| 66 | error "You are using mod_perl response handlers ", | ||
| 67 | "but do not have a mod_perl capable Apache."; | ||
| 68 | Apache::TestRun::exit_perl(0); | ||
| 69 | } | ||
| 70 | if (($rev == 1 && $mp_ver >= 1.99) || | ||
| 71 | ($rev == 2 && $mp_ver < 1.99)) { | ||
| 72 | error "Found mod_perl/$mp_ver, but it can't be used with $ver"; | ||
| 73 | Apache::TestRun::exit_perl(0); | ||
| 74 | } | ||
| 75 | |||
| 76 | if ($rev == 2) { | ||
| 77 | # load apreq2 if it is present | ||
| 78 | # do things a bit differently that find_and_load_module() | ||
| 79 | # because apreq2 can't be loaded that way (the 2 causes a problem) | ||
| 80 | my $name = 'mod_apreq2.so'; | ||
| 81 | if (my $mod_path = $test_config->find_apache_module($name)) { | ||
| 82 | |||
| 83 | # don't match the 2 here | ||
| 84 | my ($sym) = $name =~ m/mod_(\w+)2\./; | ||
| 85 | |||
| 86 | if ($mod_path && -e $mod_path) { | ||
| 87 | $test_config->preamble(IfModule => "!mod_$sym.c", | ||
| 88 | qq{LoadModule ${sym}_module "$mod_path"\n}); | ||
| 89 | } | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | $test_config->preamble_register(qw(configure_libmodperl | ||
| 94 | configure_env)); | ||
| 95 | |||
| 96 | $test_config->postamble_register(qw(configure_inc | ||
| 97 | configure_pm_tests_inc | ||
| 98 | configure_startup_pl | ||
| 99 | configure_pm_tests)); | ||
| 100 | } | ||
| 101 | |||
| 102 | sub configure { | ||
| 103 | my $self = shift; | ||
| 104 | |||
| 105 | $self->configure_modperl; | ||
| 106 | |||
| 107 | $self->SUPER::configure; | ||
| 108 | } | ||
| 109 | |||
| 110 | #if Apache::TestRun refreshes config in the middle of configure | ||
| 111 | #we need to re-add modperl configure hooks | ||
| 112 | sub refresh { | ||
| 113 | my $self = shift; | ||
| 114 | $self->SUPER::refresh; | ||
| 115 | $self->configure_modperl; | ||
| 116 | } | ||
| 117 | |||
| 118 | 1; | ||
| 119 | __END__ |