Installer/Utils/Config.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 83.3% 15 / 18 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 92.7% 77 / 83 CC 12 SCAR 20.9
CC
12
Cov
93%
_rc_config
12.2
BEGIN
1.0
BEGIN
1.0
CRAP 8.1
« Installer.pm ↑ Summary Installer/Utils/File.pm »
1 package OPM::Installer::Utils::Config;
2  
3 # ABSTRACT: Read config file for OPM::Installer
4  
5 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 15 our $VERSION = '1.0.1'; # VERSION
9  
10 15 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 15 has rc_config => ( is => 'ro', lazy => 1, default => \&_rc_config );
17 15 has conf => ( is => 'ro' );
18  
19 5 ▶sub _rc_config {
Subroutine _rc_config: called CC=12 SCAR=25.0
20 5 my ($self) = @_;
21  
22 5 my $dot_file = File::Spec->catfile(
23 File::HomeDir->my_home,
24 '.opminstaller.rc'
25 );
26  
27 5 ▶ if ( $self->conf && -f $self->conf ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->conf and -f $self->conf) { } 2 3 5
elsif ($self->conf) { } 1 2 3
Condition100%3/3
$self->conf and -f $self->conf
!ll&&!rl&&r
212
MC/DC100%2/2
$self->conf and -f $self->conf
$self->conf -f $self->conf
Truth table100%3/3
A and B
A= $self->confB= -f $self->conf
ABresult
0X0
100
111
28 2 $dot_file = $self->conf;
29 }
30 elsif ( $self->conf ) {
31 1 croak 'Config file ' . $self->conf . ' does not exist';
32 }
33  
34 4 my %config;
35 4 ▶ if ( -f $dot_file && open my $fh, '<', $dot_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $dot_file and open my $fh, "<", $dot_file) 3 1 4
Condition66%2/3
-f $dot_file and open my $fh, "<", $dot_file
!ll&&!rl&&r
103
MC/DC50%1/2
-f $dot_file and open my $fh, "<", $dot_file
-f $dot_file open my $fh, "<", $dot_file
Truth table66%2/3
A and B
A= -f $dot_fileB= open my $fh, "<", $dot_file
ABresult
0X0
100
111
36 3 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 9 3 12
37 9 chomp $line;
38 9 ▶ next if $line =~ m{\A\s*\#};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A\s*\#/ 0 9 9
39 9 ▶ next if $line =~ m{\A\s*\z};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A\s*\z/ 0 9 9
40  
41 9 my ($key, $value) = split /\s*=\s*/, $line;
42 9 $key = lc $key;
43  
44 9 ▶ if ( $key eq 'repository' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq 'repository') { } 6 3 9
elsif ($key eq 'path') { } 3 0 3
45 6 push @{ $config{$key} }, $value;
46 }
47 elsif ( $key eq 'path' ) {
48 3 ▶ if ( !File::Spec->file_name_is_absolute( $value ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($value)) 1 2 3
49 1 my $dir = dirname $dot_file;
50 1 $value = File::Spec->rel2abs(
51 File::Spec->catdir( $dir, $value ),
52 );
53 }
54  
55 3 $config{$key} = $value;
56 }
57 else {
58 0 $config{$key} = $value;
59 }
60 }
61 }
62  
63 4 return \%config;
64 }
65  
66 15 1;
67  
68 __END__
« Installer.pm ↑ Summary Installer/Utils/File.pm »