in reply to RFC: A YAML config module to be posted to CPAN
I have now released this config module as Config::Loader version 1.
Config::Loader reads in (and merges) a configuration directory tree, which can contain files with YAML, XML, JSON, INI, Perl and Config::General config data. (Thanks castaway for the pointer to Config::Any.)
(WARNING - I had a version 0.01 on CPAN from 2004 which worked very differently - look for version 1.00)
Individual keys in the real config data can be overwritten for a dev environment though one (or many) local.(yaml/json/ini/etc) file(s). See the examples/browser.pl
I've taken hossman's concerns into account by providing an OO interface in addition to the functional interface, and I've made it easier to use the functional style, so:
OROO style ------------------------------------------------------- use Config::Loader(); my $config = Config::Loader->new('/path/to/config'); @hosts = $config->('db.hosts.session'); -------------------------------------------------------
Functional style (auto generates your own config class) ------------------------------------------------------- # On startup use Config::Loader('My::Config' => '/path/to/config'); # Then, in any module where you want to use the config package My::Module; use My::Config; @hosts = C('db.hosts.sesssion'); -------------------------------------------------------
The config data can be accessed as a normal Perl variable, or for ease of reading, I provide a method for using Template Toolkit style notation, for instance:
OO style ------------------------------------------------------- @hosts = $config->('db.hosts.session'); $hosts_ref = $config->('db.hosts.session'); $host_2 = $config->('db.hosts.session.1'); @cloned_hosts = $config->clone('db.hosts.session'); # deep clones +the data -------------------------------------------------------
These lookups are memo'ised for speed.Functional style ------------------------------------------------------- @hosts = C('db.hosts.sesssion'); $hosts_ref = C('db.hosts.sesssion'); $host_2 = C('db.hosts.session.1'); @cloned_hosts = My::Config::clone('db.hosts.session'); # deep cl +ones the data $config = My::Config::object; # returns + the stored config object -------------------------------------------------------
I have used overload to make these two equivalent:
Is this overkill? How far back is overloading &{} supported?$config->C('db.hosts.session'); $config->('db.hosts.session');
thanks
clint
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RFC: A YAML config module to be posted to CPAN
by clinton (Priest) on Nov 07, 2007 at 12:41 UTC |