Subject: | Allowing multiple configuration files |
I love MooseX::SimpleConfig. Unfortunately it doesn't support multiple
configuration files.
I included a patch that I wrote. I might have implemented different than
you would want, but I tried to keep it as true to the way you wrote it.
This patch should be accompanied with a patch to MooseX::ConfigFromFile,
that changes the attribute type to allow either a Path or an ArrayRef of
a Path.
I am opening another ticket with MooseX::ConfigFromFile and including a
patch for that as well.
Thank you.
Subject: | mx_simpleconfig-allow_multiple_configs.patch |
--- /usr/local/share/perl/5.8.8/MooseX/SimpleConfig.pm 2008-01-23 08:06:35.000000000 +0200
+++ lib/MooseX/SimpleConfig.pm 2009-07-20 10:50:42.000000000 +0300
@@ -10,22 +10,27 @@
sub get_config_from_file {
my ($class, $file) = @_;
+ my $files_ref = ref $file eq 'ARRAY' ?
+ $file :
+ [ $file ];
+
my $raw_cfany = Config::Any->load_files({
- files => [ $file ],
+ files => $files_ref,
use_ext => 1,
+ flatten_to_hash => 1,
});
- die q{Specified configfile '} . $file
- . q{' does not exist, is empty, or is not readable}
- unless $raw_cfany->[0]
- && exists $raw_cfany->[0]->{$file};
-
- my $raw_config = $raw_cfany->[0]->{$file};
+ my %raw_config;
+ foreach my $file_tested ( @{$files_ref} ) {
+ if ( ! exists $raw_cfany->{$file_tested} ) {
+ die qq{Specified configfile '$file_tested' does not exist, } .
+ q{is empty, or is not readable};
+ }
+ %raw_config = ( %raw_config, %{ $raw_cfany->{$file_tested} } );
+ }
- die "configfile must represent a hash structure"
- unless $raw_config && ref $raw_config && ref $raw_config eq 'HASH';
+ \%raw_config;
- $raw_config;
}
no Moose::Role; 1;