line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Autocache::Config; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
23
|
use strict; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
114
|
|
4
|
5
|
|
|
5
|
|
14
|
use warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
115
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
13
|
use base 'Autocache::Config::Node'; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
1903
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
25
|
use Carp; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
286
|
|
9
|
5
|
|
|
5
|
|
2353
|
use IO::File; |
|
5
|
|
|
|
|
33234
|
|
|
5
|
|
|
|
|
446
|
|
10
|
5
|
|
|
5
|
|
2735
|
use Data::Dumper; |
|
5
|
|
|
|
|
33580
|
|
|
5
|
|
|
|
|
1764
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new |
13
|
|
|
|
|
|
|
{ |
14
|
5
|
|
|
5
|
0
|
11
|
my ($class,$filename) = @_; |
15
|
5
|
|
|
|
|
59
|
my $self = $class->SUPER::new( '' ); |
16
|
|
|
|
|
|
|
|
17
|
5
|
100
|
|
|
|
17
|
if( $filename ) |
18
|
|
|
|
|
|
|
{ |
19
|
4
|
50
|
|
|
|
16
|
confess "configuration file supplied cannot be found/read" |
20
|
|
|
|
|
|
|
unless _file_good( $filename ); |
21
|
4
|
|
|
|
|
22
|
$self->_load_config_file( $filename ); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else |
24
|
|
|
|
|
|
|
{ |
25
|
1
|
|
|
|
|
4
|
$filename = _locate_config_file(); |
26
|
1
|
50
|
|
|
|
3
|
$self->_load_config_file( $filename ) |
27
|
|
|
|
|
|
|
if defined $filename; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
5
|
|
|
|
|
17
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _load_config_file |
35
|
|
|
|
|
|
|
{ |
36
|
4
|
|
|
4
|
|
5
|
my ($self,$filename) = @_; |
37
|
|
|
|
|
|
|
|
38
|
4
|
50
|
|
|
|
36
|
my $fh = IO::File->new( $filename, 'r' ) |
39
|
|
|
|
|
|
|
or confess "cannot open file for reading '$filename'"; |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
484
|
while( my $line = <$fh> ) |
42
|
|
|
|
|
|
|
{ |
43
|
27
|
100
|
|
|
|
102
|
next if $line =~ /^\s*$/; |
44
|
20
|
100
|
|
|
|
46
|
next if $line =~ /^#/; |
45
|
16
|
50
|
|
|
|
45
|
next unless $line =~ /^autocache./; |
46
|
16
|
|
|
|
|
47
|
$line =~ s/^autocache.//; |
47
|
16
|
|
|
|
|
25
|
chomp $line; |
48
|
16
|
|
|
|
|
66
|
my ( $key, $value ) = split /\s+=\s+/, $line, 2; |
49
|
16
|
|
|
|
|
62
|
$self->get_node( $key )->value( $value ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
40
|
$fh->close; |
53
|
4
|
|
|
|
|
50
|
return 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _locate_config_file |
57
|
|
|
|
|
|
|
{ |
58
|
1
|
|
|
1
|
|
7
|
my $filename = sprintf '%s/etc/autocache.conf', $ENV{HOME}; |
59
|
|
|
|
|
|
|
|
60
|
1
|
50
|
|
|
|
4
|
if( _file_good( $filename ) ) |
61
|
|
|
|
|
|
|
{ |
62
|
0
|
|
|
|
|
0
|
return $filename; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
2
|
$filename = '/etc/autocache.conf'; |
66
|
|
|
|
|
|
|
|
67
|
1
|
50
|
|
|
|
35
|
if( _file_good( $filename ) ) |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
|
|
0
|
return $filename; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
2
|
return undef; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _file_good |
76
|
|
|
|
|
|
|
{ |
77
|
6
|
|
66
|
6
|
|
217
|
return ( -e $_[0] && -r _ ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |