line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Narada::Config; |
2
|
|
|
|
|
|
|
|
3
|
25
|
|
|
25
|
|
9481925
|
use warnings; |
|
25
|
|
|
|
|
57
|
|
|
25
|
|
|
|
|
979
|
|
4
|
25
|
|
|
25
|
|
114
|
use strict; |
|
25
|
|
|
|
|
45
|
|
|
25
|
|
|
|
|
548
|
|
5
|
25
|
|
|
25
|
|
93
|
use Carp; |
|
25
|
|
|
|
|
36
|
|
|
25
|
|
|
|
|
2166
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 'v2.3.7'; |
8
|
|
|
|
|
|
|
|
9
|
25
|
|
|
25
|
|
12159
|
use Export::Attrs; |
|
25
|
|
|
|
|
170789
|
|
|
25
|
|
|
|
|
151
|
|
10
|
25
|
|
|
25
|
|
8427
|
use Narada; |
|
25
|
|
|
|
|
46
|
|
|
25
|
|
|
|
|
755
|
|
11
|
25
|
|
|
25
|
|
789
|
use Path::Tiny 0.053; |
|
25
|
|
|
|
|
10065
|
|
|
25
|
|
|
|
|
1752
|
|
12
|
|
|
|
|
|
|
|
13
|
25
|
|
100
|
25
|
|
109
|
use constant NARADA => eval { local $SIG{__DIE__}; Narada::detect() } || q{}; |
|
25
|
|
|
|
|
30
|
|
|
25
|
|
|
|
|
105
|
|
14
|
25
|
|
|
25
|
|
102
|
use constant DB_DIR => NARADA eq 'narada-1' ? 'db' : 'mysql'; |
|
25
|
|
|
|
|
37
|
|
|
25
|
|
|
|
|
1098
|
|
15
|
25
|
|
|
25
|
|
87
|
use constant MAXPERM => 0666; ## no critic (ProhibitLeadingZeros) |
|
25
|
|
|
|
|
35
|
|
|
25
|
|
|
|
|
26122
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $VAR_NAME = qr{\A(?:(?![.][.]?/)[\w.-]+/)*(?![.][.]?\z)[\w.-]+\z}xms; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub get_config :Export { |
21
|
92
|
|
|
92
|
1
|
29178
|
my ($var) = @_; |
22
|
92
|
100
|
|
|
|
290
|
croak 'Usage: get_config(NAME)' if @_ != 1; |
23
|
88
|
100
|
|
|
|
868
|
$var =~ /$VAR_NAME/xms or croak "Bad config: $var"; |
24
|
62
|
|
|
|
|
63
|
return undef if !NARADA; ## no critic (ProhibitExplicitReturnUndef) |
25
|
59
|
|
|
|
|
228
|
return path("config/$var")->slurp_utf8; |
26
|
25
|
|
|
25
|
|
174
|
} |
|
25
|
|
|
|
|
34
|
|
|
25
|
|
|
|
|
152
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub get_config_line :Export { |
29
|
30
|
|
|
30
|
1
|
9427
|
my ($val) = get_config(@_); |
30
|
28
|
100
|
|
|
|
6238
|
return $val if !defined $val; |
31
|
26
|
|
|
|
|
117
|
$val =~ s/\n\s*\z//xms; |
32
|
26
|
100
|
|
|
|
85
|
croak 'Config contain more than one line' if $val =~ /\n/xms; |
33
|
24
|
|
|
|
|
105
|
return $val; |
34
|
25
|
|
|
25
|
|
6936
|
} |
|
25
|
|
|
|
|
31
|
|
|
25
|
|
|
|
|
83
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_db_config :Export { |
37
|
1
|
|
|
1
|
1
|
466
|
my %db; |
38
|
1
|
|
|
|
|
2
|
$db{db} = eval { get_config_line(DB_DIR.'/db') }; |
|
1
|
|
|
|
|
3
|
|
39
|
1
|
50
|
33
|
|
|
4
|
if (!defined $db{db} || !length $db{db}) { |
40
|
1
|
|
|
|
|
5
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
0
|
$db{login}= get_config_line(DB_DIR.'/login'); |
43
|
0
|
|
|
|
|
0
|
$db{pass} = get_config_line(DB_DIR.'/pass'); |
44
|
0
|
|
0
|
|
|
0
|
$db{host} = eval { get_config_line(DB_DIR.'/host') } || q{}; |
45
|
0
|
|
0
|
|
|
0
|
$db{port} = eval { get_config_line(DB_DIR.'/port') } || q{}; |
46
|
0
|
|
|
|
|
0
|
$db{dsn_nodb} = 'dbi:mysql:'; |
47
|
0
|
0
|
|
|
|
0
|
$db{dsn_nodb} .= ';host='.$db{host} if $db{host}; ## no critic (ProhibitPostfixControls) |
48
|
0
|
0
|
|
|
|
0
|
$db{dsn_nodb} .= ';port='.$db{port} if $db{port}; ## no critic (ProhibitPostfixControls) |
49
|
0
|
|
|
|
|
0
|
$db{dsn} = $db{dsn_nodb}.';database='.$db{db}; |
50
|
0
|
|
|
|
|
0
|
return \%db; |
51
|
25
|
|
|
25
|
|
7698
|
} |
|
25
|
|
|
|
|
30
|
|
|
25
|
|
|
|
|
79
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub set_config :Export { |
54
|
39
|
|
|
39
|
1
|
19588
|
my ($var, $val) = @_; |
55
|
39
|
100
|
|
|
|
160
|
croak 'Usage: set_config(NAME, VALUE)' if @_ != 2; |
56
|
33
|
100
|
|
|
|
389
|
$var =~ /$VAR_NAME/xms or croak "Bad config: $var"; |
57
|
11
|
|
|
|
|
28
|
croak 'Narada::Config was loaded not in narada directory' if !NARADA; |
58
|
10
|
|
|
|
|
63
|
my $cfg = path("config/$var"); |
59
|
10
|
|
|
|
|
397
|
$cfg->parent->mkpath; |
60
|
10
|
|
|
|
|
1437
|
$cfg->spew_utf8($val); |
61
|
10
|
|
|
|
|
6325
|
$cfg->chmod(MAXPERM & ~umask); |
62
|
10
|
|
|
|
|
274
|
return; |
63
|
25
|
|
|
25
|
|
6448
|
} |
|
25
|
|
|
|
|
35
|
|
|
25
|
|
|
|
|
99
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
67
|
|
|
|
|
|
|
__END__ |