File Coverage

blib/lib/SRS/EPP/Proxy/SimpleConfig.pm
Criterion Covered Total %
statement 9 28 32.1
branch 0 10 0.0
condition 0 6 0.0
subroutine 3 5 60.0
pod n/a
total 12 49 24.4


line stmt bran cond sub pod time code
1             package SRS::EPP::Proxy::SimpleConfig;
2             {
3             $SRS::EPP::Proxy::SimpleConfig::VERSION = '0.22';
4             }
5              
6             # This package is a monkeypatch for MooseX::SimpleConfig, which;
7             # a) does not allow multiple filenames to be passed as the configfile
8             # b) requires that they *all* exist, or it blows up
9             # See rt.cpan.org#57027, apparently fixed in MooseX::SimpleConfig 0.07,
10             # but we still need this class here to pull in the
11             # MooseX::ConfigFromFile monkeypatch.
12              
13 1     1   3009 use Moose::Role;
  1         2  
  1         11  
14             with 'SRS::EPP::Proxy::ConfigFromFile';
15              
16 1     1   7818 use Config::Any ();
  1         11956  
  1         310  
17              
18             sub get_config_from_file {
19 0     0     my ($class, $file) = @_;
20              
21 0 0         my $files_ref = ref $file eq 'ARRAY' ? $file : [$file];
22              
23 0           my $can_config_any_args = $class->can('config_any_args');
24 0 0         my $extra_args = $can_config_any_args
25             ? $can_config_any_args->($class, $file)
26             : {};
27            
28             local $SIG{__WARN__} = sub {
29 0 0   0     return if $_[0] =~ /deprecated/i;
30 0           print STDERR @_;
31 0           };
32            
33 0           my $raw_cfany = Config::Any->load_files({
34             %$extra_args,
35             use_ext => 1,
36             files => $files_ref,
37             flatten_to_hash => 1,
38             }
39             );
40            
41 0           undef local $SIG{__WARN__};
42              
43 0           my %raw_config;
44 0           foreach my $file_tested ( reverse @{$files_ref} ) {
  0            
45 0 0         if ( !exists $raw_cfany->{$file_tested} ) {
46 0           next;
47             }
48              
49 0           my $cfany_hash = $raw_cfany->{$file_tested};
50 0 0 0       die "configfile must represent a hash structure in file: $file_tested"
      0        
51             unless $cfany_hash && ref $cfany_hash && ref $cfany_hash eq 'HASH';
52              
53 0           %raw_config = ( %raw_config, %{$cfany_hash} );
  0            
54             }
55              
56 0           \%raw_config;
57             }
58              
59 1     1   14 no Moose::Role;
  1         10  
  1         15  
60             1;
61