Config::Multi - load multiple config files.
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;
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.
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
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.
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.
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)
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.
constructor SEE CONSTRUCTOR ARGUMENT section.
load config files and return config data.
get array references of loaded config files. You can use this method after call load() method.
your application name. use [a-z]+ for format.
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. )
specify directory where your config files are located.
you must specify extension for your config files. default is yml.
Config::Any
Tomohiro Teranishi <tomohiro.teranishi@gmail.com>
vkgtaro
This module is copyright 2008 Tomohiro Teranishi.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Config::Multi, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Config::Multi
CPAN shell
perl -MCPAN -e shell install Config::Multi
For more information on module installation, please visit the detailed CPAN module installation guide.