line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tapper::Config; |
2
|
|
|
|
|
|
|
# git description: v5.0.2-1-g2d181a9 |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Tapper - Context sensitive configuration hub for all Tapper libs |
6
|
|
|
|
|
|
|
$Tapper::Config::VERSION = '5.0.3'; |
7
|
3
|
|
|
3
|
|
76711
|
use 5.010; |
|
3
|
|
|
|
|
14
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
97
|
|
10
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
106
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
2153
|
use YAML::Syck; |
|
3
|
|
|
|
|
7929
|
|
|
3
|
|
|
|
|
267
|
|
13
|
3
|
|
|
3
|
|
2536
|
use File::Slurp 'slurp'; |
|
3
|
|
|
|
|
71485
|
|
|
3
|
|
|
|
|
389
|
|
14
|
3
|
|
|
3
|
|
2798
|
use File::ShareDir 'module_file'; |
|
3
|
|
|
|
|
30087
|
|
|
3
|
|
|
|
|
429
|
|
15
|
3
|
|
|
3
|
|
3201
|
use Hash::Merge 'merge'; |
|
3
|
|
|
|
|
11003
|
|
|
3
|
|
|
|
|
322
|
|
16
|
3
|
|
|
3
|
|
29
|
use File::ShareDir 'module_file'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
276
|
|
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
|
26
|
my ($config) = @_; |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
|
3
|
|
22
|
no warnings 'uninitialized'; # $ENV{HOME} can be undef |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
2281
|
|
31
|
|
|
|
|
|
|
|
32
|
10
|
50
|
|
|
|
94
|
foreach my $filename ("/etc/tapper.cfg", |
33
|
|
|
|
|
|
|
$ENV{HOME} ? "$ENV{HOME}/.tapper/tapper.cfg" : '', |
34
|
|
|
|
|
|
|
"$ENV{TAPPER_CONFIG_FILE}", |
35
|
|
|
|
|
|
|
) |
36
|
|
|
|
|
|
|
{ |
37
|
30
|
100
|
|
|
|
576
|
if (-e $filename) { |
38
|
8
|
|
|
|
|
14
|
my $new_config; |
39
|
8
|
|
|
|
|
14
|
eval { $new_config = LoadFile($filename) }; |
|
8
|
|
|
|
|
41
|
|
40
|
8
|
50
|
|
|
|
8343
|
die "Can not load config file '$filename': $@\n" if $@; |
41
|
8
|
|
|
|
|
43
|
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
42
|
8
|
|
|
|
|
181
|
$config = merge($config, $new_config); |
43
|
8
|
|
|
|
|
89305
|
$config->{_last_used_tapper_config_file} = $filename; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
10
|
|
|
|
|
38
|
return $config; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _getenv |
50
|
|
|
|
|
|
|
{ |
51
|
|
|
|
|
|
|
return |
52
|
|
|
|
|
|
|
$ENV{HARNESS_ACTIVE} ? 'test' |
53
|
14
|
100
|
|
14
|
|
122
|
: $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
|
|
7614
|
shift if @_ && $_[0] && $_[0] eq 'Tapper::Config'; # throw away class if called as method |
|
|
|
33
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
10
|
|
33
|
|
|
58
|
my $env = shift // _getenv(); |
64
|
|
|
|
|
|
|
|
65
|
10
|
50
|
|
|
|
82
|
return unless $env =~ /^test|live|development$/; |
66
|
|
|
|
|
|
|
|
67
|
10
|
|
|
|
|
43
|
my $yaml = slurp module_file('Tapper::Config', 'tapper.yml'); |
68
|
10
|
|
|
|
|
7255
|
$Config = Load($yaml); |
69
|
10
|
|
|
|
|
10981
|
$Config = default_merge($Config); |
70
|
|
|
|
|
|
|
|
71
|
10
|
|
|
|
|
372
|
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
72
|
10
|
|
|
|
|
200
|
$Config = merge( $Config, $Config->{$env} ); |
73
|
10
|
|
|
|
|
30310
|
$Config = _prepare_special_entries( $Config ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _prepare_special_entries { |
78
|
10
|
|
|
10
|
|
24
|
my ($Config) = @_; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Log4Perl: prepend sharedir path |
81
|
10
|
50
|
|
|
|
74
|
if (not $Config->{files}{log4perl_cfg} =~ m,^/,) { |
82
|
10
|
|
|
|
|
76
|
$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
|
|
|
|
|
6322
|
my $dbms = $ENV{TAPPERDBMS}; |
87
|
10
|
100
|
66
|
|
|
60
|
if ($dbms and _getenv ne 'test') { |
88
|
4
|
50
|
|
|
|
21
|
if ($dbms =~ m/^mysql|postgresql$/) { |
89
|
4
|
|
|
|
|
11
|
my $val = $Config->{database}{by_TAPPERDBMS}{$dbms}{TestrunDB}; |
90
|
4
|
50
|
|
|
|
19
|
$Config->{database}{TestrunDB} = $val if defined $val; |
91
|
|
|
|
|
|
|
} else { |
92
|
0
|
|
|
|
|
0
|
die 'Unsupported Tapper DBMS $TAPPERDBMS='.$ENV{TAPPERDBMS}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
10
|
|
|
|
|
181
|
return $Config; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
20
|
|
|
20
|
1
|
217
|
sub subconfig { $Config } |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
3
|
|
|
3
|
|
46
|
BEGIN { _switch_context() } |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |