MtPolicyd/Role/Connection.pm

filter: Statementstmt 100% 35 / 35 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 97.8% 45 / 46 CC 3 SCAR 3.7
CC
3
Cov
97%
__ANON__
2.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.4
« MtPolicyd/Plugin/Role/Scoring.pm ↑ Summary MtPolicyd/VirtualHost.pm »
1 package Mail::MtPolicyd::Role::Connection;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use MooseX::Role::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use Mail::MtPolicyd::ConnectionPool;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: role to consume connections from connection pool
9 7 our $VERSION = '2.01'; # VERSION
10  
11 7 parameter name => (
12 isa => 'Str',
13 default => 'db',
14 );
15  
16 7 parameter type => (
17 isa => 'Str',
18 default => 'Sql',
19 );
20  
21 7 parameter initialize_early => (
22 isa => 'Bool',
23 default => 1,
24 );
25  
26 role {
27 17 ▶ my $p = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
28 17 my $name = $p->name;
29 17 my $conn_attr = '_'.$p->name;
30 17 my $handle_attr = $conn_attr.'_handle';
31 17 my $conn_class = 'Mail::MtPolicyd::Connection::'.$p->type;
32  
33 17 ▶ if( $p->initialize_early ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->initialize_early) 17 0 17
34 before 'init' => sub {
35 3 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
36 3 $self->$conn_attr;
37 2 return;
38 17 };
39 }
40  
41 17 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 7 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
53 7 my $conn = Mail::MtPolicyd::ConnectionPool->get_connection($self->$name);
54 7 ▶ if( ! defined $conn ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $conn) 1 6 7
55 1 die("no connection $name configured!");
56 }
57 6 return $conn;
58 },
59 17 );
60  
61 has $handle_attr => (
62 is => 'ro',
63 lazy => 1,
64 default => sub {
65 6 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
66 6 return $self->$conn_attr->handle;
67 },
68 17 );
69 7 };
70  
71 7 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
« MtPolicyd/Plugin/Role/Scoring.pm ↑ Summary MtPolicyd/VirtualHost.pm »