| 1 | package Cikl::RabbitMQ; | ||||||||||
| 2 | 1 | ▶ | use 5.008005; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Cikl::Client::Transport; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | require Net::RabbitFoot; | |||||||||
| 8 | |||||||||||
| 9 | 1 | our $VERSION = "0.01"; | |||||||||
| 10 | |||||||||||
| 11 | 1 | with 'Cikl::Client::Transport'; | |||||||||
| 12 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | has 'host' => ( | |||||||||
| 15 | is => 'ro', | ||||||||||
| 16 | isa => 'Str', | ||||||||||
| 17 | default => 'localhost' | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | 1 | has 'port' => ( | |||||||||
| 21 | is => 'ro', | ||||||||||
| 22 | isa => 'Num', | ||||||||||
| 23 | default => 5572 | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | 1 | has 'username' => ( | |||||||||
| 27 | is => 'ro', | ||||||||||
| 28 | isa => 'Str', | ||||||||||
| 29 | default => 'guest' | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 1 | has 'password' => ( | |||||||||
| 33 | is => 'ro', | ||||||||||
| 34 | isa => 'Str', | ||||||||||
| 35 | default => 'guest' | ||||||||||
| 36 | ); | ||||||||||
| 37 | |||||||||||
| 38 | 1 | has 'vhost' => ( | |||||||||
| 39 | is => 'ro', | ||||||||||
| 40 | isa => 'Str', | ||||||||||
| 41 | default => '/' | ||||||||||
| 42 | ); | ||||||||||
| 43 | |||||||||||
| 44 | 1 | has 'submit_key' => ( | |||||||||
| 45 | is => 'ro', | ||||||||||
| 46 | isa => 'Str', | ||||||||||
| 47 | default => 'cikl.event' | ||||||||||
| 48 | ); | ||||||||||
| 49 | |||||||||||
| 50 | 1 | has 'submit_exchange' => ( | |||||||||
| 51 | is => 'ro', | ||||||||||
| 52 | isa => 'Str', | ||||||||||
| 53 | default => '' | ||||||||||
| 54 | ); | ||||||||||
| 55 | |||||||||||
| 56 | 1 | has 'amqp' => ( | |||||||||
| 57 | is => 'ro', | ||||||||||
| 58 | isa => 'Net::RabbitFoot', | ||||||||||
| 59 | init_arg => undef, | ||||||||||
| 60 | lazy_build => 1 | ||||||||||
| 61 | ); | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub _build_amqp { | ||||||||
|
Subroutine
_build_amqp: not called CC=1 SCAR=6.9
| |||||||||||
| 64 | 0 | my $self = shift; | |||||||||
| 65 | 0 | return Net::RabbitFoot->new()->load_xml_spec()->connect( | |||||||||
| 66 | host => $self->host(), | ||||||||||
| 67 | port => $self->port(), | ||||||||||
| 68 | user => $self->username(), | ||||||||||
| 69 | pass => $self->password(), | ||||||||||
| 70 | vhost => $self->vhost() | ||||||||||
| 71 | ); | ||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 0 | ▶ | sub shutdown_amqp { | ||||||||
|
Subroutine
shutdown_amqp: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 75 | 0 | my $self = shift; | |||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | if ($self->has_amqp()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | $self->amqp->close(); | |||||||||
| 79 | 0 | $self->clear_amqp(); | |||||||||
| 80 | } | ||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 1 | has 'channel' => ( | |||||||||
| 84 | is => 'ro', | ||||||||||
| 85 | init_arg => undef, | ||||||||||
| 86 | lazy_build => 1 | ||||||||||
| 87 | ); | ||||||||||
| 88 | |||||||||||
| 89 | 0 | ▶ | sub _build_channel { | ||||||||
|
Subroutine
_build_channel: not called CC=1 SCAR=6.9
| |||||||||||
| 90 | 0 | my $self = shift; | |||||||||
| 91 | 0 | return $self->amqp()->open_channel(); | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 0 | ▶ | after 'shutdown' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 95 | 0 | my $self = shift; | |||||||||
| 96 | |||||||||||
| 97 | 0 | ▶ | if ($self->has_channel()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 0 | $self->channel->close(); | |||||||||
| 99 | 0 | $self->clear_channel(); | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 0 | $self->shutdown_amqp(); | |||||||||
| 103 | |||||||||||
| 104 | 0 | return 1; | |||||||||
| 105 | 1 | }; | |||||||||
| 106 | |||||||||||
| 107 | 0 | ▶ | sub _submit { | ||||||||
|
Subroutine
_submit: not called CC=1 SCAR=6.9
| |||||||||||
| 108 | 0 | my $self = shift; | |||||||||
| 109 | 0 | my $event = shift; | |||||||||
| 110 | |||||||||||
| 111 | 0 | my $body = $self->encode_event($event); | |||||||||
| 112 | 0 | $self->channel->publish( | |||||||||
| 113 | exchange => $self->submit_exchange, | ||||||||||
| 114 | routing_key => $self->submit_key, | ||||||||||
| 115 | body => $body | ||||||||||
| 116 | ); | ||||||||||
| 117 | 0 | return undef; | |||||||||
| 118 | } | ||||||||||
| 119 | 1 | __PACKAGE__->meta->make_immutable(); | |||||||||
| 120 | |||||||||||
| 121 | 1 | 1; | |||||||||
| 122 | |||||||||||
| 123 | __END__ | ||||||||||