line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Dispatch::DBI; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
183093
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
110
|
|
4
|
3
|
|
|
3
|
|
17
|
use vars qw($VERSION); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
168
|
|
5
|
|
|
|
|
|
|
$VERSION = 0.02; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
3619
|
use Log::Dispatch 2.00; |
|
3
|
|
|
|
|
51698
|
|
|
3
|
|
|
|
|
170
|
|
8
|
3
|
|
|
3
|
|
34
|
use base qw(Log::Dispatch::Output); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
3321
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
8556
|
use DBI; |
|
3
|
|
|
|
|
20423
|
|
|
3
|
|
|
|
|
1180
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
1
|
|
my($proto, %params) = @_; |
14
|
0
|
|
0
|
|
|
|
my $class = ref $proto || $proto; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
17
|
0
|
|
|
|
|
|
$self->_basic_init(%params); |
18
|
0
|
|
|
|
|
|
$self->_init(%params); |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _init { |
24
|
0
|
|
|
0
|
|
|
my $self = shift; |
25
|
0
|
|
|
|
|
|
my %params = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# set parameters |
28
|
0
|
0
|
|
|
|
|
if ($params{dbh}) { |
29
|
0
|
|
|
|
|
|
$self->{dbh} = $params{dbh}; |
30
|
|
|
|
|
|
|
} else { |
31
|
0
|
0
|
|
|
|
|
$self->{dbh} = DBI->connect(@params{qw(datasource username password)}) |
32
|
|
|
|
|
|
|
or die $DBI::errstr; |
33
|
0
|
|
|
|
|
|
$self->{_mine} = 1; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
0
|
|
|
|
$self->{table} = $params{table} || 'log'; |
37
|
0
|
|
|
|
|
|
$self->{sth} = $self->create_statement; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub create_statement { |
41
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
42
|
0
|
|
|
|
|
|
return $self->{dbh}->prepare(<<"SQL"); |
43
|
|
|
|
|
|
|
INSERT INTO $self->{table} (level, message) VALUES (?, ?) |
44
|
|
|
|
|
|
|
SQL |
45
|
|
|
|
|
|
|
; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub log_message { |
49
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
50
|
0
|
|
|
|
|
|
my %params = @_; |
51
|
0
|
|
|
|
|
|
$self->{sth}->execute(@params{qw(level message)}); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub DESTROY { |
55
|
0
|
|
|
0
|
|
|
my $self = shift; |
56
|
0
|
0
|
0
|
|
|
|
if ($self->{_mine} && $self->{dbh}) { |
57
|
0
|
|
|
|
|
|
$self->{dbh}->disconnect; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
__END__ |