| 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
Condition100%3/3
$self->conf and -f $self->conf
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
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
-f $dot_file and open my $fh, "<", $dot_file
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
| |||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | 9 | chomp $line; | |||||||||||||||||||||||||||||||
| 38 | 9 | ▶ | next if $line =~ m{\A\s*\#}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 9 | ▶ | next if $line =~ m{\A\s*\z}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||