Config::Locale - Load and merge locale-specific configuration files.
use Config::Locale; my $locale = Config::Locale->new( identity => ['db', '1', 'qa'], directory => '/path/to/configs/', ); my $config = $locale->config();
This module takes an identity array, determines the permutations of the identity using Algorithm::Loops, loads configuration files using Config::Any, and finally combines the configurations using Hash::Merge.
So, given this setup:
Config::Locale->new( identity => ['db', '1', 'qa'], suffix => '.yml', );
The following configuration files will be looked for (listed from least specific to most):
default.yml all.all.qa.yml all.1.all.yml all.1.qa.yml db.all.all.yml db.all.qa.yml db.1.all.yml db.1.qa.yml
For each file found the contents will be parsed and then merged together to produce the final configuration hash. The hashes will be merged so that the most specific configuration file will take precedence over the least specific files. So, in the example above, "db.1.qa.yml" values will overwrite values from "default.yml".
The identity that configuration files will be loaded for. In a typical hostname-basedc configuration setup this will be the be the parts of the hostname that declare the class, number, and cluster that the current host identifies itself as. But, this could be any list of values.
The directory to load configuration files from. Defaults to the current directory.
The wildcard string to use when constructing the configuration filenames. Defaults to "all". This may be explicitly set to undef wich will cause the wildcard string to not be added to the filenames at all.
The name of the configuration file that contains the default configuration. Defaults to "default". This may be explcitly set to undef which will cause the default configuration file to look just like all the other configuration files, just using the "wildcard" for all of the identity values.
The character that will be used to separate the identity keys in the configuration filenames. Defaults to ".".
An optional prefix that will be prepended to the configuration filenames.
An optional suffix that will be apended to the configuration filenames. Typically this will need to be used to specify the filename extension for the particular configuration format you are using, such as ".ini", ".yml", etc.
Contains the final configuration hash as merged from the hashes in "configs".
Contains an array of hashrefs, one hashref for each file in "stems" that exists.
Holds an array of arrays containing all possible premutations of the identity.
Aran Clary Deltac <firstname.lastname@example.org>
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.