AMQP/ConnectionManager.pm

filter: Statementstmt 90.0% 27 / 30 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod n/a totaltotal 85.0% 34 / 40 CC 1 SCAR 2.6
CC
1
Cov
90%
_default_port
2.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.3
« AMQP/Role/HasAChannel.pm ↑ Summary AMQP.pm »
1 package Message::Passing::AMQP::ConnectionManager;
2 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Types::Standard qw( Bool Str Int );
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Scalar::Util qw/ weaken /;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use AnyEvent::RabbitMQ;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 with qw/
11 Message::Passing::Role::ConnectionManager
12 Message::Passing::Role::HasHostnameAndPort
13 Message::Passing::Role::HasUsernameAndPassword
14 /;
15  
16 0 ▶sub _default_port { 5672 }
Subroutine _default_port: not called CC=1 SCAR=6.9
17  
18 1 has vhost => (
19 is => 'ro',
20 isa => Str,
21 required => 1,
22 );
23  
24 has tls => (
25 is => 'ro',
26 isa => Bool,
27 0 ▶ default => sub { 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 1 );
29  
30 has verbose => (
31 is => 'ro',
32 isa => Bool,
33 0 ▶ default => sub { 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 1 );
35  
36 1 my $has_loaded;
37 sub _build_connection {
38 my $self = shift;
39 weaken($self);
40 my $client = AnyEvent::RabbitMQ->new(
41 verbose => $self->verbose,
42 );
43 $client->load_xml_spec unless $has_loaded++;
44 $client->connect(
45 host => $self->hostname,
46 port => $self->port,
47 user => $self->username,
48 pass => $self->password,
49 vhost => $self->vhost,
50 tls => $self->tls,
51 timeout => $self->timeout,
52 on_success => sub {
53 $self->_set_connected(1);
54 },
55 on_failure => sub {
56 my ($error) = @_;
57 warn("CONNECT ERROR $error");
58 $self->_set_connected(0);
59 },
60 on_close => sub {
61 warn("CLOSED");
62 $self->_set_connected(0);
63 },
64 );
65 return $client;
66 }
67  
68 1 1;
69  
70 =head1 NAME
71  
72 Message::Passing::AMQP::ConnectionManager - Implements the Message::Passing::Role::HasAConnection interface.
73  
74 =head1 ATTRIBUTES
75  
76 =head2 vhost
77  
78 Passed to L<AnyEvent::RabbitMQ>->new->connect.
79  
80 =head2 timeout
81  
82 Passed to L<AnyEvent::RabbitMQ>->new->connect.
83  
84 =head2 tls
85  
86 Passed to L<AnyEvent::RabbitMQ>->new->connect.
87  
88 =head2 verbose
89  
90 Passed to L<AnyEvent::RabbitMQ>->new.
91  
92 =head1 AUTHOR, COPYRIGHT AND LICENSE
93  
94 See L<Message::Passing::AMQP>.
95  
96 =cut
« AMQP/Role/HasAChannel.pm ↑ Summary AMQP.pm »