| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$ENV{"HOME"} and -d qq[$ENV{"HOME"}/.config/$name]
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]
| |||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
-e $rc and -r $rc
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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 50 | 0 | die "error: unable to parse $rc: " . Config::Tiny->errstr . "\n"; | |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ( !exists $config->{$section} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||