AMQP/Utils.pm

filter: Statementstmt 51.1% 45 / 88 Branchbran 9.7% 8 / 82 Conditioncond 61.5% 8 / 13 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 30.5% 11 / 36 Podpod 100% 5 / 5 totaltotal 34.6% 80 / 231 CC 49 SCAR 28.7
CC
49
Cov
33%
__ANON__
56.0
__ANON__
56.0
__ANON__
42.0
CRAP 17.6
« AMQP/ConnectionManager.pm ↑ Summary AMQP/RPC/Server.pm »
1 package Net::Async::AMQP::Utils;
2 21 $Net::Async::AMQP::Utils::VERSION = '2.000';
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 21 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Net::Async::AMQP::Utils
11  
12 =head1 VERSION
13  
14 version 2.000
15  
16 =head1 SYNOPSIS
17  
18 =head1 DESCRIPTION
19  
20 All functions are imported by default.
21  
22 =cut
23  
24 21 our @EXPORT_OK = our @EXPORT = qw(
25 amqp_frame_info
26 amqp_frame_type
27 );
28  
29 my %extra = (
30 2 ▶ 'Connection::Start' => sub {
Subroutine __ANON__: called CC=6 SCAR=19.5
31 sprintf 'AMQP %d.%d, { %s }, auth "%s", locales "%s"',
32 $_->version_major // 0,
33 $_->version_minor // 0,
34 0 ▶ join(', ', map { $_ . ' = "' . ($_[0]->server_properties->{$_} // '') . '"' } keys %{$_->server_properties}),
Condition70%7/10
$_->version_major // 0
l!l
11
$_->version_minor // 0
l!l
11
$_[0]->server_properties->{$_} // ""
l!l
00
$_->mechanisms // ""
l!l
20
$_->locales // ""
l!l
11
MC/DC100%1/1
$_->version_major // 0
$_->version_major
MC/DC100%1/1
$_->version_minor // 0
$_->version_minor
MC/DC0%0/1
$_[0]->server_properties->{$_} // ""
$_[0]->server_properties->{$_}
MC/DC0%0/1
$_->mechanisms // ""
$_->mechanisms
MC/DC100%1/1
$_->locales // ""
$_->locales
Truth table100%2/2
A
A= $_->version_major
Aresult
11
00
Truth table100%2/2
A
A= $_->version_minor
Aresult
11
00
Truth table0%0/2
A
A= $_[0]->server_properties->{$_}
Aresult
11
00
Truth table50%1/2
A
A= $_->mechanisms
Aresult
11
00
Truth table100%2/2
A
A= $_->locales
Aresult
11
00
35 $_->mechanisms // '',
36 $_->locales // ''
37 },
38 1 ▶ 'Connection::StartOk' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
39 sprintf '{ %s }, auth "%s", response "%s", locale "%s"',
40 1 join(', ', map { $_ . ' = "' . $_[0]->client_properties->{$_} . '"' } keys %{$_->client_properties}),
41 $_->mechanism,
42 $_->response,
43 $_->locale
44 },
45 0 ▶ 'Connection::Secure' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 0 sprintf 'challenge "%s"',
47 $_->challenge
48 },
49 0 ▶ 'Connection::SecureOk' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 sprintf 'response "%s"',
51 $_->response
52 },
53 1 ▶ 'Connection::Tune' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
54 1 sprintf 'channels %d, frame max %d, heartbeat %d',
55 $_->channel_max,
56 $_->frame_max,
57 $_->heartbeat,
58 },
59 1 ▶ 'Connection::TuneOk' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
60 1 sprintf 'channels %d, frame max %d, heartbeat %d',
61 $_->channel_max,
62 $_->frame_max,
63 $_->heartbeat
64 },
65 1 ▶ 'Connection::Open' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
66 1 sprintf 'vhost "%s"',
67 $_->virtual_host
68 },
69 1 ▶ 'Connection::Close' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
70 1 sprintf 'code %d, text "%s", class %d, method %d',
71 $_->reply_code,
72 $_->reply_text,
73 $_->class_id,
74 $_->method_id
75 },
76 0 ▶ 'Channel::Flow' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
77 0 ▶ sprintf '%s',
Branch: 1 branch
BranchTrueFalseTotal
$_->active ? : 0 0 0
78 $_->active ? 'enable' : 'disable'
79 },
80 0 ▶ 'Channel::Close' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 0 sprintf 'code %d, text "%s", class %d, method %d',
82 $_->reply_code,
83 $_->reply_text,
84 $_->class_id,
85 $_->method_id
86 },
87 0 ▶ 'Exchange::Declare' => sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
88 sprintf 'exchange "%s", type "%s", passive = %s, durable = %s, auto-delete = %s, internal = %s, nowait = %s, arguments { %s }',
89 $_->exchange,
90 $_->type,
91 $_->passive ? 'yes' : 'no',
92 $_->durable ? 'yes' : 'no',
93 $_->auto_delete ? 'yes' : 'no',
94 $_->internal ? 'yes' : 'no',
95 $_->nowait ? 'yes' : 'no',
96 0 ▶ $_->arguments ? join(', ', map { $_ . ' = "' . $_[0]->arguments->{$_} . '"' } keys %{$_->arguments}) : '',
Branch: 6 branches
BranchTrueFalseTotal
$_->passive ? : 0 0 0
$_->durable ? : 0 0 0
$_->auto_delete ? : 0 0 0
$_->internal ? : 0 0 0
$_->nowait ? : 0 0 0
$_->arguments ? : 0 0 0
97 },
98 0 ▶ 'Exchange::Delete' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
99 0 ▶ sprintf 'exchange "%s", if-unused "%s", nowait = %s',
Branch: 2 branches
BranchTrueFalseTotal
$_->if_unused ? : 0 0 0
$_->nowait ? : 0 0 0
100 $_->exchange,
101 $_->if_unused ? 'yes' : 'no',
102 $_->nowait ? 'yes' : 'no',
103 },
104 0 ▶ 'Exchange::Bind' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
105 sprintf 'destination "%s", source "%s", rkey "%s", nowait = %s, arguments { %s }',
106 $_->destination,
107 $_->source,
108 $_->routing_key,
109 $_->nowait ? 'yes' : 'no',
110 0 ▶ $_->arguments ? join(', ', map { $_ . ' = "' . $_[0]->arguments->{$_} . '"' } keys %{$_->arguments}) : '',
Branch: 2 branches
BranchTrueFalseTotal
$_->nowait ? : 0 0 0
$_->arguments ? : 0 0 0
111 },
112 0 ▶ 'Exchange::Unbind' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
113 sprintf 'destination "%s", source "%s", rkey "%s", nowait = %s, arguments { %s }',
114 $_->destination,
115 $_->source,
116 $_->routing_key,
117 $_->nowait ? 'yes' : 'no',
118 0 ▶ $_->arguments ? join(', ', map { $_ . ' = "' . $_[0]->arguments->{$_} . '"' } keys %{$_->arguments}) : '',
Branch: 2 branches
BranchTrueFalseTotal
$_->nowait ? : 0 0 0
$_->arguments ? : 0 0 0
119 },
120 0 ▶ 'Queue::Declare' => sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
121 sprintf 'queue "%s", passive = %s, durable = %s, exclusive = %s, auto-delete = %s, nowait = %s, arguments { %s }',
122 $_->queue,
123 $_->passive ? 'yes' : 'no',
124 $_->durable ? 'yes' : 'no',
125 $_->exclusive ? 'yes' : 'no',
126 $_->auto_delete ? 'yes' : 'no',
127 $_->nowait ? 'yes' : 'no',
128 0 ▶ $_->arguments ? join(', ', map { $_ . ' = "' . $_[0]->arguments->{$_} . '"' } keys %{$_->arguments}) : '',
Branch: 6 branches
BranchTrueFalseTotal
$_->passive ? : 0 0 0
$_->durable ? : 0 0 0
$_->exclusive ? : 0 0 0
$_->auto_delete ? : 0 0 0
$_->nowait ? : 0 0 0
$_->arguments ? : 0 0 0
129 },
130 0 ▶ 'Queue::DeclareOk' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
131 0 sprintf 'queue "%s", messages %d, consumers %d',
132 $_->queue,
133 $_->message_count,
134 $_->consumer_count,
135 },
136 0 ▶ 'Queue::Bind' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
137 sprintf 'queue "%s", exchange "%s", rkey "%s", nowait = %s, arguments { %s }',
138 $_->queue,
139 $_->exchange,
140 $_->routing_key,
141 $_->nowait ? 'yes' : 'no',
142 0 ▶ $_->arguments ? join(', ', map { $_ . ' = "' . $_[0]->arguments->{$_} . '"' } keys %{$_->arguments}) : '',
Branch: 2 branches
BranchTrueFalseTotal
$_->nowait ? : 0 0 0
$_->arguments ? : 0 0 0
143 },
144 0 ▶ 'Queue::Unbind' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
145 sprintf 'queue "%s", exchange "%s", rkey "%s", nowait = %s, arguments { %s }',
146 $_->queue,
147 $_->exchange,
148 $_->routing_key,
149 $_->nowait ? 'yes' : 'no',
150 0 ▶ $_->arguments ? join(', ', map { $_ . ' = "' . $_[0]->arguments->{$_} . '"' } keys %{$_->arguments}) : '',
Branch: 2 branches
BranchTrueFalseTotal
$_->nowait ? : 0 0 0
$_->arguments ? : 0 0 0
151 },
152 0 ▶ 'Queue::Delete' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
153 0 ▶ sprintf 'queue "%s", if-unused = %s, if-empty = %s, nowait = %s',
Branch: 3 branches
BranchTrueFalseTotal
$_->if_unused ? : 0 0 0
$_->if_empty ? : 0 0 0
$_->nowait ? : 0 0 0
154 $_->queue,
155 $_->if_unused ? 'yes' : 'no',
156 $_->if_empty ? 'yes' : 'no',
157 $_->nowait ? 'yes' : 'no',
158 },
159 0 ▶ 'Queue::DeleteOk' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
160 0 sprintf 'messages %d',
161 $_->message_count,
162 },
163 0 ▶ 'Basic::Qos' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
164 0 ▶ sprintf 'size %d, count %d, global = %s',
Branch: 1 branch
BranchTrueFalseTotal
$_->global ? : 0 0 0
165 $_->prefetch_size,
166 $_->prefetch_count,
167 $_->global ? 'yes' : 'no',
168 },
169 0 ▶ 'Basic::Consume' => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
170 sprintf 'queue "%s", ctag "%s", no-local = %s, no-ack = %s, exclusive = %s, nowait = %s, arguments { %s }',
171 $_->queue,
172 $_->consumer_tag,
173 $_->no_local ? 'yes' : 'no',
174 $_->no_ack ? 'yes' : 'no',
175 $_->exclusive ? 'yes' : 'no',
176 $_->nowait ? 'yes' : 'no',
177 0 ▶ $_->arguments ? join(', ', map { $_ . ' = "' . $_[0]->arguments->{$_} . '"' } keys %{$_->arguments}) : '',
Branch: 5 branches
BranchTrueFalseTotal
$_->no_local ? : 0 0 0
$_->no_ack ? : 0 0 0
$_->exclusive ? : 0 0 0
$_->nowait ? : 0 0 0
$_->arguments ? : 0 0 0
178 },
179 0 ▶ 'Basic::ConsumeOk' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
180 0 sprintf 'ctag "%s"',
181 $_->consumer_tag,
182 },
183 0 ▶ 'Basic::Cancel' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
184 0 ▶ sprintf 'ctag "%s", nowait = %s',
Branch: 1 branch
BranchTrueFalseTotal
$_->nowait ? : 0 0 0
185 $_->consumer_tag,
186 $_->nowait ? 'yes' : 'no',
187 },
188 0 ▶ 'Basic::CancelOk' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
189 0 sprintf 'ctag "%s"',
190 $_->consumer_tag
191 },
192 0 ▶ 'Basic::Return' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
193 0 sprintf 'code %d, text "%s", exchange "%s", rkey "%s"',
194 $_->reply_code,
195 $_->reply_text,
196 $_->exchange,
197 $_->routing_key
198 },
199 0 ▶ 'Basic::Deliver' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
200 0 ▶ sprintf 'ctag "%s", dtag %s, redelivered = %s, exchange "%s", rkey "%s"',
Branch: 1 branch
BranchTrueFalseTotal
$_->redelivered ? : 0 0 0
201 $_->consumer_tag,
202 $_->delivery_tag,
203 $_->redelivered ? 'yes' : 'no',
204 $_->exchange,
205 $_->routing_key
206 },
207 0 ▶ 'Basic::Ack' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
208 0 ▶ sprintf 'dtag %s, multiple = %s',
Branch: 1 branch
BranchTrueFalseTotal
$_->multiple ? : 0 0 0
209 $_->delivery_tag,
210 $_->multiple ? 'yes' : 'no',
211 },
212 21 );
213  
214 =head2 amqp_frame_info
215  
216 Returns a string with information about the given AMQP frame.
217  
218 =cut
219  
220 11 ▶sub amqp_frame_info($) {
Subroutine amqp_frame_info: called CC=5 SCAR=16.6
Pod documented
221 11 my ($frame) = @_;
222 11 my $type = amqp_frame_type($frame);
223 11 my $txt = $type;
224 11 ▶ $txt .= ', channel ' . $frame->channel if $frame->channel;
Branch: 1 branch
BranchTrueFalseTotal
if $frame->channel 2 9 11
225 11 ▶ if($frame->can('method_frame') && (my $method_frame = $frame->method_frame)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frame->can("method_frame") and my $method_frame = $frame->method_frame) 11 0 11
Condition33%1/3
$frame->can("method_frame") and my $method_frame = $frame->method_frame
!ll&&!rl&&r
0011
MC/DC0%0/2
$frame->can("method_frame") and my $method_frame = $frame->method_frame
$frame->can("method_frame") my $method_frame = $frame->method_frame
Truth table33%1/3
A and B
A= $frame->can("method_frame")B= my $method_frame = $frame->method_frame
ABresult
0X0
100
111
226 11 $txt .= " " . $extra{$type}->($method_frame, $frame) for grep exists $extra{$type}, $method_frame;
227 }
228 11 return $txt;
229 }
230  
231 { # We cache the lookups since they're unlikely to change during the application lifecycle
232  
233 21 my %types;
234  
235 =head2 amqp_frame_type
236  
237 Takes the following parameters:
238  
239 =over 4
240  
241 =item * $frame - the L<Net::AMQP::Frame> instance
242  
243 =back
244  
245 Returns string representing type, typically the base class with Net::AMQP::Protocol prefix removed.
246  
247 =cut
248  
249 22 ▶sub amqp_frame_type {
Subroutine amqp_frame_type: called CC=5 SCAR=16.3
Pod documented
250 22 my ($frame) = @_;
251 22 ▶ return 'Header' if $frame->isa('Net::AMQP::Frame::Header');
Branch: 1 branch
BranchTrueFalseTotal
if $frame->isa("Net::AMQP::Frame::Header") 0 22 22
252 22 ▶ return 'Heartbeat' if $frame->isa('Net::AMQP::Frame::Heartbeat');
Branch: 1 branch
BranchTrueFalseTotal
if $frame->isa("Net::AMQP::Frame::Heartbeat") 0 22 22
253 22 ▶ return 'Unknown' unless $frame->can('method_frame');
Branch: 1 branch
BranchTrueFalseTotal
unless $frame->can("method_frame") 0 22 22
254  
255 22 my $method_frame = shift->method_frame;
256 22 my $ref = ref $method_frame;
257 22 ▶ return $types{$ref} if exists $types{$ref};
Branch: 1 branch
BranchTrueFalseTotal
if exists $types{$ref} 11 11 22
258 11 my $re = qr/^Net::AMQP::Protocol::([^:]+::[^:]+)$/;
259 11 my ($frame_type) = grep /$re/, Class::ISA::self_and_super_path($ref);
260 11 ($frame_type) = $frame_type =~ $re;
261 11 $types{$ref} = $frame_type;
262 11 return $frame_type;
263 }
264 }
265  
266 {
267 21 my %amqp_codes = (
268 200 => { message => 'replysuccess', description => 'Indicates that the method completed successfully. This reply code is reserved for future use the current protocol design does not use positive confirmation and reply codes are sent only in case of an error.' },
269 311 => { message => 'contenttoolarge', type => 'channel', description => 'The client attempted to transfer content larger than the server could accept at the present time. The client may retry at a later time.' },
270 313 => { message => 'noconsumers', type => 'channel', description => 'When the exchange cannot deliver to a consumer when the immediate flag is set. As a result of pending data on the queue or the absence of any consumers of the queue.' },
271 320 => { message => 'connectionforced', type => 'connection', description => 'An operator intervened to close the connection for some reason. The client may retry at some later date.' },
272 402 => { message => 'invalidpath', type => 'connection', description => 'The client tried to work with an unknown virtual host.' },
273 403 => { message => 'accessrefused', type => 'channel', description => 'The client attempted to work with a server entity to which it has no access due to security settings.' },
274 404 => { message => 'notfound', type => 'channel', description => 'The client attempted to work with a server entity that does not exist.' },
275 405 => { message => 'resourcelocked', type => 'channel', description => 'The client attempted to work with a server entity to which it has no access because another client is working with it.' },
276 406 => { message => 'preconditionfailed', type => 'channel', description => 'The client requested a method that was not allowed because some precondition failed.' },
277 501 => { message => 'frameerror', type => 'connection', description => 'The sender sent a malformed frame that the recipient could not decode. This strongly implies a programming error in the sending peer.' },
278 502 => { message => 'syntaxerror', type => 'connection', description => 'The sender sent a frame that contained illegal values for one or more fields. This strongly implies a programming error in the sending peer.' },
279 503 => { message => 'commandinvalid', type => 'connection', description => 'The client sent an invalid sequence of frames, attempting to perform an operation that was considered invalid by the server. This usually implies a programming error in the client.' },
280 504 => { message => 'channelerror', type => 'connection', description => 'The client attempted to work with a channel that had not been correctly opened. This most likely indicates a fault in the client layer.' },
281 505 => { message => 'unexpectedframe', type => 'connection', description => 'The peer sent a frame that was not expected, usually in the context of a content header and body. This strongly indicates a fault in the peer\'s content processing.' },
282 506 => { message => 'resourceerror', type => 'connection', description => 'The server could not complete the method because it lacked sufficient resources. This may be due to the client creating too many of some type of entity.' },
283 530 => { message => 'notallowed', type => 'connection', description => 'The client tried to work with some entity in a manner that is prohibited by the server, due to security settings or by some other criteria.' },
284 540 => { message => 'notimplemented', type => 'connection', description => 'The client tried to use functionality that is not implemented in the server.' },
285 541 => { message => 'internalerror', type => 'connection', description => 'The server could not complete the method because of an internal error. The server may require intervention by an operator in order to resume normal operations.' },
286 );
287  
288 =head2 message_for_code
289  
290 Returns the name (short message) corresponding to the given status code.
291  
292 Example:
293  
294 message_for_code(540) => 'not implemented'
295  
296 =cut
297  
298 0 ▶sub message_for_code {
Subroutine message_for_code: not called CC=1 SCAR=6.9
Pod documented
299 0 my ($code) = @_;
300 $amqp_codes{$code}{message}
301 0 }
302  
303 =head2 description_for_code
304  
305 Returns the description (long message) corresponding to the given status code.
306  
307 =cut
308  
309 0 ▶sub description_for_code {
Subroutine description_for_code: not called CC=1 SCAR=6.9
Pod documented
310 0 my ($code) = @_;
311 $amqp_codes{$code}{description}
312 0 }
313  
314 =head2 type_for_code
315  
316 Returns the type for the given status code - typically "channel" or "connection".
317  
318 =cut
319  
320 0 ▶sub type_for_code {
Subroutine type_for_code: not called CC=1 SCAR=6.9
Pod documented
321 0 my ($code) = @_;
322 $amqp_codes{$code}{type}
323 0 }
324 }
325  
326 21 1;
327  
328 __END__
« AMQP/ConnectionManager.pm ↑ Summary AMQP/RPC/Server.pm »