hesco has asked for the wisdom of the Perl Monks concerning the following question:

I seem to be writing more and more web apps. I've been rolling my own configuration parsers, including ones which parse the url to determine how a script was called and then use that to choose an appropriate config file (sort of like the Apache2 server or a drupal instance finds its configuration files). In this way, I can host multiple instances of a script, while maintaining and upgrading only a single install of the code.

I've been searching cpan for configuration modules to supplant my hand-rolled beauties. But with some 2200 to look through, I haven't yet found the one that seems to fit my needs, including parsing the url and using that to choose the config file.

Here is the code which does the work for an application I wrote:

sub parse_config_directory { my($url)=@_; my $conf = $url; my $scriptpath = $0; my $scriptname = $0; $scriptname =~ s/^(.*)\///; $scriptpath =~ s/$scriptname//; $conf =~ s/https:\/\///; $conf =~ s/http:\/\///; $conf =~ s/\//./g; $conf =~ s/\.$scriptname//; $conf = $scriptpath."conf.d/".$conf."/MyApp.conf"; return $conf; } # END parse_url
I trust that might give a better idea of what I'm talking about that perhaps my prose does.

Can anyone here recommend something that would fill this bill, or do I need to build and contribute back a Config::Simple::VirtualHost? Maybe that is not quite the name for what I'm talking about, perhaps. Surely I'm not the first person to reach for this. Am I?

-- Hugh

Replies are listed 'Best First'.
Re: Is there such an animal as Config::Simple::VirtualHost?
by philcrow (Priest) on Apr 25, 2006 at 13:30 UTC
    As I said yesterday Re: Config File Shuffle, Gantry::Conf is my current favorite (but that may be because it came from our shop and I had a hand in writing it).

    We use it more and more in web apps to share and separate conf across apps and to share conf between the apache served part of the app and the cronned scripts.

    All you have to do is figure out which instance you want, tell Gantry::Conf to retrieve that and it figures out what conf you need. It should be relatively easy to write a little url to instance mapper for your case.

    Once it knows the instance, it gives you your conf. That includes sharing with others and having your own. The conf can come from files on the local machine or https requests to a centralized conf server, so apps on different boxes can still share (but then you still need a separate index file on each box). You can even add backends to fish from other sources, like sql databases or LDAP.

    Phil