Toot/Config.pm

filter: Statementstmt 30.5% 11 / 36 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 3 / 6 Podpod 100% 1 / 1 totaltotal 22.3% 15 / 67 CC 11 SCAR 34.2
CC
11
Cov
20%
_load_and_verify
56.0
_get_conf_dir
20.0
load
6.0
CRAP 30.4
↑ Summary Toot.pm »
1 package App::Toot::Config;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Config::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.05';
9  
10 0 ▶sub load {
Subroutine load: not called CC=2 SCAR=17.9
Pod documented
11 0 my $class = shift;
12 0 my $section = shift;
13  
14 0 ▶ if ( !defined $section ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $section) 0 0 0
15 0 die 'section is required';
16 }
17  
18 0 return _load_and_verify($section)->{$section};
19 }
20  
21 0 ▶sub _get_conf_dir {
Subroutine _get_conf_dir: not called CC=4 SCAR=30.0
22 0 my $name = 'toot';
23  
24 0 my $dir;
25 0 ▶ if ( $ENV{HOME} && -d "$ENV{HOME}/.config/$name" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ENV{'HOME'} and -d "$ENV{'HOME'}/.config/$name") { } 0 0 0
elsif (-d "/etc/$name") { } 0 0 0
Condition0%0/3
$ENV{"HOME"} and -d qq[$ENV{"HOME"}/.config/$name]
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"HOME"} and -d qq[$ENV{"HOME"}/.config/$name]
$ENV{"HOME"} -d qq[$ENV{"HOME"}/.config/$name]
Truth table0%0/3
A and B
A= $ENV{"HOME"}B= -d qq[$ENV{"HOME"}/.config/$name]
ABresult
0X0
100
111
26 0 $dir = "$ENV{HOME}/.config";
27 }
28 elsif ( -d "/etc/$name" ) {
29 0 $dir = '/etc';
30 }
31 else {
32 0 die "error: unable to find config directory\n";
33 }
34  
35 0 return "$dir/$name";
36 }
37  
38 0 ▶sub _load_and_verify {
Subroutine _load_and_verify: not called CC=7 SCAR=40.3
39 0 my $section = shift;
40  
41 0 my $rc = _get_conf_dir() . '/config.ini';
42  
43 0 ▶ unless ( -e $rc && -r $rc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $rc and -r $rc) 0 0 0
Condition0%0/3
-e $rc and -r $rc
!ll&&!rl&&r
000
MC/DC0%0/2
-e $rc and -r $rc
-e $rc -r $rc
Truth table0%0/3
A and B
A= -e $rcB= -r $rc
ABresult
0X0
100
111
44 0 die "error: $rc does not exist or cannot be read\n";
45 }
46  
47 0 my $config = Config::Tiny->read($rc);
48  
49 0 ▶ if ( !defined $config ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $config) 0 0 0
50 0 die "error: unable to parse $rc: " . Config::Tiny->errstr . "\n";
51 }
52  
53 0 ▶ if ( !exists $config->{$section} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $config->{$section}) 0 0 0
54 0 die "$section section was not found in the config\n";
55 }
56  
57 0 foreach my $key (qw{ instance username client_id client_secret access_token }) {
58 0 ▶ if ( !defined $config->{$section}{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $config->{$section}{$key}) 0 0 0
59 0 die "$key key for $section section in $rc is not defined\n";
60 }
61 }
62  
63 0 return $config;
64 }
65  
66 1 1;
67  
68 __END__
↑ Summary Toot.pm »