line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sledge::Config::YAML; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
918
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
84
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
61
|
|
5
|
2
|
|
|
2
|
|
9
|
use base qw(Sledge::Config); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
675
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1714
|
use YAML::Syck; |
|
2
|
|
|
|
|
5153
|
|
|
2
|
|
|
|
|
127
|
|
10
|
2
|
|
|
2
|
|
1749
|
use File::Slurp; |
|
2
|
|
|
|
|
40082
|
|
|
2
|
|
|
|
|
1046
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
14
|
0
|
|
|
|
|
|
my $config_name = shift; |
15
|
0
|
|
|
|
|
|
my $config_file = shift; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $config_base; |
18
|
0
|
0
|
|
|
|
|
if ($config_name =~ /^([^_]+)_/) { |
19
|
0
|
|
|
|
|
|
$config_base = $1; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $config_data = read_file($config_file); |
23
|
0
|
0
|
|
|
|
|
$config_data =~ s{__ENV:(.+?)__}{ $ENV{$1}||'' }ge; |
|
0
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $conf = $class->_load($config_data); |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my %config; |
27
|
0
|
0
|
|
|
|
|
if ($config_base) { |
28
|
0
|
|
|
|
|
|
%config = ( |
29
|
0
|
|
|
|
|
|
%{$conf->{common}}, |
30
|
0
|
|
|
|
|
|
%{$conf->{$config_base}}, |
31
|
0
|
0
|
|
|
|
|
$conf->{$config_name} ? %{$conf->{$config_name}} : (), |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
} else { |
34
|
0
|
|
|
|
|
|
%config = ( |
35
|
0
|
|
|
|
|
|
%{$conf->{common}}, |
36
|
0
|
0
|
|
|
|
|
$conf->{$config_name} ? %{$conf->{$config_name}} : (), |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# case sensitive hash |
41
|
0
|
0
|
|
|
|
|
%config = map { lc($_) => $config{$_} } keys %config |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
unless $class->case_sensitive; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
bless \%config, $class; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _load { |
48
|
0
|
|
|
0
|
|
|
my ($self, $config_data) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return YAML::Syck::Load( $config_data ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
__END__ |