line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tapper::Config; |
2
|
|
|
|
|
|
|
# git description: v5.0.3-1-g35a4479 |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Tapper - Context sensitive configuration hub for all Tapper libs |
6
|
|
|
|
|
|
|
$Tapper::Config::VERSION = '5.0.4'; |
7
|
3
|
|
|
3
|
|
189368
|
use 5.010; |
|
3
|
|
|
|
|
29
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
58
|
|
10
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
107
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
1318
|
use YAML::Syck; |
|
3
|
|
|
|
|
5850
|
|
|
3
|
|
|
|
|
177
|
|
13
|
3
|
|
|
3
|
|
1493
|
use File::Slurp 'slurp'; |
|
3
|
|
|
|
|
40681
|
|
|
3
|
|
|
|
|
187
|
|
14
|
3
|
|
|
3
|
|
1405
|
use File::ShareDir 'module_file'; |
|
3
|
|
|
|
|
75538
|
|
|
3
|
|
|
|
|
184
|
|
15
|
3
|
|
|
3
|
|
1307
|
use Hash::Merge 'merge'; |
|
3
|
|
|
|
|
30469
|
|
|
3
|
|
|
|
|
173
|
|
16
|
3
|
|
|
3
|
|
22
|
use File::ShareDir 'module_file'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
200
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# --- The configuration file is lib/auto/Tapper/Config/tapper.yml --- |
20
|
|
|
|
|
|
|
{ |
21
|
|
|
|
|
|
|
# closure to forbid direct access to the config hash |
22
|
|
|
|
|
|
|
my $Config; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub default_merge |
27
|
|
|
|
|
|
|
{ |
28
|
10
|
|
|
10
|
1
|
27
|
my ($config) = @_; |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
|
3
|
|
22
|
no warnings 'uninitialized'; # $ENV{HOME} can be undef |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1703
|
|
31
|
|
|
|
|
|
|
|
32
|
10
|
50
|
|
|
|
67
|
foreach my $filename ("/etc/tapper.cfg", |
33
|
|
|
|
|
|
|
$ENV{HOME} ? "$ENV{HOME}/.tapper/tapper.cfg" : '', |
34
|
|
|
|
|
|
|
"$ENV{TAPPER_CONFIG_FILE}", |
35
|
|
|
|
|
|
|
) |
36
|
|
|
|
|
|
|
{ |
37
|
30
|
100
|
|
|
|
405
|
if (-e $filename) { |
38
|
8
|
|
|
|
|
17
|
my $new_config; |
39
|
8
|
|
|
|
|
15
|
eval { $new_config = LoadFile($filename) }; |
|
8
|
|
|
|
|
26
|
|
40
|
8
|
50
|
|
|
|
5456
|
die "Can not load config file '$filename': $@\n" if $@; |
41
|
8
|
|
|
|
|
37
|
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
42
|
8
|
|
|
|
|
407
|
$config = merge($config, $new_config); |
43
|
8
|
|
|
|
|
47911
|
$config->{_last_used_tapper_config_file} = $filename; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
10
|
|
|
|
|
181
|
return $config; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _getenv |
50
|
|
|
|
|
|
|
{ |
51
|
|
|
|
|
|
|
return |
52
|
|
|
|
|
|
|
$ENV{HARNESS_ACTIVE} ? 'test' |
53
|
14
|
100
|
|
14
|
|
85
|
: $ENV{TAPPER_DEVELOPMENT} ? 'development' |
|
|
100
|
|
|
|
|
|
54
|
|
|
|
|
|
|
: 'live'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# TODO: automatically recognize context switch |
59
|
|
|
|
|
|
|
sub _switch_context |
60
|
|
|
|
|
|
|
{ |
61
|
10
|
50
|
66
|
10
|
|
4796
|
shift if @_ && $_[0] && $_[0] eq 'Tapper::Config'; # throw away class if called as method |
|
|
|
33
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
10
|
|
33
|
|
|
37
|
my $env = shift // _getenv(); |
64
|
|
|
|
|
|
|
|
65
|
10
|
50
|
|
|
|
65
|
return unless $env =~ /^test|live|development$/; |
66
|
|
|
|
|
|
|
|
67
|
10
|
|
|
|
|
85
|
my $yaml = slurp module_file('Tapper::Config', 'tapper.yml'); |
68
|
10
|
|
|
|
|
6177
|
$Config = Load($yaml); |
69
|
10
|
|
|
|
|
7249
|
$Config = default_merge($Config); |
70
|
|
|
|
|
|
|
|
71
|
10
|
|
|
|
|
39
|
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
72
|
10
|
|
|
|
|
585
|
$Config = merge( $Config, $Config->{$env} ); |
73
|
10
|
|
|
|
|
12229
|
$Config = _prepare_special_entries( $Config ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _prepare_special_entries { |
78
|
10
|
|
|
10
|
|
32
|
my ($Config) = @_; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Log4Perl: prepend sharedir path |
81
|
10
|
50
|
|
|
|
93
|
if (not $Config->{files}{log4perl_cfg} =~ m,^/,) { |
82
|
10
|
|
|
|
|
39
|
$Config->{files}{log4perl_cfg} = module_file('Tapper::Config', $Config->{files}{log4perl_cfg}); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# DB config can be overridden triggered by env var |
86
|
10
|
|
|
|
|
4722
|
my $dbms = $ENV{TAPPERDBMS}; |
87
|
10
|
100
|
66
|
|
|
43
|
if ($dbms and _getenv ne 'test') { |
88
|
4
|
50
|
|
|
|
16
|
if ($dbms =~ m/^mysql|postgresql$/) { |
89
|
4
|
|
|
|
|
11
|
my $val = $Config->{database}{by_TAPPERDBMS}{$dbms}{TestrunDB}; |
90
|
4
|
50
|
|
|
|
16
|
$Config->{database}{TestrunDB} = $val if defined $val; |
91
|
|
|
|
|
|
|
} else { |
92
|
0
|
|
|
|
|
0
|
die 'Unsupported Tapper DBMS $TAPPERDBMS='.$ENV{TAPPERDBMS}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
10
|
|
|
|
|
129
|
return $Config; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
20
|
|
|
20
|
1
|
320
|
sub subconfig { $Config } |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
3
|
|
|
3
|
|
24
|
BEGIN { _switch_context() } |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |