I recently had a job of moving a slew of related web components to several different enviroments. Most of the many configuration settings were in a common Cfg module.
I found it a huge pain when going back and forth between machines adjusting settings. Now I know I could just seperate this off into any number of configuration files but then it's one more thing to keep track of.
The solution I came up with for this particular instance was to write a Config module that has default settings with help and other features and stores current settings under the __DATA__ handle. The nice thing about this is that I can fool around with %INC during installation and get the current installation settings.
The module is required and when a special sub is called, it looks in the caller's package for a hash %CONFIG_VARS. When the user first installs or configuration info is missing, it runs a config sub which prompts the user to set up the module, giving them the option to use the current install setting (if previously installed) the default, or enter a new setting (This is eval'ed in a safe compartment.)
If the user accepts that configuration, the __DATA__ token is overwritten. It also will create directories with the proper ownership and permissions as neccassary.
I'm thinking of cleaning it up a bit and throwing it on CPAN. I'm wondering if anyone has opinions on this approach. I know for many apps, this wouldn't be the way to go but for modules that need machine/user specific info, it works well for me. I like the fact it's pure perl and the ability to retain settings easily across installs without adding foreign dependencies. Setup looks something like this.
package My::Module;
require Module::DATA::Cfg;
%CONFIG_VARS = (
'$SOMEVAR' => {sort=>1, default=>'Default setting',help=>'This conta
+ins some value'},
...
);
Module::DATA::Cfg->config_vars;
__DATA__
$SOMEVAR = 'Local install value'
How does everyone else handle this problem? In the past I've modified makefiles to prompt and replace values in source but this is a big headache. Is there some obvious solution that I'm missing?
-Lee
"To be civilized is to deny one's nature."
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.