line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Role::Connection; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
4586
|
use strict; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
193
|
|
4
|
7
|
|
|
7
|
|
1293
|
use MooseX::Role::Parameterized; |
|
7
|
|
|
|
|
112672
|
|
|
7
|
|
|
|
|
46
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
90805
|
use Mail::MtPolicyd::ConnectionPool; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
1841
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: role to consume connections from connection pool |
9
|
|
|
|
|
|
|
our $VERSION = '2.01'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
parameter name => ( |
12
|
|
|
|
|
|
|
isa => 'Str', |
13
|
|
|
|
|
|
|
default => 'db', |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
parameter type => ( |
17
|
|
|
|
|
|
|
isa => 'Str', |
18
|
|
|
|
|
|
|
default => 'Sql', |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
parameter initialize_early => ( |
22
|
|
|
|
|
|
|
isa => 'Bool', |
23
|
|
|
|
|
|
|
default => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
role { |
27
|
|
|
|
|
|
|
my $p = shift; |
28
|
|
|
|
|
|
|
my $name = $p->name; |
29
|
|
|
|
|
|
|
my $conn_attr = '_'.$p->name; |
30
|
|
|
|
|
|
|
my $handle_attr = $conn_attr.'_handle'; |
31
|
|
|
|
|
|
|
my $conn_class = 'Mail::MtPolicyd::Connection::'.$p->type; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
if( $p->initialize_early ) { |
34
|
|
|
|
|
|
|
before 'init' => sub { |
35
|
|
|
|
|
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
$self->$conn_attr; |
37
|
|
|
|
|
|
|
return; |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has $name => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
isa => 'Str', |
44
|
|
|
|
|
|
|
default => $name, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has $conn_attr => ( |
48
|
|
|
|
|
|
|
is => 'ro', |
49
|
|
|
|
|
|
|
isa => $conn_class, |
50
|
|
|
|
|
|
|
lazy => 1, |
51
|
|
|
|
|
|
|
default => sub { |
52
|
|
|
|
|
|
|
my $self = shift; |
53
|
|
|
|
|
|
|
my $conn = Mail::MtPolicyd::ConnectionPool->get_connection($self->$name); |
54
|
|
|
|
|
|
|
if( ! defined $conn ) { |
55
|
|
|
|
|
|
|
die("no connection $name configured!"); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
return $conn; |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has $handle_attr => ( |
62
|
|
|
|
|
|
|
is => 'ro', |
63
|
|
|
|
|
|
|
lazy => 1, |
64
|
|
|
|
|
|
|
default => sub { |
65
|
|
|
|
|
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
return $self->$conn_attr->handle; |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=pod |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=encoding UTF-8 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 NAME |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Mail::MtPolicyd::Role::Connection - role to consume connections from connection pool |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 VERSION |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
version 2.01 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This is free software, licensed under: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |