PetaMem has asked for the wisdom of the Perl Monks concerning the following question:
I'm just re-factoring a project that uses Net::Server::PreFork and one of the ugly things in there is the use of hardcoded paths splattered all over the source. Yuck! I thought it would be a good idea to move them to the .conf file of Net::Server with some key, like so:
... root_html /srv/www/htdocs root_cgi /srv/www/cgi-bin ...
and then read them out by either $server->{server}->{root_html} or the respective $server->get_property('root_html') method call. Unfortunately, it seems as if Net::Server would not populate the config hash with key/value pairs he doesn't know, so everything I add to its config file is undefined/unknown.
I did some code browsing and it seems like Net::Server sets up some kind of template, which is cross-checked against the parameters given, and all unknown params are simply not touched. Although I do believe this might be a good idea for some purpose, it is quite frustrating for my purpose (centralize configuration).
The documentation wasn't very fruitful mentioning any of these "templates", so maybe some of you know how to do it. Perhaps I just oversaw something and contacting the author might be a blamage... ;-).
Thank you
Update: Got it working (after going round the houses). Basically I did some slightly more intelligent cargo cult programming after looking more closely at the inheritances of Net::Server. E.g. Net::Server::PreForkSimple, defines its own options method to add options for the package. I did exactly the same thing and came up with:Ok. Problem solved. I have to ask the author though why it has to be that complicated.sub options { my $self = shift; my $ref = shift; my $prop = $self->{server}; my @newo = qw(root_html root_cgi); # YOUR NEW OPTIONS HERE! $self->SUPER::options($ref); for (@newo){ $prop->{$_} = undef if(!exists $prop->{$_}); $ref->{$_} = \$prop->{$_}; } }
Bye
PetaMem All Perl: MT, NLP, NLU
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::Server config-file extension
by ghenry (Vicar) on May 26, 2005 at 10:20 UTC | |
by PetaMem (Priest) on May 26, 2005 at 10:34 UTC | |
by ghenry (Vicar) on May 26, 2005 at 10:49 UTC | |
|
Re: Net::Server config-file extension
by dragonchild (Archbishop) on May 26, 2005 at 13:56 UTC |