AMQP/Publisher.pm

filter: Statementstmt 55.1% 27 / 49 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 27.2% 3 / 11 Podpod 0.0% 0 / 2 totaltotal 40.5% 30 / 74 CC 7 SCAR 15.4
CC
7
Cov
44%
__ANON__
6.0
__ANON__
6.0
__ANON__
6.0
CRAP 4.6
« AMQP/Subscriber.pm ↑ Summary
1 package AMQP::Publisher;
2 1 our $VERSION = '0.01';
3  
4 1 ▶use Mojo::Base 'AMQP';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use AnyEvent::RabbitMQ;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 has 'debug' => 1;
9 1 has 'host' => 'localhost';
10 1 has 'port' => 5672;
11 1 has 'user' => 'guest';
12 1 has 'password' => 'guest';
13 1 has 'vhost' => '/';
14 1 has 'timeout' => 1;
15 1 has 'heartbeat' => 30;
16 1 has 'exchange' => 'log';
17 1 has 'type' => 'topic';
18 1 has 'key' => '#';
19 1 has 'rabbit';
20 1 has 'connection';
21 1 has 'channel';
22 1 has 'status';
23 1 has 'on_connect';
24  
25 0 ▶sub attach {
Subroutine attach: not called CC=1 SCAR=6.9
Pod undocumented
26 0 my $self = shift;
27 0 $self->status(AnyEvent->condvar);
28 0 $self->rabbit(AnyEvent::RabbitMQ->new);
29 0 $self->rabbit->load_xml_spec();
30 $self->rabbit->connect(
31 host => $self->host,
32 port => $self->port,
33 user => $self->user,
34 pass => $self->password,
35 vhost => $self->vhost,
36 timeout => $self->timeout,
37 tune => { heartbeat => $self->heartbeat },
38 0 ▶ on_success => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
39 0 ▶ say "Connected to amqp://" . $self->host . ":" . $self->port . $self->vhost if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
40 0 $self->connection(shift);
41 $self->connection->open_channel(
42 on_failure => $self->status,
43 0 ▶ on_close => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
44 0 ▶ say "Channel closed" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
45 0 $self->status->send;
46 },
47 0 ▶ on_success => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
48 0 ▶ say "Opened channel" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
49 0 $self->channel(shift);
50 0 $self->on_connect->($self);
51 },
52 0 );
53 },
54 on_failure => $self->status,
55 0 ▶ on_read_failure => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
56 0 ▶ say "Failed to read" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
57 0 $self->status->send;
58 },
59 0 ▶ on_return => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
60 0 ▶ say "Failed to send" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
61 0 $self->status->send;
62 },
63 0 ▶ on_close => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
64 0 ▶ say "Connection closed" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
65 0 $self->status->send;
66 }
67 0 );
68 0 $self->status->recv;
69 }
70  
71 0 ▶sub send {
Subroutine send: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my ($self,$message) = @_;
73 0 $self->channel->send($message);
74 }
75  
76 1 1;
77  
78 __END__
« AMQP/Subscriber.pm ↑ Summary