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