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."