I always create a module to handle program configuration, and I always call it Program::RC
Then Program::RC has a method new that instantiates an object that reads the configuration from whereever it is stored (config file, à la windows INI file is pretty good, with permissions well set so as to protect sensitive data), database, LDAP directory, whatever.
The class offers a series of methods to access the different parts of the configuration file and give the variables values.
This approach has one added advantage, each time you instantiate a configuration object, the config file is read, so you can change the configuration and test it on the fly, not even a SIGHUP is needed.
An example:
use Foo::RC;
# prepare things
...
# now fork
if ( my $pid = fork() )
{
my $ret = process_request( @ data );
# ... other hooks, or whatever
}
else { ... }
sub process_request
{
# blah blah blah
my $rc = new Foo::RC;
my ($server_ip, $server_port,
$bind_dn, $bind_passwd) = $rc->get_ldap_server_data;
# ...
}
Each time the program has to process a request, it reads its configuration. Unless it's a huge config file, this is almost unnoticeable delay, and you can always memoize or create a cache for this system once it's production time (this is really useful to developing/debugging...)
good luck,
NB: as I usually use Net::Server to make these things, the fork code can be wrong, please forgive me...
-- our $Perl6 is Fantastic; |