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