Hi,

thanks to all of your help, I found a way to achieve the following
goal:

- have a couple of instances of a web application running under the
  same (name based) virtual host, under different <Location>s each
  using a different configuration than the others

- having backwards compatibillity to pure CGI without mod_perl

- have both of these points working without modifying anything in the
  (countless) scripts themselve but only in the environment like
  httpd.conf, startup.pl and of course the configuration file.

Even if it's just a little achievement I make my solution public,
hoping it saves others some time in the future. Or maybe someone has
suggestions, to improve it?

Here we go:
First, for using mod_perl, httpd.conf includes the following
(example for two instances on the server):

httpd.conf
-----------------------------------
NameVirtualHost 192.168.1.83:80
<VirtualHost 192.168.1.83>
 DocumentRoot "/www/u-dev-local/htdocs"
 ServerName u-dev-local

 PerlModule Apache::Registry
 PerlModule Apache::DBI
 PerlTaintCheck On

 Alias /contest /www/u-dev-local/contest
 <Location /contest>
   SetHandler perl-script
   PerlHandler Apache::Registry
   PerlSendHeader Off
   PerlSetVar ConfigMod Contest::Config
   PerlRequire /www/u-dev-local/contest/mod_perl_init.pl
   Options ExecCGI
   allow from all
 </Location>

 Alias /contest_demo /www/u-dev-local/contest_demo
 <Location /contest_demo>
   SetHandler perl-script
   PerlHandler Apache::Registry
   PerlSendHeader Off
   PerlSetVar ConfigMod ContestDemo::Config
   PerlRequire /www/u-dev-local/contest_demo/mod_perl_init.pl
   Options ExecCGI
   allow from all
 </Location>

</VirtualHost>
-----------------------------------

For each instance of the application, I have different startup-scripts
which load the Config-File for the instance:

/www/u-dev-local/contest/mod_perl_init.pl
-----------------------------------
use lib "/www/u-dev-local/contest";
use Contest::Config;
-----------------------------------

/www/u-dev-local/contest_demo/mod_perl_init.pl
-----------------------------------
use lib "/www/u-dev-local/contest_demo";
use ContestDemo::Config;
-----------------------------------


And in the scripts the decision has to be made, if the
default configuration file is used (netContestConfig), or if the
context of the request is given to the script as an argument (which
means running under mod_perl), and the name of the configfile is
given, too:

somescript.pl
-----------------------------------
#!/usr/bin/perl -wT
use strict;
use lib ".";
use lib_netContest;
use DBI;
use CGI (qw:standard:);

use vars qw(%c $config_module $db_handle);

my $r = shift;

if (defined $r && $r->dir_config('ConfigMod')) {
   $config_module = $r->dir_config('ConfigMod');
}
else {
   use netContestConfig;
   $config_module = "netContestConfig";
}

{
   no strict 'refs';
   *c = \%{"${config_module}::c"};
}
-----------------------------------

And by the way: the configfile has the "hash structure" described by
Stas Bekman at
http://perl.apache.org/preview/modperl-docs/dst_html/docs/1.0/guide/porting.html#Configuration_Files__Writing__Dynamically_Updating_and_Reloading
And: one must not forget to change the package declaration in the
config file if using not the default file.

Again: thank you!
S.Stuckenbrock

-- 
netendance GmbH
Sören Stuckenbrock
Fränkische Straße 38
30455 Hannover

Telefon: 49 (0) 511/4733773
Fax    : 49 (0) 511/4733776
Mobil  : 49 (0) 173/6000319
http://www.netendance.de


Reply via email to