| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->_config and $self->_config->{"path"}
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"}
| |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # default if undef | ||||||||||||||||||||||||||||
| 32 | 5 | ▶ | $path //= 'darkpan'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$path //= "darkpan"
MC/DC100%1/1
$path //= "darkpan"
$path
Truth table100%2/2
A
A= $path
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->_config and $self->_config->{"directory"}
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"}
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # default if undef | ||||||||||||||||||||||||||||
| 89 | 12 | ▶ | $dir //= 'darkpan'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$dir //= "darkpan"
MC/DC100%1/1
$dir //= "darkpan"
$dir
Truth table100%2/2
A
A= $dir
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $ENV{"DARKPAN_COMPRESS_INDEX"} and length $ENV{"DARKPAN_COMPRESS_INDEX"}
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"}
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->_config and defined $self->_config->{"compress_index"}
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"}
| |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # default if undef | ||||||||||||||||||||||||||||
| 109 | 12 | ▶ | $compress //= 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$compress //= 1
MC/DC100%1/1
$compress //= 1
$compress
Truth table100%2/2
A
A= $compress
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||