| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBIx::dbMan::Config; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
18
|
use strict; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
85
|
|
|
4
|
3
|
|
|
3
|
|
958
|
use locale; |
|
|
3
|
|
|
|
|
1264
|
|
|
|
3
|
|
|
|
|
14
|
|
|
5
|
3
|
|
|
3
|
|
134
|
use vars qw/$AUTOLOAD/; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
168
|
|
|
6
|
3
|
|
|
3
|
|
1044
|
use POSIX; |
|
|
3
|
|
|
|
|
16798
|
|
|
|
3
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
1; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
14
|
0
|
|
|
|
|
|
my $obj = bless { @_ }, $class; |
|
15
|
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
$obj->{config} = {}; |
|
17
|
0
|
|
0
|
|
|
|
$obj->{configfile} = $obj->{-file} || $obj->_configfile(); |
|
18
|
0
|
0
|
|
|
|
|
$obj->_load if $obj->{configfile}; |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return $obj; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _bhashes { |
|
24
|
0
|
|
|
0
|
|
|
my $line = shift; |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$line =~ s/#/\\#/g; |
|
27
|
0
|
|
|
|
|
|
return $line; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _load { |
|
31
|
0
|
|
|
0
|
|
|
my $obj = shift; |
|
32
|
0
|
0
|
|
|
|
|
if (open F,$obj->{configfile}) { |
|
33
|
0
|
|
|
|
|
|
while () { |
|
34
|
0
|
|
|
|
|
|
my $key; my $value; |
|
35
|
0
|
|
|
|
|
|
chomp; |
|
36
|
0
|
|
|
|
|
|
s/\\/\\\\/g; # double backslashes |
|
37
|
0
|
|
|
|
|
|
s/^(['"])(.*?)([^\\])\1/$1.(_bhashes($2.$3)).$1/eg; |
|
|
0
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
s/([^\\])(['"])(.*?)([^\\])\2/$1.$2.(_bhashes($3.$4)).$2/eg; |
|
|
0
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# backslash # in '' |
|
40
|
0
|
|
|
|
|
|
s/^#.*$//; # whole-line comment |
|
41
|
0
|
|
|
|
|
|
s/([^\\])#.*$/$1/; # other comment |
|
42
|
0
|
|
|
|
|
|
s/\\#/#/g; # unbackslash # |
|
43
|
0
|
|
|
|
|
|
s/\\\\/\\/g; # single backslashes |
|
44
|
0
|
|
|
|
|
|
s/^\s+//; # starting whitespaces |
|
45
|
0
|
|
|
|
|
|
s/\s+$//; # ending whitespaces |
|
46
|
0
|
0
|
|
|
|
|
next unless $_; # empty line |
|
47
|
0
|
0
|
|
|
|
|
if (/^(\S+)\s+(.*)$/) { |
|
48
|
0
|
|
|
|
|
|
($key,$value) = ($1,$2); |
|
49
|
|
|
|
|
|
|
} else { |
|
50
|
0
|
|
|
|
|
|
($key,$value) = ($_,''); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
0
|
|
|
|
|
|
$value =~ s/^(['"])(.*)\1$/$2/; # quoted line |
|
53
|
0
|
|
|
|
|
|
push @{$obj->{config}->{$key}},$value; |
|
|
0
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
|
55
|
0
|
|
|
|
|
|
close F; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub merge { |
|
60
|
0
|
|
|
0
|
0
|
|
my ($obj,$config) = @_; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
return 0 unless $config; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
for my $tag ($config->all_tags) { |
|
65
|
0
|
0
|
|
|
|
|
if ( ref $config->$tag eq "ARRAY" ) { |
|
66
|
0
|
|
|
|
|
|
push @{$obj->{config}->{$tag}}, @{$config->$tag}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} else { |
|
68
|
0
|
|
|
|
|
|
push @{$obj->{config}->{$tag}}, $config->$tag; |
|
|
0
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
} |
|
71
|
0
|
|
|
|
|
|
return 1; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _configfile { |
|
75
|
0
|
|
|
0
|
|
|
my $obj = shift; |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $res = $ENV{DBMAN_CONFIG}; |
|
78
|
0
|
0
|
0
|
|
|
|
return $res if $res and -e $res; |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$res = $ENV{HOME}.'/.dbman/config'; |
|
81
|
0
|
0
|
|
|
|
|
return $res if -e $res; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return '/etc/dbman.conf'; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub all_tags { |
|
87
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
|
88
|
0
|
|
|
|
|
|
return keys %{$obj->{config}}; |
|
|
0
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
92
|
0
|
|
|
0
|
|
|
my $obj = shift; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
$AUTOLOAD =~ s/^DBIx::dbMan::Config:://; |
|
95
|
0
|
|
|
|
|
|
my $res = $obj->{config}->{$AUTOLOAD}; |
|
96
|
0
|
0
|
|
|
|
|
if (defined $res) { |
|
97
|
0
|
0
|
0
|
|
|
|
if (ref $res and scalar @$res > 1) { |
|
98
|
0
|
0
|
|
|
|
|
return wantarray ? @$res : $res; |
|
99
|
|
|
|
|
|
|
} else { |
|
100
|
0
|
0
|
|
|
|
|
return wantarray ? @$res : $res->[0]; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} else { |
|
103
|
0
|
|
|
|
|
|
return undef; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |