line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OPM::Installer::Utils::Config; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Read config file for OPM::Installer |
4
|
|
|
|
|
|
|
|
5
|
15
|
|
|
15
|
|
431579
|
use strict; |
|
15
|
|
|
|
|
71
|
|
|
15
|
|
|
|
|
370
|
|
6
|
15
|
|
|
15
|
|
105
|
use warnings; |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
535
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
15
|
|
|
15
|
|
70
|
use Carp qw(croak); |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
734
|
|
11
|
15
|
|
|
15
|
|
88
|
use File::Basename; |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
748
|
|
12
|
15
|
|
|
15
|
|
2145
|
use File::HomeDir; |
|
15
|
|
|
|
|
23143
|
|
|
15
|
|
|
|
|
658
|
|
13
|
15
|
|
|
15
|
|
84
|
use File::Spec; |
|
15
|
|
|
|
|
27
|
|
|
15
|
|
|
|
|
283
|
|
14
|
15
|
|
|
15
|
|
2213
|
use Moo; |
|
15
|
|
|
|
|
46985
|
|
|
15
|
|
|
|
|
81
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has rc_config => ( is => 'ro', lazy => 1, default => \&_rc_config ); |
17
|
|
|
|
|
|
|
has conf => ( is => 'ro' ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _rc_config { |
20
|
5
|
|
|
5
|
|
8461
|
my ($self) = @_; |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
|
|
43
|
my $dot_file = File::Spec->catfile( |
23
|
|
|
|
|
|
|
File::HomeDir->my_home, |
24
|
|
|
|
|
|
|
'.opminstaller.rc' |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
5
|
100
|
100
|
|
|
425
|
if ( $self->conf && -f $self->conf ) { |
|
|
100
|
|
|
|
|
|
28
|
2
|
|
|
|
|
12
|
$dot_file = $self->conf; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif ( $self->conf ) { |
31
|
1
|
|
|
|
|
160
|
croak 'Config file ' . $self->conf . ' does not exist'; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
4
|
|
|
|
|
9
|
my %config; |
35
|
4
|
100
|
66
|
|
|
203
|
if ( -f $dot_file && open my $fh, '<', $dot_file ) { |
36
|
3
|
|
|
|
|
127
|
while ( my $line = <$fh> ) { |
37
|
9
|
|
|
|
|
21
|
chomp $line; |
38
|
9
|
50
|
|
|
|
24
|
next if $line =~ m{\A\s*\#}; |
39
|
9
|
50
|
|
|
|
31
|
next if $line =~ m{\A\s*\z}; |
40
|
|
|
|
|
|
|
|
41
|
9
|
|
|
|
|
40
|
my ($key, $value) = split /\s*=\s*/, $line; |
42
|
9
|
|
|
|
|
37
|
$key = lc $key; |
43
|
|
|
|
|
|
|
|
44
|
9
|
100
|
|
|
|
51
|
if ( $key eq 'repository' ) { |
|
|
50
|
|
|
|
|
|
45
|
6
|
|
|
|
|
22
|
push @{ $config{$key} }, $value; |
|
6
|
|
|
|
|
30
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ( $key eq 'path' ) { |
48
|
3
|
100
|
|
|
|
48
|
if ( !File::Spec->file_name_is_absolute( $value ) ) { |
49
|
1
|
|
|
|
|
25
|
my $dir = dirname $dot_file; |
50
|
1
|
|
|
|
|
25
|
$value = File::Spec->rel2abs( |
51
|
|
|
|
|
|
|
File::Spec->catdir( $dir, $value ), |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
38
|
$config{$key} = $value; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
0
|
$config{$key} = $value; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
55
|
return \%config; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |