[Hampshire] mod_perl, PerlSetVar and startup scripts

Top Page
Author: Andy Smith
Date:  
To: Hampshire
CC: 
Subject: [Hampshire] mod_perl, PerlSetVar and startup scripts

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x56f89100.hantslug.org.uk.16131': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Sat Nov 17 05:55:09 2007 GMT
gpg: using DSA key 2099B64CBF15490B
gpg: Can't check signature: No public key
Hi,

I'm attempting to write a mod_perl (registry) application and would
like to parse a config file once per (web) server startup. I want
to avoid hard coding the path to the config file in the startup
script.

So say for example my apache virtual server config looks a bit like
this:

    PerlSwitches -I/data/www-ssl/foohost/perl
    PerlSetVar foo_conf /data/www-ssl/foohost/foo.conf
    PerlPostConfigRequire /data/www-ssl/foohost/perl/startup.pl


and my /data/www-ssl/foohost/perl/startup.pl might be a bit like
this:

    use strict;
    use warnings;

    
    use CGI ();
    use Config::Auto;
    use vars qw($config);

    
    $Config::Auto::DisablePerl = 1;

    
    $config = Config::Auto::parse('/data/www-ssl/foohost/foo.conf');

    
    1;


Now, I want that '/data/www-ssl/foohost/foo.conf' to be replaced by
the value from the PerlSetVar, but I can't seem to read it. Is it
not possible to get access to these variables inside the startup
script?

The documentation says I should be able to do
$r->dir_config('foo_conf') to get it, but I don't see where I would
get $r from inside the startup script.

I see that the API module Apache2::ServerUtil also has a dir_config
function, so I tried doing:

        use Apache2::ServerUtil;
        use Data::Dumper;


        my $s = Apache2::ServerUtil->server;
        print STDERR Dumper($s->dir_config('foo_conf'));


but that just gets me an undef value.

I don't want to parse my config file on every single web hit. Is
there a way around this? Should I instead be checking if $config is
undef on every web hit and parsing the config file only if it is?

As you can probably tell, I'm not a web developer. :)

Cheers,
Andy