lib/Narada/Config.pm

filter: Statementstmt 86.0% 68 / 79 Branchbran 72.2% 13 / 18 Conditioncond 44.4% 4 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 17 / 17 Podpod 100% 4 / 4 totaltotal 81.0% 107 / 132 CC 14 SCAR 20.0
CC
14
Cov
80%
get_db_config
25.6
get_config
3.0
get_config_line
3.0
CRAP 7.4
« blib/script/narada-setup-qmail ↑ Summary blib/script/narada-install »
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() } } || ''
l!l
2108
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() } }
Aresult
11
00
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
BranchTrueFalseTotal
if @_ != 1 4 201 205
23 201 ▶ $var =~ /$VAR_NAME/xms or croak "Bad config: $var";
Branch: 1 branch
BranchTrueFalseTotal
$var =~ /$VAR_NAME/msx or croak("Bad config: $var") 175 26 201
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
BranchTrueFalseTotal
unless defined $val 2 135 137
31 135 $val =~ s/\n\s*\z//xms;
32 135 ▶ croak 'Config contain more than one line' if $val =~ /\n/xms;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /\n/msx 2 133 135
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
BranchTrueFalseTotal
unless (defined $db{"db"} and length $db{"db"}) 110 0 110
Condition66%2/3
defined $db{"db"} and length $db{"db"}
!ll&&!rl&&r
11090
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"}
ABresult
0X0
100
111
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') } } || ''
l!l
00
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') } }
Aresult
11
00
45 0 ▶ $db{port} = eval { get_config_line(DB_DIR.'/port') } || q{};
Condition0%0/2
eval { do { get_config_line('mysql/port') } } || ''
l!l
00
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') } }
Aresult
11
00
46 0 $db{dsn_nodb} = 'dbi:mysql:';
47 0 ▶ $db{dsn_nodb} .= ';host='.$db{host} if $db{host}; ## no critic (ProhibitPostfixControls)
Branch: 1 branch
BranchTrueFalseTotal
if $db{"host"} 0 0 0
48 0 ▶ $db{dsn_nodb} .= ';port='.$db{port} if $db{port}; ## no critic (ProhibitPostfixControls)
Branch: 1 branch
BranchTrueFalseTotal
if $db{"port"} 0 0 0
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
BranchTrueFalseTotal
if @_ != 2 6 60 66
56 60 ▶ $var =~ /$VAR_NAME/xms or croak "Bad config: $var";
Branch: 1 branch
BranchTrueFalseTotal
$var =~ /$VAR_NAME/msx or croak("Bad config: $var") 38 22 60
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__
« blib/script/narada-setup-qmail ↑ Summary blib/script/narada-install »