line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::DB; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$Config::DB::VERSION = '0.2'; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
87467
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
97
|
|
6
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
69
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
14
|
use Carp; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
235
|
|
9
|
3
|
|
|
3
|
|
1459
|
use Config::DB::Record; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
68
|
|
10
|
3
|
|
|
3
|
|
1430
|
use Config::DB::Table; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
64
|
|
11
|
3
|
|
|
3
|
|
8056
|
use DBI; |
|
3
|
|
|
|
|
63125
|
|
|
3
|
|
|
|
|
3065
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
13
|
|
|
13
|
1
|
188380
|
my ( $class, %pars ) = @_; |
15
|
13
|
|
|
|
|
64
|
my $self = { %pars, read => 0, values => {} }; |
16
|
|
|
|
|
|
|
|
17
|
13
|
100
|
100
|
|
|
427
|
croak __PACKAGE__ . "::new: wrong call" if !defined $class || $class eq ''; |
18
|
|
|
|
|
|
|
|
19
|
11
|
|
|
|
|
19
|
eval { |
20
|
11
|
100
|
|
|
|
40
|
die |
21
|
|
|
|
|
|
|
if $class->check_Config_DB_hineritance ne |
22
|
|
|
|
|
|
|
'check_Config_DB_hineritance'; |
23
|
|
|
|
|
|
|
}; |
24
|
11
|
100
|
|
|
|
248
|
croak __PACKAGE__ . "::new: '$class' does not hinerit 'Config::DB'" |
25
|
|
|
|
|
|
|
if $@ ne ''; |
26
|
|
|
|
|
|
|
|
27
|
9
|
100
|
|
|
|
117
|
croak __PACKAGE__ . "::new: missing 'connect' paramenter" |
28
|
|
|
|
|
|
|
if !defined $self->{connect}; |
29
|
8
|
100
|
|
|
|
163
|
croak __PACKAGE__ |
30
|
|
|
|
|
|
|
. "::new: 'connect' paramenter is not a reference to ARRAY" |
31
|
|
|
|
|
|
|
if ref $self->{connect} ne 'ARRAY'; |
32
|
7
|
100
|
|
|
|
171
|
croak __PACKAGE__ . "::new: missing 'tables' paramenter" |
33
|
|
|
|
|
|
|
if !defined $self->{tables}; |
34
|
6
|
100
|
|
|
|
156
|
croak __PACKAGE__ . "::new: 'tables' paramenter is not a reference to HASH" |
35
|
|
|
|
|
|
|
if ref $self->{tables} ne 'HASH'; |
36
|
5
|
|
|
|
|
111
|
croak __PACKAGE__ . "::new: no tables defined" |
37
|
5
|
100
|
|
|
|
86
|
if 0 == scalar keys %{ $self->{tables} }; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
62
|
return bless $self, $class; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
our $AUTOLOAD; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub AUTOLOAD { |
45
|
0
|
|
|
0
|
|
0
|
my ( $self, @pars ) = @_; |
46
|
0
|
|
|
|
|
0
|
my $name = $AUTOLOAD; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
$name =~ s/.*://; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
0
|
croak "Can't locate object method \"$name\" via package \"" |
51
|
|
|
|
|
|
|
. __PACKAGE__ . '"' |
52
|
|
|
|
|
|
|
unless $name =~ /^_/; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
$name =~ s/^_//; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
return $self->get( $name, @pars ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
0
|
|
0
|
sub DESTROY { |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub check_Config_DB_hineritance { |
63
|
9
|
|
|
9
|
0
|
52
|
return 'check_Config_DB_hineritance'; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get { |
67
|
2
|
|
|
2
|
1
|
3437
|
my ( $self, $table, $key, $field ) = @_; |
68
|
|
|
|
|
|
|
|
69
|
2
|
50
|
|
|
|
18
|
$self->read unless $self->{read}; |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
0
|
croak __PACKAGE__ . "::get: missing table parameter" unless defined $table; |
72
|
0
|
0
|
|
|
|
0
|
croak __PACKAGE__ . "::get: unknown configuration table '$table'" |
73
|
|
|
|
|
|
|
unless exists $self->{values}->{$table}; |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
0
|
return $self->{values}->{$table} unless defined $key; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
0
|
croak __PACKAGE__ |
78
|
|
|
|
|
|
|
. "::get: missing key '$key' in configuration table '$table'" |
79
|
|
|
|
|
|
|
unless exists $self->{values}->{$table}->{$key}; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
0
|
return $self->{values}->{$table}->{$key} unless defined $field; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
0
|
croak __PACKAGE__ |
84
|
|
|
|
|
|
|
. "::get: unknown field '$field' for configuration table '$table'" |
85
|
|
|
|
|
|
|
unless exists $self->{values}->{$table}->{$key}->{$field}; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
0
|
return $self->{values}->{$table}->{$key}->{$field}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub read { |
91
|
7
|
|
|
7
|
1
|
7884
|
my ($self) = @_; |
92
|
7
|
|
|
|
|
15
|
my @connect = @{ $self->{connect} }; |
|
7
|
|
|
|
|
35
|
|
93
|
7
|
100
|
|
|
|
11
|
my %attr = %{ $connect[3] || {} }; |
|
7
|
|
|
|
|
47
|
|
94
|
7
|
|
|
|
|
14
|
my $dbh; |
95
|
|
|
|
|
|
|
|
96
|
7
|
|
|
|
|
19
|
$attr{PrintError} = 0; |
97
|
7
|
|
|
|
|
15
|
$attr{RaiseError} = 1; |
98
|
7
|
|
|
|
|
15
|
$connect[3] = \%attr; |
99
|
|
|
|
|
|
|
|
100
|
7
|
|
|
|
|
13
|
eval { $dbh = DBI->connect(@connect); }; |
|
7
|
|
|
|
|
305
|
|
101
|
7
|
100
|
|
|
|
5160
|
croak "$@\n" . __PACKAGE__ . "::read: can't connect" if $@; |
102
|
|
|
|
|
|
|
|
103
|
6
|
|
|
|
|
11
|
foreach my $table ( keys %{ $self->{tables} } ) { |
|
6
|
|
|
|
|
27
|
|
104
|
6
|
|
|
|
|
10
|
my $t; |
105
|
|
|
|
|
|
|
|
106
|
6
|
|
|
|
|
8
|
eval { |
107
|
6
|
|
|
|
|
78
|
$t = $dbh->selectall_hashref( |
108
|
|
|
|
|
|
|
"SELECT $self->{tables}->{$table} AS dbcfg_key, $table.* FROM $table", |
109
|
|
|
|
|
|
|
'dbcfg_key' |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
}; |
112
|
6
|
50
|
|
|
|
14325
|
croak "$@\n" . __PACKAGE__ . "::read: reading '$table' table" if $@; |
113
|
0
|
|
|
|
|
|
$self->{values}->{$table} = $t; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
foreach my $key ( keys %$t ) { |
116
|
0
|
|
|
|
|
|
delete $t->{$key}->{dbcfg_key}; |
117
|
0
|
|
|
|
|
|
bless $t->{$key}, 'Config::DB::Record'; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
bless $t, 'Config::DB::Table'; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$self->{read} = 1; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |