lib/Serge/Config.pm

filter: Statementstmt 69.8% 58 / 83 Branchbran 16.6% 2 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 16 / 20 Podpod 0.0% 0 / 5 totaltotal 63.3% 76 / 120 SCAR 27.1
CC
10
Cov
63%
get_db_sources
20.0
any_job_exists
12.0
any_language_exists
12.0
CRAP 15.0
« lib/Serge/Engine/Plugin/parse_android.pm ↑ Summary lib/Serge/Command.pm »
1 package Serge::Config;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶no warnings qw(redefine);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Config::Neat::Inheritable;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Config::Neat::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::Spec::Functions qw(rel2abs);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Serge::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 #
14 # Initialize object
15 #
16 sub new {
17 7 ▶ my ($class, $path) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
18  
19 7 ▶ die "path not provided" unless $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 0 7 7
20 7 $path = rel2abs($path);
21  
22 # Load config file
23 7 my $data;
24  
25 7 my $s = Config::Neat::Schema->new();
26 7 $s->load(dirname(__FILE__).'/config_schema.serge');
27  
28 7 my $c = Config::Neat::Inheritable->new();
29 7 $data = $c->parse_file($path);
30  
31 7 ▶ die "Config is not a hash\n" unless ref($data) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 7 7
32  
33 7 $s->validate($data);
34  
35 # Check config validity
36  
37 7 my $self = {
38 base_dir => dirname($path),
39 data => $data,
40 };
41 7 bless $self, $class;
42  
43 7 return $self;
44 }
45  
46 sub abspath {
47 0 ▶ my ($self, $path) = @_;
Subroutine abspath: not called CC=1 SCAR=6.9
48  
49 0 return Serge::Util::abspath($self->{base_dir}, $path);
50 }
51  
52 sub chdir {
53 7 ▶ my ($self) = @_;
Subroutine chdir: called CC=1 SCAR=0.0
Pod undocumented
54  
55 7 chdir($self->{base_dir});
56 }
57  
58 #
59 # Get database sources
60 #
61 sub get_db_sources {
62 0 ▶ my $self = shift;
Subroutine get_db_sources: not called CC=4 SCAR=30.0
Pod undocumented
63  
64 0 my %db_sources;
65  
66 0 for my $job (@{$self->{data}->{jobs}}) {
67 # skip configs that don't have the db_source defined
68 0 ▶ if (exists $job->{db_source}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $job->{"db_source"}) 0 0 0
69 0 my $value = {};
70 0 my $key = join("\001", map {$value->{$_} = subst_macros($job->{$_}); $job->{$_}} qw(db_source db_username db_password));
71 0 ▶ $db_sources{$key} = $value unless exists $db_sources{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $db_sources{$key} 0 0 0
72 }
73 }
74  
75 0 return \%db_sources;
76 }
77  
78 #
79 # Test if any job from the provided hash exists in the config
80 #
81 sub any_job_exists {
82 0 ▶ my ($self, $jobs) = @_;
Subroutine any_job_exists: not called CC=3 SCAR=24.8
Pod undocumented
83  
84 0 for my $job (@{$self->{data}->{jobs}}) {
85 0 ▶ return 1 if exists $jobs->{$job->{id}};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$jobs{$job->{"id"}} 0 0 0
86 }
87  
88 0 return undef;
89 }
90  
91 #
92 # Test if any language from the provided hash exists in the config
93 #
94 sub any_language_exists {
95 0 ▶ my ($self, $languages) = @_;
Subroutine any_language_exists: not called CC=3 SCAR=24.8
Pod undocumented
96  
97 0 for my $job (@{$self->{data}->{jobs}}) {
98 map {
99 0 ▶ return 1 if exists $languages->{$_}
Branch: 1 branch
BranchTrueFalseTotal
if exists $languages->{$_} 0 0 0
100 0 } @{$job->{destination_languages}};
101 }
102  
103 0 return undef;
104 }
105  
106 2 1;
« lib/Serge/Engine/Plugin/parse_android.pm ↑ Summary lib/Serge/Command.pm »