| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::SqlConnection; |
|
2
|
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
85292
|
use strict; |
|
|
8
|
|
|
|
|
18
|
|
|
|
8
|
|
|
|
|
248
|
|
|
4
|
8
|
|
|
8
|
|
4182
|
use MooseX::Singleton; |
|
|
8
|
|
|
|
|
1646117
|
|
|
|
8
|
|
|
|
|
49
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: singleton class to hold the sql database connection |
|
7
|
|
|
|
|
|
|
our $VERSION = '1.23'; # VERSION |
|
8
|
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
245304
|
use DBI; |
|
|
8
|
|
|
|
|
147772
|
|
|
|
8
|
|
|
|
|
2353
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'dsn' => ( is => 'ro', isa => 'Str', required => 1 ); |
|
12
|
|
|
|
|
|
|
has 'user' => ( is => 'ro', isa => 'Str', required => 1 ); |
|
13
|
|
|
|
|
|
|
has 'password' => ( is => 'ro', isa => 'Str', required => 1 ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'dbh' => ( is => 'rw', isa => 'DBI::db', lazy => 1, |
|
16
|
|
|
|
|
|
|
default => sub { |
|
17
|
|
|
|
|
|
|
my $self = shift; |
|
18
|
|
|
|
|
|
|
return $self->_create_dbh; |
|
19
|
|
|
|
|
|
|
}, |
|
20
|
|
|
|
|
|
|
handles => [ 'disconnect' ], |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _create_dbh { |
|
24
|
5
|
|
|
5
|
|
75
|
my $self = shift; |
|
25
|
5
|
|
|
|
|
200
|
my $dbh = DBI->connect( |
|
26
|
|
|
|
|
|
|
$self->dsn, |
|
27
|
|
|
|
|
|
|
$self->user, |
|
28
|
|
|
|
|
|
|
$self->password, |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
|
|
|
|
|
|
RaiseError => 1, |
|
31
|
|
|
|
|
|
|
PrintError => 0, |
|
32
|
|
|
|
|
|
|
AutoCommit => 1, |
|
33
|
|
|
|
|
|
|
mysql_auto_reconnect => 1, |
|
34
|
|
|
|
|
|
|
}, |
|
35
|
|
|
|
|
|
|
); |
|
36
|
5
|
|
|
|
|
68887
|
return $dbh; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub reconnect { |
|
40
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
41
|
0
|
|
|
|
|
0
|
$self->dbh( $self->_create_dbh ); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub is_initialized { |
|
45
|
5
|
|
|
5
|
0
|
560
|
my ( $class, @args ) = @_; |
|
46
|
|
|
|
|
|
|
|
|
47
|
5
|
100
|
|
|
|
26
|
if( $class->meta->existing_singleton ) { |
|
48
|
3
|
|
|
|
|
102
|
return( 1 ); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
2
|
|
|
|
|
161
|
return( 0 ); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=pod |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=encoding UTF-8 |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NAME |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Mail::MtPolicyd::SqlConnection - singleton class to hold the sql database connection |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 VERSION |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
version 1.23 |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 AUTHOR |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This is free software, licensed under: |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |