line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Lite; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
52096
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
156
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
66
|
|
5
|
2
|
|
|
2
|
|
10
|
use Fcntl qw/:flock/; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
1265
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(load_config set_config_separator); |
11
|
|
|
|
|
|
|
our @EXPORT = qw(); |
12
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %separator; |
15
|
|
|
|
|
|
|
$separator{'kv'} = "="; |
16
|
|
|
|
|
|
|
$separator{'comment'} = "#"; |
17
|
|
|
|
|
|
|
$separator{'line'} = "\n"; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub set_config_separator |
20
|
|
|
|
|
|
|
{ |
21
|
3
|
|
|
3
|
1
|
16
|
my $kind = shift; |
22
|
3
|
|
|
|
|
6
|
my $str = shift; |
23
|
3
|
|
|
|
|
10
|
$separator{$kind} = $str; |
24
|
3
|
|
|
|
|
7
|
return 1; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub load_config |
28
|
|
|
|
|
|
|
{ |
29
|
4
|
|
|
4
|
1
|
8100
|
my $config_filename = shift; |
30
|
4
|
100
|
|
|
|
302
|
open my $fh,"<", $config_filename or return "no config file found"; |
31
|
2
|
|
|
|
|
19
|
flock $fh, LOCK_SH; |
32
|
2
|
|
|
|
|
5
|
my $config_string = do { local $/ ; <$fh> }; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
97
|
|
33
|
2
|
|
|
|
|
15
|
flock $fh, LOCK_UN; |
34
|
2
|
|
|
|
|
39
|
close $fh; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
60
|
my @config_array = split /$separator{'line'}/, $config_string; |
37
|
2
|
|
|
|
|
7
|
my %config_hash; |
38
|
2
|
|
|
|
|
6
|
foreach ( @config_array ) |
39
|
|
|
|
|
|
|
{ |
40
|
22
|
100
|
|
|
|
91
|
next unless $_ =~ /$separator{'kv'}/; |
41
|
13
|
100
|
|
|
|
73
|
next if $_ =~ /^$separator{'comment'}/; |
42
|
12
|
|
|
|
|
136
|
my ($k, $v) = $_ =~ /\s*(.+?)$separator{'kv'}(.+?)\s*$/; |
43
|
12
|
|
|
|
|
45
|
$config_hash{$k} = $v; |
44
|
|
|
|
|
|
|
} |
45
|
2
|
|
|
|
|
31
|
return %config_hash; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
__END__ |