http://qs321.pair.com?node_id=116116

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

This question springs from a recent conversation I had with btrott and his rather excellent STAMP script.

Imagine if you will a typical Apache box, it's got one shared CGI-BIN, or mod_perl folder that is shared by all the various virtual domains on the box. Each domain looks different, so I want to make the script look different too.

QUESTION how do you neatly configure the script for all the various domains?

You can ask CGI to give you the virtual host name, and then check to see if there is a configuration file for it, if not you read a default one. This is what I tried, see code below. It works okay, but you'll end up with a folder full of config files, one per script per host, which may get messy.

So my question is, how do you neatly write CGI/mod_Perl script so that they can be shared on a mass-hosting Apache box, and yet maintain their own look'n'feel (via config), and what have you.

my $server = "localhost"; # Default host my $domain = ".company.com"; # Default domain my $conf_loc = "/someplace"; # Where config files live $server = $q->virtual_host() if $q->virtual_host(); # Where are +we? $server .= $domain unless ($server =~ /[$domain]$/i); # Need a do +main? if ($server =~ /^([-\w\.]+)$/) { # clean it $server = lc($1); chdir $conf_loc or error($q, qq(Unable to locate configuration fol +der $conf_loc)); $CFG_FILE = $server . ".$CFG_FILE" if ($server && -R "$server.$CFG +_FILE"); # If there is a specific file then use it }

$CFG_FILE is what STAMP expects to use, and error is it's error handling routine.

This is an addition to STAMP, I used for ilustration purposes. STAMP is cool, get it your self from it's author.

As ever thanks in advance.