AMQP/Utils.pm

filter: Statementstmt 84.6% 33 / 39 Branchbran 66.6% 8 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 100% 5 / 5 totaltotal 75.3% 52 / 69 CC 8 SCAR 12.3
CC
8
Cov
78%
amqp_frame_type
5.1
amqp_frame_info
4.2
message_for_code
2.0
CRAP 3.4
« AMQP/Server/Protocol.pm ↑ Summary AMQP/Server/Connection.pm »
1 package Net::Async::AMQP::Utils;
2 18 $Net::Async::AMQP::Utils::VERSION = '0.031';
3 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 18 ▶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 0.031
15  
16 =head1 SYNOPSIS
17  
18 =head1 DESCRIPTION
19  
20 All functions are imported by default.
21  
22 =cut
23  
24 18 our @EXPORT_OK = our @EXPORT = qw(
25 amqp_frame_info
26 amqp_frame_type
27 );
28  
29 =head2 amqp_frame_info
30  
31 Returns a string with information about the given AMQP frame.
32  
33 =cut
34  
35 sub amqp_frame_info($) {
36 11 ▶ my ($frame) = @_;
Subroutine amqp_frame_info: called CC=4 SCAR=14.5
Pod documented
37 11 my $txt = amqp_frame_type($frame);
38 11 ▶ $txt .= ', channel ' . $frame->channel if $frame->channel;
Branch: 1 branch
BranchTrueFalseTotal
if $frame->channel 2 9 11
39 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
40 #note($_);
41 } else {
42  
43 }
44 11 return $txt;
45 }
46  
47 { # We cache the lookups since they're unlikely to change during the application lifecycle
48  
49 18 my %types;
50  
51 =head2 amqp_frame_type
52  
53 Takes the following parameters:
54  
55 =over 4
56  
57 =item * $frame - the L<Net::AMQP::Frame> instance
58  
59 =back
60  
61 Returns string representing type, typically the base class with Net::AMQP::Protocol prefix removed.
62  
63 =cut
64  
65 sub amqp_frame_type {
66 22 ▶ my ($frame) = @_;
Subroutine amqp_frame_type: called CC=5 SCAR=16.3
Pod documented
67 22 ▶ return 'Header' if $frame->isa('Net::AMQP::Frame::Header');
Branch: 1 branch
BranchTrueFalseTotal
if $frame->isa("Net::AMQP::Frame::Header") 0 22 22
68 22 ▶ return 'Heartbeat' if $frame->isa('Net::AMQP::Frame::Heartbeat');
Branch: 1 branch
BranchTrueFalseTotal
if $frame->isa("Net::AMQP::Frame::Heartbeat") 0 22 22
69 22 ▶ return 'Unknown' unless $frame->can('method_frame');
Branch: 1 branch
BranchTrueFalseTotal
unless $frame->can("method_frame") 0 22 22
70  
71 22 my $method_frame = shift->method_frame;
72 22 my $ref = ref $method_frame;
73 22 ▶ return $types{$ref} if exists $types{$ref};
Branch: 1 branch
BranchTrueFalseTotal
if exists $types{$ref} 11 11 22
74 11 my $re = qr/^Net::AMQP::Protocol::([^:]+::[^:]+)$/;
75 11 my ($frame_type) = grep /$re/, Class::ISA::self_and_super_path($ref);
76 11 ($frame_type) = $frame_type =~ $re;
77 11 $types{$ref} = $frame_type;
78 11 return $frame_type;
79 }
80 }
81  
82 {
83 18 my %amqp_codes = (
84 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.' },
85 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.' },
86 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.' },
87 320 => { message => 'connectionforced', type => 'connection', description => 'An operator intervened to close the connection for some reason. The client may retry at some later date.' },
88 402 => { message => 'invalidpath', type => 'connection', description => 'The client tried to work with an unknown virtual host.' },
89 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.' },
90 404 => { message => 'notfound', type => 'channel', description => 'The client attempted to work with a server entity that does not exist.' },
91 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.' },
92 406 => { message => 'preconditionfailed', type => 'channel', description => 'The client requested a method that was not allowed because some precondition failed.' },
93 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.' },
94 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.' },
95 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.' },
96 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.' },
97 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.' },
98 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.' },
99 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.' },
100 540 => { message => 'notimplemented', type => 'connection', description => 'The client tried to use functionality that is not implemented in the server.' },
101 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.' },
102 );
103  
104 =head2 message_for_code
105  
106 Returns the name (short message) corresponding to the given status code.
107  
108 Example:
109  
110 message_for_code(540) => 'not implemented'
111  
112 =cut
113  
114 sub message_for_code {
115 0 ▶ my ($code) = @_;
Subroutine message_for_code: not called CC=1 SCAR=6.9
Pod documented
116 $amqp_codes{$code}{message}
117 0 }
118  
119 =head2 description_for_code
120  
121 Returns the description (long message) corresponding to the given status code.
122  
123 =cut
124  
125 sub description_for_code {
126 0 ▶ my ($code) = @_;
Subroutine description_for_code: not called CC=1 SCAR=6.9
Pod documented
127 $amqp_codes{$code}{description}
128 0 }
129  
130 =head2 type_for_code
131  
132 Returns the type for the given status code - typically "channel" or "connection".
133  
134 =cut
135  
136 sub type_for_code {
137 0 ▶ my ($code) = @_;
Subroutine type_for_code: not called CC=1 SCAR=6.9
Pod documented
138 $amqp_codes{$code}{type}
139 0 }
140 }
141  
142 18 1;
143  
144 __END__
« AMQP/Server/Protocol.pm ↑ Summary AMQP/Server/Connection.pm »