lib/Kephra/Config.pm

filter: Statementstmt 28.7% 19 / 66 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 6 totaltotal 19.8% 25 / 126 CC 25 SCAR 51.7
CC
25
Cov
18%
check
342.0
set_value
30.0
get_value
12.0
CRAP 176.8
« lib/Kephra/App/Editor/Position.pm ↑ Summary lib/Kephra/App/Editor/Move.pm »
1 1 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Kephra::Config;
5  
6 1 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Kephra::Config::Default;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 my $file_name = File::Spec->catfile( File::HomeDir->my_home, '.config', 'kephra', 'main-recent.yaml');
13  
14 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
15 0 my $default = Kephra::Config::Default::get();
16 0 my $data = {};
17 0 ▶ if (-r $file_name){
Branch: 1 branch
BranchTrueFalseTotal
if (-r $file_name) { } 0 0 0
18 0 $data = (YAML::LoadFile( $file_name ))[0];
19 0 check( $data, $default);
20 0 } else { $data = $default; }
21 0 return bless {data => $data};
22 }
23  
24 0 ▶sub write {
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
25 0 my ($self) = @_;
26 0 YAML::DumpFile( $file_name, $self->{'data'} );
27 }
28  
29 0 ▶sub reload {
Subroutine reload: not called CC=1 SCAR=6.9
Pod undocumented
30 0 my ($self) = @_;
31 }
32  
33 0 ▶sub set_value {
Subroutine set_value: not called CC=5 SCAR=34.0
Pod undocumented
34 0 my ($self, $value, @keys) = @_;
35 0 ▶ return undef unless @keys;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys 0 0 0
36 0 my $last_key = pop @keys;
37 0 my $data = $self->{'data'};
38 0 for my $k (@keys){
39 0 ▶ return undef unless exists $data->{ $k };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $data->{$k} 0 0 0
40 0 $data = $data->{ $k };
41 }
42 0 ▶ $data->{$last_key} = $value if exists $data->{$last_key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{$last_key} 0 0 0
43 }
44  
45 0 ▶sub get_value {
Subroutine get_value: not called CC=3 SCAR=24.8
Pod undocumented
46 0 my ($self, @keys) = @_;
47 0 my $data = $self->{'data'};
48 0 for my $k (@keys){
49 0 ▶ return undef unless exists $data->{ $k };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $data->{$k} 0 0 0
50 0 $data = $data->{ $k };
51 }
52 0 return $data;
53 }
54  
55  
56 0 ▶sub check {
Subroutine check: not called CC=18 SCAR=58.3
Pod undocumented
57 0 my ($data, $default) = @_;
58 0 ▶ return unless ref $data eq 'HASH' and ref $default eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" and ref $default eq "HASH" 0 0 0
Condition0%0/3
ref $data eq "HASH" and ref $default eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $data eq "HASH" and ref $default eq "HASH"
ref $data eq "HASH" ref $default eq "HASH"
Truth table0%0/3
A and B
A= ref $data eq "HASH"B= ref $default eq "HASH"
ABresult
0X0
100
111
59 0 for my $k (keys %$data){
60 0 ▶ delete $data->{$k} unless exists $default->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $default->{$k} 0 0 0
61 }
62 0 for my $k (keys %$default) {
63 0 my $vr = ref $default->{$k};
64 0 ▶ if ( not $vr){
Branch: 3 branches
BranchTrueFalseTotal
if (not $vr) { } 0 0 0
elsif ($vr eq 'ARRAY') { } 0 0 0
elsif ($vr eq 'HASH') { } 0 0 0
65 0 ▶ $data->{$k} = $default->{$k} if not exists $data->{$k} or ref $data->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if not exists $data->{$k} or ref $data->{$k} 0 0 0
Condition0%0/3
not exists $data->{$k} or ref $data->{$k}
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $data->{$k} or ref $data->{$k}
not exists $data->{$k} ref $data->{$k}
Truth table0%0/3
not(A) or B
A= not exists $data->{$k}B= ref $data->{$k}
ABresult
1X1
011
000
66 } elsif ($vr eq 'ARRAY'){
67 0 ▶ if (ref $data->{$k} ne 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data->{$k} ne 'ARRAY') { } 0 0 0
68 0 $data->{$k} = $default->{$k};
69 } else {
70 0 ▶ if (@{$default->{$k}}){
Branch: 1 branch
BranchTrueFalseTotal
if (@{$default->{$k};}) 0 0 0
71 0 my $subvalref = ref $default->{$k}[0];
72 0 for my $i (reverse 0 .. $#{$data->{$k}}){
73 0 ▶ delete $data->{$k}[$i] if ref $data->{$k}[$i] ne $subvalref;
Branch: 1 branch
BranchTrueFalseTotal
if ref $data->{$k}[$i] ne $subvalref 0 0 0
74 }
75 0 ▶ if (ref $default->{$k}[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $default->{$k}[0] eq "HASH") 0 0 0
76 0 check( $_, $default->{$k}[0]) for @{$data->{$k}};
77 }
78 }
79 }
80 } elsif ($vr eq 'HASH'){
81 0 ▶ if (ref $data->{$k} ne 'HASH'){ $data->{$k} = $default->{$k} }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data->{$k} ne 'HASH') { } 0 0 0
82 0 else { check( $data->{$k}, $default->{$k} ) }
83 0 } else { return }
84 }
85 }
86  
87 1 1;
« lib/Kephra/App/Editor/Position.pm ↑ Summary lib/Kephra/App/Editor/Move.pm »