lib/Mojo/Darkpan/Config.pm

filter: Statementstmt 100% 73 / 73 Branchbran 100% 22 / 22 Conditioncond 80.9% 17 / 21 MC/DCmcdc 69.2% 9 / 13 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 1 totaltotal 93.7% 134 / 143 CC 21 SCAR 14.2
CC
21
Cov
97%
_build_compressIndex
6.0
_build_basic_auth
6.0
_build_path
5.0
CRAP 4.2
« lib/Mojolicious/Plugin/DirectoryHandler.pm ↑ Summary lib/Mojo/Darkpan/Util.pm »
1 package Mojo::Darkpan::Config;
2 5 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Mojo::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 has _config => (is => 'lazy');
10 5 has directory => (is => 'lazy');
11 5 has compressIndex => (is => 'lazy');
12 5 has path => (is => 'lazy');
13 5 has basic_auth => (is => 'lazy');
14  
15 15 ▶sub no_compress {
Subroutine no_compress: called CC=1 SCAR=0.0
Pod undocumented
16 15 my $self = shift;
17 15 return !$self->compressIndex;
18 }
19  
20 7 ▶sub _build_path {
Subroutine _build_path: called CC=5 SCAR=16.1
21 7 my $self = shift;
22 7 my $path;
23 7 ▶ if ($ENV{DARKPAN_PATH}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'DARKPAN_PATH'}) { } 1 6 7
24 1 $path = $ENV{DARKPAN_PATH};
25 }
26 else {
27 $path = $self->_config->{path}
28 6 ▶ if $self->_config && $self->_config->{path};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_config and $self->_config->{"path"} 1 3 4
Condition66%2/3
$self->_config and $self->_config->{"path"}
!ll&&!rl&&r
301
MC/DC50%1/2
$self->_config and $self->_config->{"path"}
$self->_config $self->_config->{"path"}
Truth table66%2/3
A and B
A= $self->_configB= $self->_config->{"path"}
ABresult
0X0
100
111
29 }
30  
31 # default if undef
32 5 ▶ $path //= 'darkpan';
Condition100%2/2
$path //= "darkpan"
l!l
23
MC/DC100%1/1
$path //= "darkpan"
$path
Truth table100%2/2
A
A= $path
Aresult
11
00
33  
34 5 return $path;
35 }
36  
37 16 ▶sub _build_basic_auth {
Subroutine _build_basic_auth: called CC=6 SCAR=17.9
38 16 my $self = shift;
39 16 my $config;
40 16 ▶ if ($ENV{DARKPAN_AUTH_REALM}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ENV{'DARKPAN_AUTH_REALM'}) { } 7 9 16
elsif (defined $self->_config and defined $self->_config->{'basic_auth'}) { } 1 16 17
41 7 $config->{realm} = $ENV{DARKPAN_AUTH_REALM};
42 7 for my $k (keys %ENV) {
43 246 ▶ if ($k =~ m/^DARKPAN_AUTH_(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^DARKPAN_AUTH_(.*)/u) 20 226 246
44 20 $config->{config}->{lc($1)} = $ENV{$k};
45 }
46 }
47 }
48 ▶ elsif (defined($self->_config) && defined($self->_config->{basic_auth})) {
Condition66%2/3
defined $self->_config and defined $self->_config->{"basic_auth"}
!ll&&!rl&&r
801
MC/DC50%1/2
defined $self->_config and defined $self->_config->{"basic_auth"}
defined $self->_config defined $self->_config->{"basic_auth"}
Truth table66%2/3
A and B
A= defined $self->_configB= defined $self->_config->{"basic_auth"}
ABresult
0X0
100
111
49 1 my @keys = keys %{$self->_config->{basic_auth}};
50 $config = {
51 realm => $keys[0],
52 1 config => $self->_config->{basic_auth}->{$keys[0]}
53 };
54 }
55  
56 16 return $config;
57 }
58  
59 17 ▶sub _build__config {
Subroutine _build__config: called CC=2 SCAR=6.9
60 17 my $self = shift;
61 17 my $location = $ENV{DARKPAN_CONFIG_FILE};
62  
63 17 ▶ if (defined($location)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $location) 5 12 17
64  
65 5 $self->_validateAssetLocation($location);
66  
67 5 my $file = Mojo::File->new($location);
68 5 my $config = JSON->new->utf8->decode($file->slurp);
69  
70 3 return $config;
71 }
72  
73 12 return undef;
74 }
75  
76 12 ▶sub _build_directory {
Subroutine _build_directory: called CC=5 SCAR=16.1
77 12 my $self = shift;
78  
79 12 my $dir;
80 12 ▶ if ($ENV{DARKPAN_DIRECTORY}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'DARKPAN_DIRECTORY'}) { } 10 2 12
81 10 $dir = $ENV{DARKPAN_DIRECTORY};
82 }
83 else {
84 $dir = $self->_config->{directory}
85 2 ▶ if $self->_config && $self->_config->{directory};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_config and $self->_config->{"directory"} 1 1 2
Condition66%2/3
$self->_config and $self->_config->{"directory"}
!ll&&!rl&&r
101
MC/DC50%1/2
$self->_config and $self->_config->{"directory"}
$self->_config $self->_config->{"directory"}
Truth table66%2/3
A and B
A= $self->_configB= $self->_config->{"directory"}
ABresult
0X0
100
111
86 }
87  
88 # default if undef
89 12 ▶ $dir //= 'darkpan';
Condition100%2/2
$dir //= "darkpan"
l!l
111
MC/DC100%1/1
$dir //= "darkpan"
$dir
Truth table100%2/2
A
A= $dir
Aresult
11
00
90  
91 12 $dir = $self->_validateAssetLocation($dir);
92  
93 12 return $dir;
94 }
95  
96 12 ▶sub _build_compressIndex {
Subroutine _build_compressIndex: called CC=6 SCAR=17.9
97 12 my $self = shift;
98 12 my $compress;
99 # an empty env var falls through to the config file; "0" is a real value
100 12 ▶ if (defined $ENV{DARKPAN_COMPRESS_INDEX} && length $ENV{DARKPAN_COMPRESS_INDEX}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{'DARKPAN_COMPRESS_INDEX'} and length $ENV{'DARKPAN_COMPRESS_INDEX'}) { } 1 11 12
Condition100%3/3
defined $ENV{"DARKPAN_COMPRESS_INDEX"} and length $ENV{"DARKPAN_COMPRESS_INDEX"}
!ll&&!rl&&r
1011
MC/DC100%2/2
defined $ENV{"DARKPAN_COMPRESS_INDEX"} and length $ENV{"DARKPAN_COMPRESS_INDEX"}
defined $ENV{"DARKPAN_COMPRESS_INDEX"} length $ENV{"DARKPAN_COMPRESS_INDEX"}
Truth table100%3/3
A and B
A= defined $ENV{"DARKPAN_COMPRESS_INDEX"}B= length $ENV{"DARKPAN_COMPRESS_INDEX"}
ABresult
0X0
100
111
101 1 $compress = $ENV{DARKPAN_COMPRESS_INDEX};
102 }
103 else {
104 $compress = $self->_config->{compress_index}
105 11 ▶ if $self->_config && defined $self->_config->{compress_index};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_config and defined $self->_config->{"compress_index"} 3 8 11
Condition66%2/3
$self->_config and defined $self->_config->{"compress_index"}
!ll&&!rl&&r
803
MC/DC50%1/2
$self->_config and defined $self->_config->{"compress_index"}
$self->_config defined $self->_config->{"compress_index"}
Truth table66%2/3
A and B
A= $self->_configB= defined $self->_config->{"compress_index"}
ABresult
0X0
100
111
106 }
107  
108 # default if undef
109 12 ▶ $compress //= 1;
Condition100%2/2
$compress //= 1
l!l
48
MC/DC100%1/1
$compress //= 1
$compress
Truth table100%2/2
A
A= $compress
Aresult
11
00
110  
111 12 return $compress;
112 }
113  
114 17 ▶sub _validateAssetLocation {
Subroutine _validateAssetLocation: called CC=2 SCAR=6.9
115 17 my $self = shift;
116 17 my $dir = shift;
117  
118 17 ▶ if ($dir !~ m/^\//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dir =~ m[^/]u) 2 15 17
119 2 $dir =~ s/^\.\///;
120 2 my $base = getcwd;
121 2 $dir = "$base/$dir";
122 }
123  
124 17 return $dir;
125 }
126  
127 5 1;
« lib/Mojolicious/Plugin/DirectoryHandler.pm ↑ Summary lib/Mojo/Darkpan/Util.pm »