line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Connection::Sql; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
1285
|
use Moose; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
31
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Mail::MtPolicyd::Connection'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Connection pool sql connection object |
8
|
|
|
|
|
|
|
our $VERSION = '2.02'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
18466
|
use DBI; |
|
5
|
|
|
|
|
11331
|
|
|
5
|
|
|
|
|
912
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'dsn' => ( is => 'ro', isa => 'Str', required => 1 ); |
14
|
|
|
|
|
|
|
has 'user' => ( is => 'ro', isa => 'Str', default => '' ); |
15
|
|
|
|
|
|
|
has 'password' => ( is => 'ro', isa => 'Str', default => '' ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'handle' => ( is => 'rw', isa => 'DBI::db', lazy => 1, |
18
|
|
|
|
|
|
|
default => sub { |
19
|
|
|
|
|
|
|
my $self = shift; |
20
|
|
|
|
|
|
|
return $self->_create_handle; |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
handles => [ 'disconnect' ], |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _create_handle { |
26
|
4
|
|
|
4
|
|
7
|
my $self = shift; |
27
|
4
|
|
|
|
|
101
|
my $handle = DBI->connect( |
28
|
|
|
|
|
|
|
$self->dsn, |
29
|
|
|
|
|
|
|
$self->user, |
30
|
|
|
|
|
|
|
$self->password, |
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
RaiseError => 1, |
33
|
|
|
|
|
|
|
PrintError => 0, |
34
|
|
|
|
|
|
|
AutoCommit => 1, |
35
|
|
|
|
|
|
|
mysql_auto_reconnect => 1, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
); |
38
|
4
|
|
|
|
|
35666
|
return $handle; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub reconnect { |
42
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
43
|
0
|
|
|
|
|
|
$self->handle( $self->_create_handle ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=encoding UTF-8 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Mail::MtPolicyd::Connection::Sql - Connection pool sql connection object |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 VERSION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
version 2.02 |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
<Connection db> |
65
|
|
|
|
|
|
|
module = "Sql" |
66
|
|
|
|
|
|
|
# see perldoc DBI for syntax of dsn connection string |
67
|
|
|
|
|
|
|
dsn = "dbi:SQLite:dbname=/var/lib/mtpolicyd/mtpolicyd.sqlite" |
68
|
|
|
|
|
|
|
# user = "mtpolicyd" |
69
|
|
|
|
|
|
|
# user = "secret" |
70
|
|
|
|
|
|
|
</Connection> |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 PARAMETERS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=over |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item dsn (required) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
A perl DBI connection string. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Examples: |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
dbi:SQLite:dbname=/var/lib/mtpolicyd/mtpolicyd.sqlite |
83
|
|
|
|
|
|
|
dbi:SQLite::memory: |
84
|
|
|
|
|
|
|
DBI:mysql:database=test;host=localhost |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
see L<DBI> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item user (default: '') |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
A username if required for connection. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item password (default: '') |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
A password if required for user/connection. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=back |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHOR |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This is free software, licensed under: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |