blib/lib/ASP4/ConfigLoader.pm

filter: Statementstmt 100% 32 / 32 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 93.8% 46 / 49 CC 4 SCAR 7.9
CC
4
Cov
95%
load
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.2
« blib/lib/ASP4/HTTPHandler.pm ↑ Summary blib/lib/ASP4/ConfigPostProcessor.pm »
1  
2 package ASP4::ConfigLoader;
3  
4 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use ASP4::ConfigFinder;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use ASP4::ConfigParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 15 our $Configs = { };
12  
13  
14 #==============================================================================
15 sub load
16 31020 ▶{
Subroutine load: called CC=4 SCAR=13.9
Pod documented
17 31020 my ($s) = @_;
18
19 31020 my $path = ASP4::ConfigFinder->config_path;
20 31020 my $file_time = (stat($path))[7];
21 31020 ▶ if( exists($Configs->{$path}) && ( $file_time <= $Configs->{$path}->{timestamp} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ASP4::ConfigLoader::Configs->{$path} and $file_time <= $ASP4::ConfigLoader::Configs->{$path}{"timestamp"}) 31005 15 31020
Condition66%2/3
exists $ASP4::ConfigLoader::Configs->{$path} and $file_time <= $ASP4::ConfigLoader::Configs->{$path}{"timestamp"}
!ll&&!rl&&r
15031005
MC/DC50%1/2
exists $ASP4::ConfigLoader::Configs->{$path} and $file_time <= $ASP4::ConfigLoader::Configs->{$path}{"timestamp"}
exists $ASP4::ConfigLoader::Configs->{$path} $file_time <= $ASP4::ConfigLoader::Configs->{$path}{"timestamp"}
Truth table66%2/3
A and B
A= exists $ASP4::ConfigLoader::Configs->{$path}B= $file_time <= $ASP4::ConfigLoader::Configs->{$path}{"timestamp"}
ABresult
0X0
100
111
22 {
23 31005 return $Configs->{$path}->{data};
24 }# end if()
25
26 15 ▶ open my $ifh, '<', $path
Branch: 1 branch
BranchTrueFalseTotal
open my $ifh, "<", $path or die "Cannot open '${path}' for reading: $!" 15 0 15
27 or die "Cannot open '$path' for reading: $!";
28 15 local $/;
29 15 my $doc = decode_json( scalar(<$ifh>) );
30 15 close($ifh);
31
32 15 (my $where = $path) =~ s/\/conf\/[^\/]+$//;
33 15 $Configs->{$path} = {
34 data => ASP4::ConfigParser->new->parse( $doc, $where ),
35 timestamp => $file_time,
36 };
37 15 return $Configs->{$path}->{data};
38 }# end parse()
39  
40 15 1;# return true:
41  
42 __END__
« blib/lib/ASP4/HTTPHandler.pm ↑ Summary blib/lib/ASP4/ConfigPostProcessor.pm »