| 1 | package Narada::Config; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 218 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 218 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 218 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 218 | our $VERSION = 'v2.3.8'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 218 | ▶ | use Export::Attrs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 218 | ▶ | use Narada; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 218 | ▶ | use Path::Tiny 0.053; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 218 | ▶ | use constant NARADA => eval { local $SIG{__DIE__}; Narada::detect() } || q{}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
Condition100%2/2
eval {
do {
local $SIG{'__DIE__'};
Narada::detect()
}
} || ''
MC/DC100%1/1
eval {
do {
local $SIG{'__DIE__'};
Narada::detect()
}
} || ''
eval {
do {
local $SIG{'__DIE__'};
Narada::detect()
}
}
Truth table100%2/2
A
A= eval {
do {
local $SIG{'__DIE__'};
Narada::detect()
}
}
| |||||||||||||||||||||||||||||
| 14 | 218 | ▶ | use constant DB_DIR => NARADA eq 'narada-1' ? 'db' : 'mysql'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 218 | ▶ | use constant MAXPERM => 0666; ## no critic (ProhibitLeadingZeros) | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 218 | my $VAR_NAME = qr{\A(?:(?![.][.]?/)[\w.-]+/)*(?![.][.]?\z)[\w.-]+\z}xms; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 205 | ▶ | sub get_config :Export { | ||||||||||||||||||||||||||
|
Subroutine
get_config: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 205 | my ($var) = @_; | |||||||||||||||||||||||||||
| 22 | 205 | ▶ | croak 'Usage: get_config(NAME)' if @_ != 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 201 | ▶ | $var =~ /$VAR_NAME/xms or croak "Bad config: $var"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 175 | return undef if !NARADA; ## no critic (ProhibitExplicitReturnUndef) | |||||||||||||||||||||||||||
| 25 | 172 | return path("config/$var")->slurp_utf8; | |||||||||||||||||||||||||||
| 26 | 218 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 139 | ▶ | sub get_config_line :Export { | ||||||||||||||||||||||||||
|
Subroutine
get_config_line: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 139 | my ($val) = get_config(@_); | |||||||||||||||||||||||||||
| 30 | 137 | ▶ | return $val if !defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 135 | $val =~ s/\n\s*\z//xms; | |||||||||||||||||||||||||||
| 32 | 135 | ▶ | croak 'Config contain more than one line' if $val =~ /\n/xms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 133 | return $val; | |||||||||||||||||||||||||||
| 34 | 218 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 110 | ▶ | sub get_db_config :Export { | ||||||||||||||||||||||||||
|
Subroutine
get_db_config: called CC=7 SCAR=32.4
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 110 | my %db; | |||||||||||||||||||||||||||
| 38 | 110 | $db{db} = eval { get_config_line(DB_DIR.'/db') }; | |||||||||||||||||||||||||||
| 39 | 110 | ▶ | if (!defined $db{db} || !length $db{db}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $db{"db"} and length $db{"db"}
MC/DC0%0/2
defined $db{"db"} and length $db{"db"}
defined $db{"db"}
length $db{"db"}
Truth table66%2/3
A and B
A= defined $db{"db"}B= length $db{"db"}
| |||||||||||||||||||||||||||||
| 40 | 110 | return; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 0 | $db{login}= get_config_line(DB_DIR.'/login'); | |||||||||||||||||||||||||||
| 43 | 0 | $db{pass} = get_config_line(DB_DIR.'/pass'); | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | $db{host} = eval { get_config_line(DB_DIR.'/host') } || q{}; | ||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
get_config_line('mysql/host')
}
} || ''
MC/DC0%0/1
eval {
do {
get_config_line('mysql/host')
}
} || ''
eval {
do {
get_config_line('mysql/host')
}
}
Truth table0%0/2
A
A= eval {
do {
get_config_line('mysql/host')
}
}
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | $db{port} = eval { get_config_line(DB_DIR.'/port') } || q{}; | ||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
get_config_line('mysql/port')
}
} || ''
MC/DC0%0/1
eval {
do {
get_config_line('mysql/port')
}
} || ''
eval {
do {
get_config_line('mysql/port')
}
}
Truth table0%0/2
A
A= eval {
do {
get_config_line('mysql/port')
}
}
| |||||||||||||||||||||||||||||
| 46 | 0 | $db{dsn_nodb} = 'dbi:mysql:'; | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | $db{dsn_nodb} .= ';host='.$db{host} if $db{host}; ## no critic (ProhibitPostfixControls) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $db{dsn_nodb} .= ';port='.$db{port} if $db{port}; ## no critic (ProhibitPostfixControls) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | $db{dsn} = $db{dsn_nodb}.';database='.$db{db}; | |||||||||||||||||||||||||||
| 50 | 0 | return \%db; | |||||||||||||||||||||||||||
| 51 | 218 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 66 | ▶ | sub set_config :Export { | ||||||||||||||||||||||||||
|
Subroutine
set_config: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 66 | my ($var, $val) = @_; | |||||||||||||||||||||||||||
| 55 | 66 | ▶ | croak 'Usage: set_config(NAME, VALUE)' if @_ != 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 60 | ▶ | $var =~ /$VAR_NAME/xms or croak "Bad config: $var"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 38 | croak 'Narada::Config was loaded not in narada directory' if !NARADA; | |||||||||||||||||||||||||||
| 58 | 37 | my $cfg = path("config/$var"); | |||||||||||||||||||||||||||
| 59 | 37 | $cfg->parent->mkpath; | |||||||||||||||||||||||||||
| 60 | 35 | $cfg->spew_utf8($val); | |||||||||||||||||||||||||||
| 61 | 33 | $cfg->chmod(MAXPERM & ~umask); | |||||||||||||||||||||||||||
| 62 | 33 | return; | |||||||||||||||||||||||||||
| 63 | 218 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 218 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||