line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Divide; |
2
|
7
|
|
|
7
|
|
51928
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
551
|
|
3
|
7
|
|
|
7
|
|
35
|
use warnings; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
206
|
|
4
|
|
|
|
|
|
|
|
5
|
7
|
|
|
7
|
|
33
|
use Carp; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
867
|
|
6
|
7
|
|
|
7
|
|
7016
|
use Config::Any; |
|
7
|
|
|
|
|
136415
|
|
|
7
|
|
|
|
|
261
|
|
7
|
7
|
|
|
7
|
|
79
|
use File::Spec; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
3525
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.036'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub get_config_files { |
12
|
25
|
|
|
25
|
0
|
53
|
my ($class, $config_path) = @_; |
13
|
25
|
50
|
|
|
|
81
|
return if !$config_path; |
14
|
|
|
|
|
|
|
|
15
|
25
|
|
|
|
|
914
|
$config_path = File::Spec->rel2abs($config_path); |
16
|
25
|
|
|
|
|
45
|
my @config_files; |
17
|
|
|
|
|
|
|
|
18
|
25
|
50
|
|
|
|
1613
|
opendir my $dh, $config_path or die "$config_path : $!"; |
19
|
25
|
|
|
|
|
508
|
for my $file (grep !/^\.\.?/, readdir($dh)) { |
20
|
50
|
|
|
|
|
118
|
$file = "$config_path/$file"; |
21
|
50
|
50
|
|
|
|
1345
|
next if -z $file; |
22
|
50
|
|
|
|
|
133
|
push @config_files, $file; |
23
|
|
|
|
|
|
|
} |
24
|
25
|
|
|
|
|
332
|
closedir $dh; |
25
|
|
|
|
|
|
|
|
26
|
25
|
|
|
|
|
173
|
@config_files; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub load_config { |
30
|
18
|
|
|
18
|
1
|
55044
|
my $class = shift; |
31
|
18
|
|
|
|
|
43
|
my %opt; |
32
|
|
|
|
|
|
|
|
33
|
18
|
100
|
|
|
|
106
|
if (ref $_[0] eq 'ARRAY') { |
|
|
100
|
|
|
|
|
|
34
|
9
|
|
|
|
|
42
|
%opt = (config_paths => $_[0], config_any_options => $_[1]); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
elsif (ref $_[0] eq 'HASH') { |
37
|
8
|
|
|
|
|
15
|
%opt = %{ $_[0] }; |
|
8
|
|
|
|
|
31
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
1
|
|
|
|
|
32
|
croak 'invalid args'; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
17
|
|
|
|
|
33
|
my (@config_files, @config_paths); |
44
|
17
|
|
|
|
|
115
|
push @config_files, $class->get_config_files($_) |
45
|
17
|
|
|
|
|
29
|
for @{$opt{config_paths}}; |
46
|
|
|
|
|
|
|
|
47
|
17
|
|
|
|
|
60
|
my %config_any_options = ( |
48
|
|
|
|
|
|
|
use_ext => 1, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
17
|
50
|
|
|
|
58
|
%config_any_options = (%config_any_options, %{$opt{config_any_options}}) |
|
0
|
|
|
|
|
0
|
|
52
|
|
|
|
|
|
|
if $opt{config_any_options}; |
53
|
|
|
|
|
|
|
|
54
|
17
|
|
|
|
|
188
|
my $config = Config::Any->load_files( |
55
|
|
|
|
|
|
|
{ |
56
|
|
|
|
|
|
|
files => \@config_files, |
57
|
|
|
|
|
|
|
%config_any_options, |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
13
|
|
|
|
|
586264
|
my %_config = map { %$_ } @$config; |
|
38
|
|
|
|
|
143
|
|
62
|
|
|
|
|
|
|
|
63
|
13
|
|
|
|
|
32
|
my %merged; |
64
|
13
|
|
|
|
|
37
|
for my $key (@config_files) { |
65
|
38
|
50
|
|
|
|
132
|
next if !$_config{$key}; |
66
|
38
|
|
|
|
|
85
|
%merged = (%merged, %{$_config{$key}}); |
|
38
|
|
|
|
|
359
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
13
|
|
|
|
|
273
|
\%merged; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |