lib/Serge/Config/Collector.pm

filter: Statementstmt 46.7% 43 / 92 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 63.6% 14 / 22 Podpod 0.0% 0 / 7 totaltotal 43.5% 57 / 131 SCAR 32.1
CC
9
Cov
42%
gather_config_files
20.0
gather_config_from_path
12.0
parse_configs
12.0
CRAP 24.7
« lib/Serge/Plugin/Base/Callback.pm ↑ Summary lib/Serge/Engine/Plugin/Transform/case.pm »
1 package Serge::Config::Collector;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Spec::Functions qw(rel2abs catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Serge::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Serge::FindFiles;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Serge::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub new {
13 0 ▶ my ($class, @paths) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
14  
15 0 my $self = {
16 config_lookup_paths => \@paths,
17 config_files => {}
18 };
19  
20 0 bless $self, $class;
21  
22 0 $self->gather_config_files;
23 0 $self->parse_configs;
24  
25 0 return $self;
26 }
27  
28 sub gather_config_files {
29 0 ▶ my ($self) = @_;
Subroutine gather_config_files: not called CC=4 SCAR=30.0
Pod undocumented
30  
31 0 $self->{config_files} = {};
32  
33 0 my $has_params;
34  
35 0 foreach (@{$self->{config_lookup_paths}}) {
36 # if @ARGV is passed, we need to filter out
37 # command-line parameters that start with '--'
38 0 ▶ if ($_ !~ m/^--/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ =~ /^--/) 0 0 0
39 0 $has_params = 1;
40 0 $self->gather_config_from_path($_); # not recursively
41 }
42 }
43  
44 0 ▶ if (!$has_params) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $has_params) 0 0 0
45 0 $self->gather_config_from_path(getcwd); # not recursively
46 }
47 }
48  
49 sub gather_config_from_path {
50 0 ▶ my ($self, $path, $recursively) = @_;
Subroutine gather_config_from_path: not called CC=3 SCAR=24.8
Pod undocumented
51  
52 0 $path = rel2abs($path);
53  
54 0 ▶ if (-f $path) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $path) { } 0 0 0
elsif (-d $path) { } 0 0 0
55 0 $self->{config_files}->{catfile($path)} = 1;
56 } elsif (-d $path) {
57 0 print "Scanning .serge files in '$path'...";
58 0 my $n = 0;
59  
60 my $ff = Serge::FindFiles->new({
61 match => ['\.serge$'],
62 process_subdirs => $recursively,
63 postcheck_callback => sub {
64 0 ▶ my ($file_rel, $fullpath) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 0 $n++;
66 0 $self->{config_files}->{$fullpath} = 1;
67 }
68 0 });
69 0 $ff->find($path);
70  
71 0 print " $n files found\n";
72 } else {
73 0 die "'$path' doesn't point to an existing file or directory";
74 }
75 }
76  
77 sub parse_configs {
78 0 ▶ my ($self) = @_;
Subroutine parse_configs: not called CC=3 SCAR=24.8
Pod undocumented
79  
80 0 foreach my $config_file (keys %{$self->{config_files}}) {
81 0 eval {
82 0 $self->{config_files}->{$config_file} = Serge::Config->new($config_file);
83 };
84 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
85 0 die "Exception in configuration file '$config_file': $@\n";
86 }
87 }
88 }
89  
90 sub get_config_files {
91 0 ▶ my ($self) = @_;
Subroutine get_config_files: not called CC=1 SCAR=6.9
Pod undocumented
92 0 return sort keys %{$self->{config_files}};
93 }
94  
95 sub get_config_object {
96 0 ▶ my ($self, $config_file) = @_;
Subroutine get_config_object: not called CC=1 SCAR=6.9
Pod undocumented
97 0 return $self->{config_files}->{$config_file};
98 }
99  
100 sub get_db_sources {
101 0 ▶ my ($self) = @_;
Subroutine get_db_sources: not called CC=2 SCAR=17.9
Pod undocumented
102  
103 0 my %db_sources;
104 my @res;
105  
106 0 foreach my $config_file (keys %{$self->{config_files}}) {
107 0 my $cfg = $self->get_config_object($config_file);
108 0 my $cfg_db_sources = $cfg->get_db_sources;
109 0 @db_sources{keys %$cfg_db_sources} = values %$cfg_db_sources;
110 }
111  
112 0 return \%db_sources;
113 }
114  
115 1 1;
« lib/Serge/Plugin/Base/Callback.pm ↑ Summary lib/Serge/Engine/Plugin/Transform/case.pm »