line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::File; |
2
|
2
|
|
|
2
|
|
9173
|
use warnings; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
78
|
|
3
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
39
|
|
4
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
102
|
|
5
|
2
|
|
|
2
|
|
13
|
use Exporter; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
79
|
|
6
|
2
|
|
|
2
|
|
1030
|
use IO::File; |
|
2
|
|
|
|
|
17800
|
|
|
2
|
|
|
|
|
229
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
14
|
use vars qw($VERSION @ISA @EXPORT_OK); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1137
|
|
9
|
|
|
|
|
|
|
@ISA = qw/Exporter/; |
10
|
|
|
|
|
|
|
@EXPORT_OK = qw/read_config_file/; |
11
|
|
|
|
|
|
|
$VERSION = '1.54'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub read_config_file($) { |
14
|
2
|
|
|
2
|
1
|
720
|
my ( $conf, $file, $fh, $line_num ); |
15
|
2
|
|
|
|
|
4
|
$file = shift; |
16
|
2
|
50
|
|
|
|
12
|
$fh = IO::File->new( $file, 'r' ) |
17
|
|
|
|
|
|
|
or croak "Can't read configuration in $file: $!\n"; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
66
|
|
|
276
|
while ( ++$line_num and my $line = $fh->getline ) { |
20
|
11
|
|
|
|
|
298
|
my ( $orig_line, $conf_ele, $conf_data ); |
21
|
11
|
|
|
|
|
19
|
chomp $line; |
22
|
11
|
|
|
|
|
16
|
$orig_line = $line; |
23
|
|
|
|
|
|
|
|
24
|
11
|
100
|
|
|
|
53
|
next if $line =~ m/^\s*#/; |
25
|
10
|
|
|
|
|
25
|
$line =~ s/(?
|
26
|
10
|
|
|
|
|
16
|
$line =~ s/\\#/#/g; |
27
|
10
|
50
|
|
|
|
26
|
next if $line =~ m/^\s*$/; |
28
|
10
|
|
|
|
|
21
|
$line =~ s{\$(\w+)}{ |
29
|
2
|
50
|
|
|
|
13
|
exists($conf->{$1}) ? $conf->{$1} : "\$$1" |
30
|
|
|
|
|
|
|
}gsex; |
31
|
|
|
|
|
|
|
|
32
|
10
|
100
|
|
|
|
60
|
unless ( $line =~ m/\s*([^\s=]+)\s*=\s*(.*?)\s*$/ ) { |
33
|
1
|
|
|
|
|
16
|
warn "Line format invalid at line $line_num: '$orig_line'"; |
34
|
1
|
|
|
|
|
25
|
next; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
9
|
|
|
|
|
27
|
( $conf_ele, $conf_data ) = ( $1, $2 ); |
38
|
9
|
100
|
|
|
|
27
|
unless ( $conf_ele =~ /^[\]\[A-Za-z0-9_-]+$/ ) { |
39
|
1
|
|
|
|
|
74
|
warn "Invalid characters in key $conf_ele at line $line_num" |
40
|
|
|
|
|
|
|
. " - Ignoring"; |
41
|
1
|
|
|
|
|
32
|
next; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
$conf_ele = |
44
|
8
|
|
|
|
|
43
|
'$conf->{"' . join( '"}->{"', split /[][]+/, $conf_ele ) . '"}'; |
45
|
8
|
|
|
|
|
22
|
$conf_data =~ s!([\\\'])!\\$1!g; |
46
|
8
|
|
|
|
|
375
|
eval "$conf_ele = '$conf_data'"; |
47
|
|
|
|
|
|
|
} |
48
|
2
|
|
|
|
|
90
|
$fh->close; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
100
|
|
|
45
|
return $conf // {}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |