File Coverage

blib/lib/ASP4/ConfigLoader.pm
Criterion Covered Total %
statement 27 27 100.0
branch 3 4 75.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 38 39 97.4


line stmt bran cond sub pod time code
1              
2             package ASP4::ConfigLoader;
3              
4 9     9   41460 use strict;
  9         12  
  9         242  
5 9     9   32 use warnings 'all';
  9         12  
  9         285  
6 9     9   36 use Carp 'confess';
  9         7  
  9         605  
7 9     9   3012 use ASP4::ConfigFinder;
  9         14  
  9         238  
8 9     9   2829 use ASP4::ConfigParser;
  9         27  
  9         209  
9 9     9   5740 use JSON::XS ();
  9         53915  
  9         1620  
10              
11             our $Configs = { };
12              
13              
14             #==============================================================================
15             sub load
16             {
17 37117     37117 1 33001 my ($s) = @_;
18            
19 37117         74196 my $path = ASP4::ConfigFinder->config_path;
20 37117 100       210573 return $Configs->{$path} if $Configs->{$path};
21            
22 9 50       658 open my $ifh, '<', $path
23             or die "Cannot open '$path' for reading: $!";
24 9         63 local $/ = '';
25 9         1110 my $doc = JSON::XS->new->decode( scalar(<$ifh>) );
26 9         160 close($ifh);
27            
28 9         152 (my $where = $path) =~ s/\/conf\/[^\/]+$//;
29 9         131 return $Configs->{$path} = ASP4::ConfigParser->new->parse( $doc, $where );
30             }# end parse()
31              
32             1;# return true:
33              
34             __END__