Juliagraph/Config.pm

filter: Statementstmt 23.9% 17 / 71 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 45.4% 5 / 11 Podpod 0.0% 0 / 6 totaltotal 17.0% 22 / 129 CC 24 SCAR 43.2
CC
24
Cov
15%
load
156.0
save
72.0
add_setting_file
20.0
CRAP 75.3
« Juliagraph/Compute/Mapping.pm ↑ Summary Juliagraph/Settings.pm »
1  
2 # config file parser and data access
3  
4 package App::GUI::Juliagraph::Config;
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 File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use App::GUI::Juliagraph::Config::Default;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 my $file_name = File::Spec->catfile( File::HomeDir->my_home, '.config', 'juliagraph');
12 1 my $dir = '';
13  
14 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
15 0 my ($pkg) = @_;
16 0 ▶ my $data = -r $file_name
Branch: 1 branch
BranchTrueFalseTotal
-r $file_name ? : 0 0 0
17 ? load( $pkg, $file_name )
18 : $ App::GUI::Juliagraph::Config::Default::data;
19 0 bless { path => $file_name, data => $data };
20 }
21  
22 0 ▶sub load {
Subroutine load: not called CC=12 SCAR=50.5
Pod undocumented
23 0 my ($self, $file) = @_;
24 0 my $data = {};
25 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
26 0 my $category = '';
27 0 ▶ while (<$FH>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $FH)) 0 0 0
28 0 chomp;
29 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
30 0 ▶ if (/^\s*(\w+):\s*$/) { $category = $1; $data->{$category} = []; }
Branch: 5 branches
BranchTrueFalseTotal
if (/^\s*(\w+):\s*$/u) { } 0 0 0
elsif (/^\s+-\s+(.+)\s*$/u) { } 0 0 0
elsif (/^\s+\+\s+(\w+)\s*=\s*\[\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\]/u) { } 0 0 0
elsif (/^\s+\+\s+(\w+)\s*=\s*\[\s*(.+)\s*\]/u) { } 0 0 0
elsif (/\s*(\w+)\s*=\s*(.+)\s*$/u) { } 0 0 0
31 0 elsif (/^\s+-\s+(.+)\s*$/) { push @{$data->{$category}}, $1; }
32 elsif (/^\s+\+\s+(\w+)\s*=\s*\[\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\]/)
33 0 ▶ { $data->{$category} = {} if ref $data->{$category} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data->{$category} ne "HASH" 0 0 0
34 0 $data->{$category}{$1} = [$2, $3, $4]; }
35 elsif (/^\s+\+\s+(\w+)\s*=\s*\[\s*(.+)\s*\]/)
36 0 ▶ { $data->{$category} = {} if ref $data->{$category} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data->{$category} ne "HASH" 0 0 0
37 0 $data->{$category}{$1} = [map {tr/ //d; $_} split /,/, $2] }
38 0 elsif (/\s*(\w+)\s*=\s*(.+)\s*$/) { $data->{$1} = $2; $category = '';}
39 }
40 0 close $FH;
41 0 $data;
42 }
43  
44 0 ▶sub save {
Subroutine save: not called CC=8 SCAR=42.8
Pod undocumented
45 0 my ($self) = @_;
46 0 my $data = $self->{'data'};
47 0 my $file = $self->{'path'};
48 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
49 0 $" = ',';
50 0 for my $key (sort keys %$data){
51 0 my $val = $data->{ $key };
52 0 ▶ if (ref $val eq 'ARRAY'){
Branch: 3 branches
BranchTrueFalseTotal
if (ref $val eq 'ARRAY') { } 0 0 0
elsif (ref $val eq 'HASH') { } 0 0 0
elsif (not ref $val) { } 0 0 0
53 0 say $FH "$key:";
54 0 say $FH " - $_" for @$val;
55 } elsif (ref $val eq 'HASH'){
56 0 say $FH "$key:";
57 0 say $FH " + $_ = [ @{$val->{$_}} ]" for sort keys %$val;
58 } elsif (not ref $val){
59 0 say $FH "$key = $val";
60 }
61 }
62 0 close $FH;
63 }
64  
65  
66 0 ▶sub get_value {
Subroutine get_value: not called CC=2 SCAR=17.9
Pod undocumented
67 0 my ($self, $key) = @_;
68 0 ▶ $self->{'data'}{$key} if exists $self->{'data'}{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"data"}{$key} 0 0 0
69 }
70  
71 0 ▶sub set_value {
Subroutine set_value: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my ($self, $key, $value) = @_;
73 0 $self->{'data'}{$key} = $value;
74 }
75  
76 0 ▶sub add_setting_file {
Subroutine add_setting_file: not called CC=4 SCAR=30.0
Pod undocumented
77 0 my ($self, $file) = @_;
78 0 $file = App::GUI::Juliagraph::Settings::shrink_path( $file );
79 0 ▶ for my $f (@{$self->{'data'}{'last_settings'}}) { return if $f eq $file }
Branch: 1 branch
BranchTrueFalseTotal
if $f eq $file 0 0 0
80 0 push @{$self->{'data'}{'last_settings'}}, $file;
81 0 ▶ shift @{$self->{'data'}{'last_settings'}} if @{$self->{'data'}{'last_settings'}} > 15;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"data"}{"last_settings"};} > 15 0 0 0
82 }
83  
84 1 1;
« Juliagraph/Compute/Mapping.pm ↑ Summary Juliagraph/Settings.pm »