| 1 | package Mojo::RabbitMQ::Client::Method; | ||||||||||
| 2 | 5 | ▶ | use Mojo::Base 'Mojo::EventEmitter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 5 | has is_sent => 0; | |||||||||
| 5 | 5 | has client => undef; | |||||||||
| 6 | 5 | has channel => undef; | |||||||||
| 7 | 5 | has name => undef; | |||||||||
| 8 | 0 | ▶ | has arguments => sub { {} }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 9 | 5 | has expect => undef; | |||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub setup { | ||||||||
|
Subroutine
setup: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 12 | 0 | my $self = shift; | |||||||||
| 13 | 0 | $self->name(shift); | |||||||||
| 14 | 0 | $self->arguments(shift); | |||||||||
| 15 | 0 | $self->expect(shift); | |||||||||
| 16 | |||||||||||
| 17 | 0 | return $self; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub deliver { | ||||||||
|
Subroutine
deliver: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 21 | 0 | my $self = shift; | |||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | return 0 unless $self->channel->_assert_open(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | |||||||||||
| 25 | $self->client->_write_expect( | ||||||||||
| 26 | $self->name => $self->arguments, | ||||||||||
| 27 | 0 | ▶ | $self->expect => sub { $self->emit('success', @_); }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 28 | 0 | ▶ | sub { $self->emit('error', @_); }, $self->channel->id, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 29 | ); | ||||||||||
| 30 | 0 | $self->is_sent(1); | |||||||||
| 31 | |||||||||||
| 32 | 0 | return 1; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 5 | 1; | |||||||||
| 36 | |||||||||||
| 37 | =encoding utf8 | ||||||||||
| 38 | |||||||||||
| 39 | =head1 NAME | ||||||||||
| 40 | |||||||||||
| 41 | Mojo::RabbitMQ::Client::Method - it's a generic class for all AMQP method calls | ||||||||||
| 42 | |||||||||||
| 43 | =head1 SYNOPSIS | ||||||||||
| 44 | |||||||||||
| 45 | use Mojo::RabbitMQ::Client::Method; | ||||||||||
| 46 | |||||||||||
| 47 | my $method = Mojo::RabbitMQ::Client::Method->new( | ||||||||||
| 48 | client => $client, | ||||||||||
| 49 | channel => $channel | ||||||||||
| 50 | )->setup( | ||||||||||
| 51 | 'Basic::Consume' => { | ||||||||||
| 52 | ... | ||||||||||
| 53 | }, | ||||||||||
| 54 | ['Basic::ConsumeOk', ...] | ||||||||||
| 55 | ); | ||||||||||
| 56 | |||||||||||
| 57 | # Watch for errors | ||||||||||
| 58 | $method->on(error => sub { warn "Error in reception: " . $_[1] }); | ||||||||||
| 59 | |||||||||||
| 60 | # Send this frame to AMQP | ||||||||||
| 61 | $method->deliver; | ||||||||||
| 62 | |||||||||||
| 63 | =head1 DESCRIPTION | ||||||||||
| 64 | |||||||||||
| 65 | L<Mojo::RabbitMQ::Client::Method> is general class for every AMQP method call. | ||||||||||
| 66 | |||||||||||
| 67 | =head1 EVENTS | ||||||||||
| 68 | |||||||||||
| 69 | L<Mojo::RabbitMQ::Client::Method> inherits all events from L<Mojo::EventEmitter> and can emit the | ||||||||||
| 70 | following new ones. | ||||||||||
| 71 | |||||||||||
| 72 | =head2 success | ||||||||||
| 73 | |||||||||||
| 74 | $method->on(success => sub { | ||||||||||
| 75 | my ($method, $frame) = @_; | ||||||||||
| 76 | ... | ||||||||||
| 77 | }); | ||||||||||
| 78 | |||||||||||
| 79 | Emitted when one of expected replies is received. | ||||||||||
| 80 | |||||||||||
| 81 | =head2 message | ||||||||||
| 82 | |||||||||||
| 83 | Can be emitted by consumption & get methods. | ||||||||||
| 84 | |||||||||||
| 85 | =head2 empty | ||||||||||
| 86 | |||||||||||
| 87 | Can be emitted by get method, when no messages are available on queue. | ||||||||||
| 88 | |||||||||||
| 89 | =head1 ATTRIBUTES | ||||||||||
| 90 | |||||||||||
| 91 | L<Mojo::RabbitMQ::Client::Method> has following attributes. | ||||||||||
| 92 | |||||||||||
| 93 | =head2 is_sent | ||||||||||
| 94 | |||||||||||
| 95 | $method->is_sent ? "Method was sent" : "Method is still pending delivery"; | ||||||||||
| 96 | |||||||||||
| 97 | =head2 client | ||||||||||
| 98 | |||||||||||
| 99 | my $client = $method->client; | ||||||||||
| 100 | $method->client($client); | ||||||||||
| 101 | |||||||||||
| 102 | =head2 name | ||||||||||
| 103 | |||||||||||
| 104 | my $name = $method->name; | ||||||||||
| 105 | $method->name('Basic::Get'); | ||||||||||
| 106 | |||||||||||
| 107 | =head2 arguments | ||||||||||
| 108 | |||||||||||
| 109 | my $arguments = $method->arguments; | ||||||||||
| 110 | $method->arguments({no_ack => 1, ticket => 0, queue => 'amq.queue'}); | ||||||||||
| 111 | |||||||||||
| 112 | =head2 expect | ||||||||||
| 113 | |||||||||||
| 114 | my $expectations = $method->expect; | ||||||||||
| 115 | $method->expect([qw(Basic::GetOk Basic::GetEmpty)]); | ||||||||||
| 116 | |||||||||||
| 117 | =head1 METHODS | ||||||||||
| 118 | |||||||||||
| 119 | L<Mojo::RabbitMQ::Client::Method> inherits all methods from L<Mojo::EventEmitter> and implements | ||||||||||
| 120 | the following new ones. | ||||||||||
| 121 | |||||||||||
| 122 | =head2 setup | ||||||||||
| 123 | |||||||||||
| 124 | $method = $method->setup($name, $arguments, $expectations); | ||||||||||
| 125 | |||||||||||
| 126 | Sets AMQP method name, its arguments and expected replies. | ||||||||||
| 127 | |||||||||||
| 128 | =head2 deliver | ||||||||||
| 129 | |||||||||||
| 130 | my $status = $method->deliver(); | ||||||||||
| 131 | |||||||||||
| 132 | This delivers AMQP method call to server. Returns C<<false>> when channel is not open, C<<true>> otherwise. | ||||||||||
| 133 | On successful delivery->reply cycle emits C<<success>> event. | ||||||||||
| 134 | C<<error>> is emitted when none of expected replies are received. | ||||||||||
| 135 | |||||||||||
| 136 | =head1 SEE ALSO | ||||||||||
| 137 | |||||||||||
| 138 | L<Mojo::RabbitMQ::Client::Channel>, L<Mojo::RabbitMQ::Client> | ||||||||||
| 139 | |||||||||||
| 140 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 141 | |||||||||||
| 142 | Copyright (C) 2015-2017, Sebastian Podjasek and others | ||||||||||
| 143 | |||||||||||
| 144 | Based on L<AnyEvent::RabbitMQ> - Copyright (C) 2010 Masahito Ikuta, maintained by C<< bobtfish@bobtfish.net >> | ||||||||||
| 145 | |||||||||||
| 146 | This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. | ||||||||||
| 147 | |||||||||||
| 148 | =cut | ||||||||||