Config-Multi
view release on metacpan or search on metacpan
Revision history for Config::Multi
0.12 2013-03-10T00:11:30+09:00
- avoided a worning of using uninitialized value.
thanks Siraiwa san for patch!
0.11 2009-10-09T12:36:39+09:00
- fixed 08-unicode-option-with-yaml-syck.t.
is_supported_yaml_syck() returned false, if not supported YAML::Syck.
0.10 2009-10-05T18:02:00+09:00
- remove Data::Visitor::Encode code and using Unicode::RecursiveDowngrade instead
because I do not want to have Any::Moose dependancy.
0.09 2009-09-20T17:44:52+09:00
- fixed bug, not die if $YAML::Syck::ImplicitUnicode is true.
0.08 2008-12-15/14:34
- not using Config::Any::YAML->is_supported for test.
0.07 2008-12-13/14:27
- no more dependecies YAML and YAML::Syck.
0.06 2008-11-07/15:03
- bug fix. add YAML at requires list of Makefile.PL
0.05 2008-09-11/21:00
- add unicode option. unicode => 1.
- fix bug. remove hard coded extension 'yml' , use $extension valiable instead.
0.04 2008-05-18/19:20
- add Config::Any arguments. use_ext => 1.
0.03 2008-05-17/23:07
- fix 00-load.t
- bug fix. 02-overwrite.t will pass all test now.
0.02 2008-05-17/21:53
MANIFEST This list of files
META.yml
README
t/00-load.t
t/01-loadling.t
t/02-overwrite.t
t/03-multi.t
t/04-env.t
t/05-no-prefix.t
t/06-extension.t
t/07-unicode-option.t
t/08-unicode-option-with-yaml-syck.t
t/boilerplate.t
t/conf/env-prefix.yml
t/conf/env.yml
t/conf/myapp.yml
t/conf/myapp_boin.yaml
t/conf/myapp_boin.yml
t/conf/myapp_local.yml
t/conf/myapp_oppai.yml
t/conf/never_load.yml
t/conf/unicode.yml
t/conf/unicode_hogera.yml
t/conf/web_myapp.yml
t/conf/web_myapp_cat.yml
t/conf/web_myapp_dog.yml
t/conf/web_myapp_local.yml
lib/Config/Multi.pm view on Meta::CPAN
use Config::Any;
use Unicode::RecursiveDowngrade;
use Encode;
use DirHandle;
use File::Spec;
use base qw/Class::Accessor/;
our $VERSION = '0.12';
__PACKAGE__->mk_accessors(qw/app_name prefix dir files extension unicode/);
sub load {
my $self = shift;
my @files = ();
$self->{extension} ||= 'yml';
croak('you must set dir') unless $self->{dir};
croak('you must set app_name') unless $self->{app_name};
my $config = {};
lib/Config/Multi.pm view on Meta::CPAN
push @files, $filename;
$local_config->{$filename} = $data;
}
for (@{$local_files} ) {
$config = { %{$config}, %{ $local_config->{$_} } };
}
$self->{files} = \@files;
if ( $self->unicode ) {
my $rd = Unicode::RecursiveDowngrade->new;
$rd->filter(sub { Encode::decode('utf8',shift) });
$config = $rd->downgrade($config);
}
return $config;
}
sub _local_files {
my $self = shift;
lib/Config/Multi.pm view on Meta::CPAN
Config::Multi - load multiple config files.
=head1 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;
=head1 DESCRIPTION
This module load multiple config files using L<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 interfa...
lib/Config/Multi.pm view on Meta::CPAN
${prefix}_${myapp}.yml ${prefix}_${myapp}_*.yml
=head2 $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)
=head2 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.
=head1 METHODS
=head2 new
constructor SEE CONSTRUCTOR ARGUMENT section.
=head2 load
t/07-unicode-option.t view on Meta::CPAN
plan tests => 1 * blocks;
}
else {
plan skip_all => 'YAML format not supported';
}
my $dir = File::Spec->catfile( $FindBin::Bin , 'conf' );
run {
my $block = shift;
my $cm = Config::Multi->new({dir => $dir, app_name => 'unicode', extension => 'yml', unicode => 1 });
my $config = $cm->load();
is_deeply( $block->expected, $config );
}
__END__
=== test
--- expected eval
{
hoge => 'ã»ã',
t/08-unicode-option-with-yaml-syck.t view on Meta::CPAN
else {
plan skip_all => 'YAML::Syck not supported';
}
my $dir = File::Spec->catfile( $FindBin::Bin , 'conf' );
run {
my $block = shift;
no warnings 'once';
local $YAML::Syck::ImplicitUnicode = 1;
my $cm = Config::Multi->new({dir => $dir, app_name => 'unicode', extension => 'yml', unicode => 1 });
my $config = $cm->load();
is_deeply( $block->expected, $config );
}
__END__
=== test
--- expected eval
{
hoge => 'ã»ã',
( run in 0.856 second using v1.01-cache-2.11-cpan-88abd93f124 )