line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::ConnectionPool; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
59209
|
use strict; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
215
|
|
4
|
8
|
|
|
8
|
|
2253
|
use MooseX::Singleton; |
|
8
|
|
|
|
|
1056343
|
|
|
8
|
|
|
|
|
35
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.01'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: a singleton to hold all configure connections |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'pool' => ( |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
isa => 'HashRef[Mail::MtPolicyd::Connection]', |
12
|
|
|
|
|
|
|
lazy => 1, |
13
|
|
|
|
|
|
|
default => sub { {} }, |
14
|
|
|
|
|
|
|
traits => [ 'Hash' ], |
15
|
|
|
|
|
|
|
handles => { |
16
|
|
|
|
|
|
|
'get_connection' => 'get', |
17
|
|
|
|
|
|
|
'add_connection' => 'set', |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub get_handle { |
22
|
27
|
|
|
27
|
0
|
11234
|
my ( $self, $name ) = @_; |
23
|
27
|
50
|
|
|
|
834
|
if( defined $self->pool->{$name} ) { |
24
|
27
|
|
|
|
|
1020
|
return $self->pool->{$name}->handle; |
25
|
|
|
|
|
|
|
} |
26
|
0
|
|
|
|
|
0
|
return; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'plugin_prefix' => ( is => 'ro', isa => 'Str', |
30
|
|
|
|
|
|
|
default => 'Mail::MtPolicyd::Connection::'); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub load_config { |
33
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $config ) = @_; |
34
|
0
|
|
|
|
|
0
|
foreach my $name ( keys %$config ) { |
35
|
0
|
|
|
|
|
0
|
$self->load_connection( $name, $config->{$name} ); |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
0
|
return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub load_connection { |
41
|
5
|
|
|
5
|
0
|
2899
|
my ( $self, $name, $params ) = @_; |
42
|
5
|
50
|
|
|
|
20
|
if( ! defined $params->{'module'} ) { |
43
|
0
|
|
|
|
|
0
|
die('no module defined for connection '.$name.'!'); |
44
|
|
|
|
|
|
|
} |
45
|
5
|
|
|
|
|
10
|
my $module = $params->{'module'}; |
46
|
5
|
|
|
|
|
172
|
my $class = $self->plugin_prefix.$module; |
47
|
5
|
|
|
|
|
3696
|
my $conn; |
48
|
|
|
|
|
|
|
|
49
|
5
|
|
|
|
|
15
|
my $code = "require ".$class.";"; |
50
|
5
|
|
|
|
|
272
|
eval $code; ## no critic (ProhibitStringyEval) |
51
|
5
|
50
|
|
|
|
30
|
if($@) { |
52
|
0
|
|
|
|
|
0
|
die('could not load connection '.$name.': '.$@); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
5
|
|
|
|
|
8
|
eval { |
56
|
5
|
|
|
|
|
57
|
$conn = $class->new( |
57
|
|
|
|
|
|
|
name => $name, |
58
|
|
|
|
|
|
|
%$params, |
59
|
|
|
|
|
|
|
); |
60
|
5
|
|
|
|
|
6171
|
$conn->init(); |
61
|
|
|
|
|
|
|
}; |
62
|
5
|
50
|
|
|
|
18
|
if($@) { |
63
|
0
|
|
|
|
|
0
|
die('could not initialize connection '.$name.': '.$@); |
64
|
|
|
|
|
|
|
} |
65
|
5
|
|
|
|
|
187
|
$self->add_connection( $name => $conn ); |
66
|
5
|
|
|
|
|
92
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub shutdown { |
70
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
foreach my $conn ( values %{$self->pool} ) { |
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$conn->shutdown(@_); # cascade |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub reconnect { |
80
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
foreach my $conn ( values %{$self->pool} ) { |
|
0
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
$conn->reconnect(@_); # cascade |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=encoding UTF-8 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Mail::MtPolicyd::ConnectionPool - a singleton to hold all configure connections |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 VERSION |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
version 2.01 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This is free software, licensed under: |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |