| 1 | package Mojo::RabbitMQ::Client::Method::Publish; | ||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use Mojo::Base 'Mojo::RabbitMQ::Client::Method'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 0 | ▶ | sub setup { | ||||||||||||||||||||||||||
|
Subroutine
setup: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 5 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 0 | $self->arguments({@_}); | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 0 | return $self; | |||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub deliver { | ||||||||||||||||||||||||||
|
Subroutine
deliver: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | return $self if !$self->channel->is_active; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | my %args = %{$self->arguments}; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | my $header_args | ||||||||||||||||||||||||||||
| 20 | 0 | ▶ | = {header => delete $args{header} || {}, weight => delete $args{weight}}; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args{'header'} || {}
MC/DC0%0/1
delete $args{'header'} || {}
delete $args{'header'}
Truth table0%0/2
A
A= delete $args{'header'}
| |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $body = delete $args{body} || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args{'body'} || ''
MC/DC0%0/1
delete $args{'body'} || ''
delete $args{'body'}
Truth table0%0/2
A
A= delete $args{'body'}
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $self->_publish(%args)->_header($header_args, $body)->_body($body, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 24 | 0 | $self->is_sent(1); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | $self->emit('success'); | |||||||||||||||||||||||||||
| 27 | 0 | }); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | return $self if !$args{mandatory} && !$args{immediate}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"mandatory"} or $args{"immediate"}
MC/DC0%0/2
$args{"mandatory"} or $args{"immediate"}
$args{"mandatory"}
$args{"immediate"}
Truth table0%0/3
A or B
A= $args{"mandatory"}B= $args{"immediate"}
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | $self->channel->return_cbs->{($args{exchange} || '') . '_' | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | . $args{routing_key}} = $self; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'exchange'} || ''
MC/DC0%0/1
$args{'exchange'} || ''
$args{'exchange'}
Truth table0%0/2
A
A= $args{'exchange'}
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | return $self; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub _publish { | ||||||||||||||||||||||||||
|
Subroutine
_publish: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | $self->client->_write_frame( | |||||||||||||||||||||||||||
| 42 | Net::AMQP::Protocol::Basic::Publish->new( | ||||||||||||||||||||||||||||
| 43 | exchange => '', | ||||||||||||||||||||||||||||
| 44 | mandatory => 0, | ||||||||||||||||||||||||||||
| 45 | immediate => 0, | ||||||||||||||||||||||||||||
| 46 | %args, # routing_key | ||||||||||||||||||||||||||||
| 47 | ticket => 0, | ||||||||||||||||||||||||||||
| 48 | ), | ||||||||||||||||||||||||||||
| 49 | $self->channel->id | ||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | return $self; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub _header { | ||||||||||||||||||||||||||
|
Subroutine
_header: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 56 | 0 | my ($self, $args, $body) = @_; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | $self->client->_write_frame( | ||||||||||||||||||||||||||||
| 59 | Net::AMQP::Frame::Header->new( | ||||||||||||||||||||||||||||
| 60 | weight => $args->{weight} || 0, | ||||||||||||||||||||||||||||
| 61 | body_size => length($body), | ||||||||||||||||||||||||||||
| 62 | header_frame => Net::AMQP::Protocol::Basic::ContentHeader->new( | ||||||||||||||||||||||||||||
| 63 | content_type => 'application/octet-stream', | ||||||||||||||||||||||||||||
| 64 | content_encoding => undef, | ||||||||||||||||||||||||||||
| 65 | headers => {}, | ||||||||||||||||||||||||||||
| 66 | delivery_mode => 1, | ||||||||||||||||||||||||||||
| 67 | priority => 1, | ||||||||||||||||||||||||||||
| 68 | correlation_id => undef, | ||||||||||||||||||||||||||||
| 69 | expiration => undef, | ||||||||||||||||||||||||||||
| 70 | message_id => undef, | ||||||||||||||||||||||||||||
| 71 | timestamp => time, | ||||||||||||||||||||||||||||
| 72 | type => undef, | ||||||||||||||||||||||||||||
| 73 | user_id => $self->client->user, | ||||||||||||||||||||||||||||
| 74 | app_id => undef, | ||||||||||||||||||||||||||||
| 75 | cluster_id => undef, | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | %{ $args->{header} }, | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'weight'} || 0
MC/DC0%0/1
$args->{'weight'} || 0
$args->{'weight'}
Truth table0%0/2
A
A= $args->{'weight'}
| |||||||||||||||||||||||||||||
| 77 | ), | ||||||||||||||||||||||||||||
| 78 | ), | ||||||||||||||||||||||||||||
| 79 | $self->channel->id | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | return $self; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub _body { | ||||||||||||||||||||||||||
|
Subroutine
_body: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 86 | 0 | my ($self, $body, $cb) = @_; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | $self->client->_write_frame(Net::AMQP::Frame::Body->new(payload => $body), | |||||||||||||||||||||||||||
| 89 | $self->channel->id, $cb); | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | return $self; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 5 | 1; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =encoding utf8 | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 NAME | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Mojo::RabbitMQ::Client::Method::Publish - single class to do all of AMQP Publish method magic | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | use Mojo::RabbitMQ::Client::Method::Publish; | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | my $method = Mojo::RabbitMQ::Client::Method::Publish->new( | ||||||||||||||||||||||||||||
| 107 | client => $client, | ||||||||||||||||||||||||||||
| 108 | channel => $channel | ||||||||||||||||||||||||||||
| 109 | )->setup( | ||||||||||||||||||||||||||||
| 110 | exchange => 'mojo', | ||||||||||||||||||||||||||||
| 111 | routing_key => '', | ||||||||||||||||||||||||||||
| 112 | header => {} | ||||||||||||||||||||||||||||
| 113 | body => 'mojo', | ||||||||||||||||||||||||||||
| 114 | mandatory => 0, | ||||||||||||||||||||||||||||
| 115 | immediate => 0, | ||||||||||||||||||||||||||||
| 116 | )->deliver(); | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | L<Mojo::RabbitMQ::Client::Method::Publish> is a special class to implement AMQP message publish workflow. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head1 EVENTS | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | L<Mojo::RabbitMQ::Client::Method::Publish> inherits all events from L<Mojo::RabbitMQ::Client::Method>. | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | L<Mojo::RabbitMQ:Client:::Method::Publish> inherits all attributes from L<Mojo::RabbitMQ::Client::Method>. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head1 METHODS | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | L<Mojo::RabbitMQ::Client::Method::Publish> inherits all methods from L<Mojo::RabbitMQ::Client::Method> with | ||||||||||||||||||||||||||||
| 133 | following changes. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head2 setup | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | $method = $method->setup($arguments); | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | Only accepts common arguments for message publish chain. Which is: | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =over 2 | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =item Frame::Method | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =over 2 | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =item Basic::Publish | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =over 2 | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =item * exchange | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =item * routing_key | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =item * mandatory | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =item * immediate | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =back | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =back | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =item Frame::Header | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =over 2 | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =item Basic::ContentHeader | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =over 2 | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =item * header | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =item * weight | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =back | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =back | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =item Frame::Body | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =over 2 | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =item * body (as payload) | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =back | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =back | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | L<Mojo::RabbitMQ::Client::Method>, L<Mojo::RabbitMQ::Client::Channel>, L<Mojo::RabbitMQ::Client> | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | Copyright (C) 2015-2017, Sebastian Podjasek and others | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | Based on L<AnyEvent::RabbitMQ> - Copyright (C) 2010 Masahito Ikuta, maintained by C<< bobtfish@bobtfish.net >> | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =cut | ||||||||||||||||||||||||||||