Esteemed Monks,
We support some fairly complex web applications and lately we're running into some issues with our config infrastructure. I got some help recently when I asked What config info belongs where for web apps?; thanks to those who responded.
Now I'm trying to define a better config system, but I can't find any best practices or guidelines beyond simple config file processing.
Here are my needs:
- be able to load shared config info that is machine-specific but relevant across many apps (e.g., directory prefixes, current environment (dev, prod), current server name, etc.). Would like to be able to pass in a project name to allow some automatic customization of directory paths;
- be able to load app-specific info, and use variables from the shared info to do it (e.g., use a path from the shared info to tell me where to find my app-specific config file on a given system);
- load 'session scoped' info appropriately with a layer of abstraction so apps aren't directly using $ENV{REMOTE_USER}; I want a layer because depending on the auth system we use, the current username might be in REMOTE_USER or SOME_OTHER_ENV and I'd like to abstract that from direct use by apps.
- do all of this in a cgi and mod_perl safe way so we can have just one way to do it;
Here's a draft of a best practice (untested), with many questions:
### Shared config info -- "machine scope" ###
# A local module that loads the shared config info.
# Is there a way to pass in a project name in a 'use'
# that is mod_perl safe?
use My::LocalConfig qw(project_name);
### App-specific config info -- "machine scope" ###
# Assuming 'config_path' is a function exported by the LocalConfig mod
+ule.
# Or should it just set a variable?
# What sort of variable and where can it be set so it's ready when
# the require runs?
# Would a 'do' be better?
# Should the project_name be passed in here as a parameter?
require config_path . "/my_config.pl";
# Or should we use a Config module here?
# Do various config modules allow a function call when you set
# the path?
# Are there Config modules that allow some logic in them?
# We have several cases where we set
# variables differently based on dev, QA, or prod environments.
### Session config info -- "session scope" ###
# A module that just grabs relevant $ENV info and
# provides it via a method or methods.
use My::SessionConfig;
# then
my $session = My::SessionConfig->new();
my $current_userid = $session->current_user();
What are you doing for your config environment?
Do you have custom modules to handle all of this?
Once I nail down the best practice or a functioning system, I'd like to follow some of TheDamian's advice and hide a bunch of this to make it easier to use. But we've already been burned by some cleverness in our mod_perl environment, so I'll want to be careful.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|