I wrote a custom config module. This module had a search path that it knew to follow of places that it could find configuration information. When you called that module's import method, it looked at caller to figure out the module being loaded and then search for the appropriate configuration files. For a module named Foo::Bar, it would look for files named Bar.pc in that path. Each would be read into RAM, a package command would be inserted, and then eval called. When it was done it would then look through the import request, and would export them to the caller's package if they were loaded, plus would tell strict.pm that they were now OK. If they were not loaded I would die a horrible flaming death. To figure that out use the *foo{THING} syntax described in perlref. You'll need to require that all scalars must be defined.
The configuration path had a directory for good development defaults, a directory with as little as possible in it for overrides for production (presumably you'd want another for testing overrides), and a directory outside of source control for per developer overrides.
Together with a script to load the full configuration and then dump it in various formats, this should meet your needs.
Another solution that I've used is to build up a hash of different configurations for different situations where the configurations are built up from each other. Then require people to use special access functions for their configuration data. There are cases where this is more flexible than the other, and cases where the other is more flexible than this. On the whole I think I preferred the first approach - actually having variables exported into your namespace is a nice convenience touch.
But it seems that everyone has different desires for a configuration module. Which is one reason why there are so many configuration modules on CPAN, most of which are worse for my desires than raw Perl. Figure out what you want and pick a configuration solution that makes sense.
But, absolutely, you must settle on one. Even if it is a configuration solution that you dislike, a mediocre solution used consistently is better than several much better solutions competing with each other in the same code.
In reply to Re: Handling configuration for mutliple modules
by tilly
in thread Handling configuration for multiple modules
by jhourcle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |