line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tapper::Config; |
2
|
|
|
|
|
|
|
# git description: v4.1.2-2-g394d7ec |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
BEGIN { |
5
|
3
|
|
|
3
|
|
93632
|
$Tapper::Config::AUTHORITY = 'cpan:TAPPER'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
{ |
8
|
|
|
|
|
|
|
$Tapper::Config::VERSION = '4.1.3'; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
# ABSTRACT: Tapper - Context sensitive configuration hub for all Tapper libs |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
76
|
use 5.010; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
239
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
130
|
|
15
|
3
|
|
|
3
|
|
29
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
107
|
|
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
3003
|
use YAML::Syck; |
|
3
|
|
|
|
|
9113
|
|
|
3
|
|
|
|
|
408
|
|
18
|
3
|
|
|
3
|
|
4033
|
use File::Slurp 'slurp'; |
|
3
|
|
|
|
|
48908
|
|
|
3
|
|
|
|
|
220
|
|
19
|
3
|
|
|
3
|
|
4075
|
use File::ShareDir 'module_file'; |
|
3
|
|
|
|
|
23153
|
|
|
3
|
|
|
|
|
249
|
|
20
|
3
|
|
|
3
|
|
2561
|
use Hash::Merge::Simple 'merge'; |
|
3
|
|
|
|
|
1401
|
|
|
3
|
|
|
|
|
175
|
|
21
|
3
|
|
|
3
|
|
487
|
use File::ShareDir 'module_file'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
185
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# --- The configuration file is lib/auto/Tapper/Config/tapper.yml --- |
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
# closure to forbid direct access to the config hash |
27
|
|
|
|
|
|
|
my $Config; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub default_merge |
32
|
|
|
|
|
|
|
{ |
33
|
18
|
|
|
18
|
1
|
32
|
my ($config) = @_; |
34
|
|
|
|
|
|
|
|
35
|
3
|
|
|
3
|
|
14
|
no warnings 'uninitialized'; # $ENV{HOME} can be undef |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1800
|
|
36
|
|
|
|
|
|
|
|
37
|
18
|
|
100
|
|
|
95
|
my $env_config_file = $ENV{TAPPER_CONFIG_FILE} || ""; |
38
|
18
|
|
|
|
|
57
|
my $user_config_file = "$ENV{HOME}/.tapper/tapper.cfg"; |
39
|
18
|
|
|
|
|
76
|
my $global_config_file = "/etc/tapper.cfg"; |
40
|
|
|
|
|
|
|
|
41
|
18
|
|
|
|
|
24
|
my $new_config; |
42
|
|
|
|
|
|
|
my $new_config_file; |
43
|
|
|
|
|
|
|
|
44
|
18
|
50
|
33
|
|
|
133
|
$new_config_file = |
|
|
50
|
33
|
|
|
|
|
|
|
100
|
|
|
|
|
|
45
|
|
|
|
|
|
|
(exists $ENV{TAPPER_CONFIG_FILE}) ? $env_config_file |
46
|
|
|
|
|
|
|
: (-e $user_config_file && !$ENV{HARNESS_ACTIVE}) ? $user_config_file |
47
|
|
|
|
|
|
|
: (-e $global_config_file && !$ENV{HARNESS_ACTIVE}) ? $global_config_file |
48
|
|
|
|
|
|
|
: undef; |
49
|
|
|
|
|
|
|
|
50
|
18
|
100
|
|
|
|
46
|
if ($new_config_file) { |
51
|
16
|
|
|
|
|
24
|
eval { $new_config = LoadFile($new_config_file) }; |
|
16
|
|
|
|
|
50
|
|
52
|
16
|
50
|
|
|
|
19380
|
die "Can not load config file '$new_config_file': $@\n" if $@; |
53
|
16
|
|
|
|
|
69
|
$config = merge($config, $new_config); |
54
|
|
|
|
|
|
|
} |
55
|
18
|
|
|
|
|
35090
|
return $config; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _getenv |
59
|
|
|
|
|
|
|
{ |
60
|
|
|
|
|
|
|
return |
61
|
30
|
100
|
|
30
|
|
199
|
$ENV{HARNESS_ACTIVE} ? 'test' |
|
|
100
|
|
|
|
|
|
62
|
|
|
|
|
|
|
: $ENV{TAPPER_DEVELOPMENT} ? 'development' |
63
|
|
|
|
|
|
|
: 'live'; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# TODO: automatically recognize context switch |
68
|
|
|
|
|
|
|
sub _switch_context |
69
|
|
|
|
|
|
|
{ |
70
|
18
|
50
|
66
|
18
|
|
14113
|
shift if @_ && $_[0] && $_[0] eq 'Tapper::Config'; # throw away class if called as method |
|
|
|
33
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
18
|
|
33
|
|
|
71
|
my $env = shift // _getenv(); |
73
|
|
|
|
|
|
|
|
74
|
18
|
50
|
|
|
|
95
|
return unless $env =~ /^test|live|development$/; |
75
|
|
|
|
|
|
|
|
76
|
18
|
|
|
|
|
65
|
my $yaml = slurp module_file('Tapper::Config', 'tapper.yml'); |
77
|
18
|
|
|
|
|
15329
|
$Config = Load($yaml); |
78
|
18
|
|
|
|
|
27249
|
$Config = default_merge($Config); |
79
|
|
|
|
|
|
|
|
80
|
18
|
|
|
|
|
645
|
$Config = merge( $Config, $Config->{$env} ); |
81
|
18
|
|
|
|
|
5958
|
$Config = _prepare_special_entries( $Config ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _prepare_special_entries { |
86
|
18
|
|
|
18
|
|
39
|
my ($Config) = @_; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Log4Perl: prepend sharedir path |
89
|
18
|
50
|
|
|
|
85
|
if (not $Config->{files}{log4perl_cfg} =~ m,^/,) { |
90
|
18
|
|
|
|
|
82
|
$Config->{files}{log4perl_cfg} = module_file('Tapper::Config', $Config->{files}{log4perl_cfg}); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# DB config can be overridden triggered by env var |
94
|
18
|
|
|
|
|
9912
|
my $dbms = $ENV{TAPPERDBMS}; |
95
|
18
|
100
|
66
|
|
|
108
|
if ($dbms and _getenv ne 'test') { |
96
|
12
|
50
|
|
|
|
50
|
if ($dbms =~ m/^mysql|postgresql$/) { |
97
|
12
|
|
|
|
|
30
|
foreach (qw(TestrunDB ReportsDB HardwareDB)) { |
98
|
36
|
|
|
|
|
85
|
my $val = $Config->{database}{by_TAPPERDBMS}{$dbms}{$_}; |
99
|
36
|
50
|
|
|
|
153
|
$Config->{database}{$_} = $val if defined $val; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} else { |
102
|
0
|
|
|
|
|
0
|
die 'Unsupported Tapper DBMS $TAPPERDBMS='.$ENV{TAPPERDBMS}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
18
|
|
|
|
|
208
|
return $Config; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
38
|
|
|
38
|
1
|
1386
|
sub subconfig { $Config } |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
3
|
|
|
3
|
|
8
|
BEGIN { _switch_context() } |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |