NAME
Config::Multi - load multiple config files.
SYNOPSIS
use Config::Multi;
use File::Spec;
use FindBin;
my $dir = File::Spec->catfile( $FindBin::Bin , 'conf' );
# prefix, extension and unicode is optional.
my $cm
= Config::Multi->new({
dir => $dir ,
app_name => 'myapp' ,
prefix => 'web' ,
extension => 'yml' ,
unicode => 1 # unicode option
});
my $config = $cm->load();
my $loaded_config_files = $cm->files;
DESCRIPTION
This module load multiple config files using Config::Any. You can specify directory and put into your config files!
I create this module because I want to load not only loading multiple config files but also switch config files depend on interface I am using. like, I want to load web.yml only for web interface configuration and cli.yml for only for client interface configuration. let me explain step by step at EXAMPLE section.
EXAMPLE
your configuration files
This is under your ~/myapp/conf/ and have yaml configuration in each files. you can specify the directory using dir option.
.
|-- env-prefix.yml
|-- env.yml
|-- myapp.yml
|-- myapp_boin.yml
|-- myapp_local.yml
|-- myapp_oppai.yml
|-- never_load.yml
|-- web_myapp.yml
|-- web_myapp_cat.yml
|-- web_myapp_dog.yml
`-- web_myapp_local.yml
switchable
when you set app_name as 'myapp' and prefix as 'jobqueue' then below files are loaded
|-- myapp.yml
|-- myapp_boin.yml
|-- myapp_local.yml
|-- myapp_oppai.yml
${app_name}.yml or ${app_name}_*.yml
when you set app_name as 'myapp' and prefix as 'web' then below files are loaded
|-- myapp.yml
|-- myapp_boin.yml
|-- myapp_local.yml
|-- myapp_oppai.yml
|-- web_myapp.yml
|-- web_myapp_cat.yml
|-- web_myapp_dog.yml
`-- web_myapp_local.yml
${prefix}_${myapp}.yml ${prefix}_${myapp}_*.yml
YES! you can switch config files depend on what you set for app_name and prefix.
overwrite rule.
there is also overwriting rule. there are three steps for this.
_local.yml file overwrite the other config setting
${prefix}_${app_name}_local.yml
${app_name}_local.yml
${prefix}_ files overwrite ${app_name} config setting
${app_name}.yml, ${app_name}_*.yml (not include ${app_name}_local.yml)
app config.
${prefix}_${myapp}.yml ${prefix}_${myapp}_*.yml
$ENV setting
instead of ${prefix}_${app_name}_local.yml , you can specify the path with $ENV{CONFIG_MULTI_PREFIX_MYAPP}
instead of ${app_name}_local.yml , you can specify the path with $ENV{CONFIG_MULTI_MYAPP}
note. PREFIX = uc($prefix); MYAPP = uc($app_name)
unicode option
if you set true to unicode option, return $config of flagged UTF-8. in the future, this option will also be posiible to default. at least I would hope so.
METHODS
new
constructor SEE CONSTRUCTOR ARGUMENT section.
load
load config files and return config data.
files
get array references of loaded config files. You can use this method after call load() method.
CONSTRUCTOR ARGUMENT
app_name
your application name. use [a-z]+ for format.
prefix
prefix name . use [a-z]+ for format. this is optional. if you did not set. only application config is loaded(include appname_local.yml if you have. )
dir
specify directory where your config files are located.
extension
you must specify extension for your config files. default is yml.
SEE ALSO
AUTHOR
Tomohiro Teranishi <tomohiro.teranishi@gmail.com>
THANKS
vkgtaro
COPYRIGHT
This module is copyright 2008 Tomohiro Teranishi.
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.