line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Darkpan::Config; |
2
|
1
|
|
|
1
|
|
13
|
use v5.20; |
|
1
|
|
|
|
|
7
|
|
3
|
1
|
|
|
1
|
|
541
|
use Moo; |
|
1
|
|
|
|
|
10667
|
|
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
2177
|
use JSON; |
|
1
|
|
|
|
|
8453
|
|
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
151
|
use Mojo::File; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
6
|
1
|
|
|
1
|
|
9
|
use Cwd; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
7
|
1
|
|
|
1
|
|
7
|
use Data::Dumper; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
653
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has _config => (is => 'lazy'); |
10
|
|
|
|
|
|
|
has directory => (is => 'lazy'); |
11
|
|
|
|
|
|
|
has compressIndex => (is => 'lazy'); |
12
|
|
|
|
|
|
|
has path => (is => 'lazy'); |
13
|
|
|
|
|
|
|
has basic_auth => (is => 'lazy'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub no_compress { |
16
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
17
|
0
|
|
|
|
|
|
return !$self->compressIndex; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _build_path { |
21
|
0
|
|
|
0
|
|
|
my $self = shift; |
22
|
0
|
|
|
|
|
|
my $path; |
23
|
0
|
0
|
|
|
|
|
if ($ENV{DARKPAN_PATH}) { |
24
|
0
|
|
|
|
|
|
$path = $ENV{DARKPAN_PATH}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
|
|
|
|
|
|
$path = $self->_config->{path} |
28
|
0
|
0
|
0
|
|
|
|
if $self->_config && $self->_config->{path}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# default if undef |
32
|
0
|
|
0
|
|
|
|
$path //= 'darkpan'; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return $path; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _build_basic_auth { |
38
|
0
|
|
|
0
|
|
|
my $self = shift; |
39
|
0
|
|
|
|
|
|
my $config; |
40
|
0
|
0
|
0
|
|
|
|
if ($ENV{DARKPAN_AUTH_REALM}) { |
|
|
0
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$config->{realm} = $ENV{DARKPAN_AUTH_REALM}; |
42
|
0
|
|
|
|
|
|
for my $k (keys %ENV) { |
43
|
0
|
0
|
|
|
|
|
if ($k =~ m/^DARKPAN_AUTH_(.*)/) { |
44
|
0
|
|
|
|
|
|
$config->{config}->{lc($1)} = $ENV{$k}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif (defined($self->_config) && defined($self->_config->{basic_auth})) { |
49
|
0
|
|
|
|
|
|
my @keys = keys %{$self->_config->{basic_auth}}; |
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$config = { |
51
|
|
|
|
|
|
|
realm => $keys[0], |
52
|
0
|
|
|
|
|
|
config => $self->_config->{basic_auth}->{$keys[0]} |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return $config; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _build__config { |
60
|
0
|
|
|
0
|
|
|
my $self = shift; |
61
|
0
|
|
|
|
|
|
my $location = $ENV{DARKPAN_CONFIG_FILE}; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if (defined($location)) { |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$self->_validateAssetLocation($location); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $file = Mojo::File->new($location); |
68
|
0
|
|
|
|
|
|
my $config = JSON->new->utf8->decode($file->slurp); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return $config; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return undef; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _build_directory { |
77
|
0
|
|
|
0
|
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $dir; |
80
|
0
|
0
|
|
|
|
|
if ($ENV{DARKPAN_DIRECTORY}) { |
81
|
0
|
|
|
|
|
|
$dir = $ENV{DARKPAN_DIRECTORY}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
|
|
|
|
|
|
$dir = $self->_config->{directory} |
85
|
0
|
0
|
0
|
|
|
|
if $self->_config && $self->_config->{directory}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# default if undef |
89
|
0
|
|
0
|
|
|
|
$dir //= 'darkpan'; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$dir = $self->_validateAssetLocation($dir); |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return $dir; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _build_compressIndex { |
97
|
0
|
|
|
0
|
|
|
my $self = shift; |
98
|
0
|
|
|
|
|
|
my $compress; |
99
|
0
|
0
|
|
|
|
|
if ($ENV{DARKPAN_COMPRESS_INDEX}) { |
100
|
0
|
|
|
|
|
|
$compress = $ENV{DARKPAN_COMPRESS_INDEX}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else { |
103
|
|
|
|
|
|
|
$compress = $self->_config->{compress_index} |
104
|
0
|
0
|
0
|
|
|
|
if $self->_config && $self->_config->{compress_index}; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# default if undef |
108
|
0
|
|
0
|
|
|
|
$compress //= 1; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return $compress; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _validateAssetLocation { |
114
|
0
|
|
|
0
|
|
|
my $self = shift; |
115
|
0
|
|
|
|
|
|
my $dir = shift; |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if ($dir !~ m/^\//) { |
118
|
0
|
|
|
|
|
|
$dir =~ s/^\.\///; |
119
|
0
|
|
|
|
|
|
my $base = getcwd; |
120
|
0
|
|
|
|
|
|
$dir = "$base/$dir"; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
return $dir; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |