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
|
|
468963
|
use strict; |
|
15
|
|
|
|
|
87
|
|
|
15
|
|
|
|
|
381
|
|
6
|
15
|
|
|
15
|
|
104
|
use warnings; |
|
15
|
|
|
|
|
26
|
|
|
15
|
|
|
|
|
567
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0.0'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
15
|
|
|
15
|
|
97
|
use Carp qw(croak); |
|
15
|
|
|
|
|
26
|
|
|
15
|
|
|
|
|
692
|
|
11
|
15
|
|
|
15
|
|
82
|
use File::Basename; |
|
15
|
|
|
|
|
37
|
|
|
15
|
|
|
|
|
746
|
|
12
|
15
|
|
|
15
|
|
2287
|
use File::HomeDir; |
|
15
|
|
|
|
|
25156
|
|
|
15
|
|
|
|
|
800
|
|
13
|
15
|
|
|
15
|
|
92
|
use File::Spec; |
|
15
|
|
|
|
|
24
|
|
|
15
|
|
|
|
|
392
|
|
14
|
15
|
|
|
15
|
|
2446
|
use Moo; |
|
15
|
|
|
|
|
52176
|
|
|
15
|
|
|
|
|
99
|
|
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
|
|
9375
|
my ($self) = @_; |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
|
|
45
|
my $dot_file = File::Spec->catfile( |
23
|
|
|
|
|
|
|
File::HomeDir->my_home, |
24
|
|
|
|
|
|
|
'.opminstaller.rc' |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
5
|
100
|
100
|
|
|
417
|
if ( $self->conf && -f $self->conf ) { |
|
|
100
|
|
|
|
|
|
28
|
2
|
|
|
|
|
13
|
$dot_file = $self->conf; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif ( $self->conf ) { |
31
|
1
|
|
|
|
|
163
|
croak 'Config file ' . $self->conf . ' does not exist'; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
4
|
|
|
|
|
11
|
my %config; |
35
|
4
|
100
|
66
|
|
|
247
|
if ( -f $dot_file && open my $fh, '<', $dot_file ) { |
36
|
3
|
|
|
|
|
129
|
while ( my $line = <$fh> ) { |
37
|
9
|
|
|
|
|
22
|
chomp $line; |
38
|
9
|
50
|
|
|
|
25
|
next if $line =~ m{\A\s*\#}; |
39
|
9
|
50
|
|
|
|
36
|
next if $line =~ m{\A\s*\z}; |
40
|
|
|
|
|
|
|
|
41
|
9
|
|
|
|
|
45
|
my ($key, $value) = split /\s*=\s*/, $line; |
42
|
9
|
|
|
|
|
45
|
$key = lc $key; |
43
|
|
|
|
|
|
|
|
44
|
9
|
100
|
|
|
|
72
|
if ( $key eq 'repository' ) { |
|
|
50
|
|
|
|
|
|
45
|
6
|
|
|
|
|
16
|
push @{ $config{$key} }, $value; |
|
6
|
|
|
|
|
30
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ( $key eq 'path' ) { |
48
|
3
|
100
|
|
|
|
51
|
if ( !File::Spec->file_name_is_absolute( $value ) ) { |
49
|
1
|
|
|
|
|
27
|
my $dir = dirname $dot_file; |
50
|
1
|
|
|
|
|
26
|
$value = File::Spec->rel2abs( |
51
|
|
|
|
|
|
|
File::Spec->catdir( $dir, $value ), |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
40
|
$config{$key} = $value; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
0
|
$config{$key} = $value; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
68
|
return \%config; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |