Juliagraph/Settings.pm

filter: Statementstmt 18.1% 12 / 66 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 33.3% 4 / 12 Podpod 0.0% 0 / 8 totaltotal 11.3% 16 / 141 CC 25 SCAR 38.1
CC
25
Cov
11%
are_equal
90.0
load
72.0
write
30.0
CRAP 45.2
« Juliagraph/Config.pm ↑ Summary Juliagraph.pm »
1  
2 # read and writ .ini files with settings of a drawing
3  
4 package App::GUI::Juliagraph::Settings;
5 1 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub load {
Subroutine load: not called CC=8 SCAR=42.8
Pod undocumented
11 0 my ($file) = @_;
12 0 ▶ return unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 0 0
13 0 $file = expand_path( $file );
14 0 my $data = {};
15 0 ▶ open my $FH, '<', $file or return "could not read $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $FH, "<", $file or return "could not read ${file}: $!" 0 0 0
16 0 my $cat = '';
17 0 ▶ while (<$FH>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $FH)) 0 0 0
18 0 chomp;
19 0 ▶ next unless $_ or substr( $_, 0, 1) eq '#';
Branch: 1 branch
BranchTrueFalseTotal
unless $_ or substr($_, 0, 1) eq "#" 0 0 0
Condition0%0/3
$_ or substr($_, 0, 1) eq "#"
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ or substr($_, 0, 1) eq "#"
$_ substr($_, 0, 1) eq "#"
Truth table0%0/3
A or B
A= $_B= substr($_, 0, 1) eq "#"
ABresult
1X1
011
000
20 0 ▶ if (/\s*\[(\w+)\]/) { $cat = $1 }
Branch: 2 branches
BranchTrueFalseTotal
if (/\s*\[(\w+)\]/u) { } 0 0 0
elsif (/\s*(\w+)\s*=\s*(.+)\s*$/u) { } 0 0 0
21 0 elsif (/\s*(\w+)\s*=\s*(.+)\s*$/){ $data->{$cat}{$1} = $2 }
22 }
23 0 close $FH;
24 0 $data;
25 }
26  
27 0 ▶sub write {
Subroutine write: not called CC=5 SCAR=34.0
Pod undocumented
28 0 my ($file, $data) = @_;
29 0 ▶ open my $FH, '>', $file or return "could not write $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $FH, ">", $file or return "could not write ${file}: $!" 0 0 0
30 0 for my $main_key (sort keys %$data){
31 0 say $FH "\n [$main_key]\n";
32 0 my $subhash = $data->{$main_key};
33 0 ▶ next unless ref $subhash eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $subhash eq "HASH" 0 0 0
34 0 for my $key (sort keys %$subhash){
35 0 say $FH "$key = $subhash->{$key}";
36 }
37 }
38 0 close $FH;
39 0 0;
40 }
41  
42 0 ▶sub ensure_file_ending {
Subroutine ensure_file_ending: not called CC=1 SCAR=6.9
Pod undocumented
43 0 my ($file, $ending) = @_;
44 0 my $ret = $file;
45 0 $ret;
46 }
47  
48 0 ▶sub extract_dir {
Subroutine extract_dir: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my ($path) = @_;
50 0 my ($volume, $dir, $file) = File::Spec->splitpath( $path );
51 0 $path = File::Spec->catdir( $volume, $dir );
52 0 shrink_path( $path );
53 }
54  
55 0 ▶sub shrink_path {
Subroutine shrink_path: not called CC=3 SCAR=24.8
Pod undocumented
56 0 my ($path) = @_;
57 0 my $i = index($path, $FindBin::Bin );
58 0 ▶ $path = '.' . substr( $path, length $FindBin::Bin) if $i > -1;
Branch: 1 branch
BranchTrueFalseTotal
if $i > -1 0 0 0
59 0 $i = index($path, $ENV{HOME} );
60 0 ▶ $path = '~' . substr( $path, length $ENV{HOME}) if $i > -1;
Branch: 1 branch
BranchTrueFalseTotal
if $i > -1 0 0 0
61 0 $path;
62 }
63  
64 0 ▶sub expand_path {
Subroutine expand_path: not called CC=3 SCAR=24.8
Pod undocumented
65 0 my ($path) = @_;
66 0 ▶ $path = File::Spec->catdir( $FindBin::Bin, substr( $path, 1) ) if substr($path, 0,1) eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if substr($path, 0, 1) eq "." 0 0 0
67 0 ▶ $path = File::Spec->catdir( $ENV{HOME}, substr( $path, 1) ) if substr($path, 0,1) eq '~';
Branch: 1 branch
BranchTrueFalseTotal
if substr($path, 0, 1) eq "~" 0 0 0
68 0 $path;
69 }
70  
71  
72 0 ▶sub are_equal {
Subroutine are_equal: not called CC=9 SCAR=45.0
Pod undocumented
73 0 my ($h1, $h2) = @_;
74 0 ▶ return 0 unless ref $h1 eq 'HASH' and ref $h2 eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $h1 eq "HASH" and ref $h2 eq "HASH" 0 0 0
Condition0%0/3
ref $h1 eq "HASH" and ref $h2 eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $h1 eq "HASH" and ref $h2 eq "HASH"
ref $h1 eq "HASH" ref $h2 eq "HASH"
Truth table0%0/3
A and B
A= ref $h1 eq "HASH"B= ref $h2 eq "HASH"
ABresult
0X0
100
111
75 0 for my $key (keys %$h1){
76 0 ▶ next if not ref $h1->{$key} and exists $h2->{$key} and not ref $h2->{$key} and $h1->{$key} eq $h2->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if not ref $h1->{$key} and exists $h2->{$key} and not ref $h2->{$key} and $h1->{$key} eq $h2->{$key} 0 0 0
Condition0%0/9
not ref $h1->{$key} and exists $h2->{$key} and not ref $h2->{$key} and $h1->{$key} eq $h2->{$key}
!ll&&!rl&&r
000
not ref $h1->{$key} and exists $h2->{$key} and not ref $h2->{$key}
!ll&&!rl&&r
000
not ref $h1->{$key} and exists $h2->{$key}
!ll&&!rl&&r
000
MC/DC0%0/4
not ref $h1->{$key} and exists $h2->{$key} and not ref $h2->{$key} and $h1->{$key} eq $h2->{$key}
not ref $h1->{$key} exists $h2->{$key} not ref $h2->{$key} $h1->{$key} eq $h2->{$key}
Truth table0%0/5
not(A) and B and not(C) and D
A= not ref $h1->{$key}B= exists $h2->{$key}C= not ref $h2->{$key}D= $h1->{$key} eq $h2->{$key}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
77 0 ▶ next if are_equal( $h1->{$key}, $h2->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
if are_equal($h1->{$key}, $h2->{$key}) 0 0 0
78 0 return 0;
79 }
80 0 1;
81 }
82  
83 0 ▶sub clone {
Subroutine clone: not called CC=2 SCAR=17.9
Pod undocumented
84 0 my ($settings) = @_;
85 0 ▶ return unless ref $settings eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $settings eq "HASH" 0 0 0
86 0 {map { $_ => {%{$settings->{$_}}} } keys %$settings};
87 }
88  
89  
90  
91  
92 1 1;
« Juliagraph/Config.pm ↑ Summary Juliagraph.pm »