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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.