| 1 | #+############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # File: Net/STOMP/Client/Frame.pm # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Description: Frame support for Net::STOMP::Client # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | #-############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # module definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | package Net::STOMP::Client::Frame; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use 5.005; # need the four-argument form of substr() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | our $VERSION = "2.4"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | our $REVISION = sprintf("%d.%02d", q$Revision: 2.4 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # used modules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | ▶ | use Encode qw(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | use No::Worries::Die qw(dief); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | ▶ | use No::Worries::Export qw(export_control); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | use No::Worries::Log qw(log_debug); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | use Params::Validate qw(validate validate_pos :types); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # constants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | ▶ | use constant I_COMMAND => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | ▶ | use constant I_HEADERS => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | ▶ | use constant I_BODY => 2; # stored as reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # global variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | our( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # public | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | $DebugBodyLength, # the maximum length of body that will be debugged | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | $StrictEncode, # true if encoding/decoding operations should be strict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # private | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | $_HeaderNameRE, # regular expression matching a header name (STOMP 1.0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | %_EncMap1, # map to \-encode some chars in the header (STOMP 1.1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | %_DecMap1, # map to \-decode some chars in the header (STOMP 1.1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | $_EncSet1, # set of chars to encode in the header (STOMP 1.1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | %_EncMap2, # map to \-encode some chars in the header (STOMP >= 1.2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | %_DecMap2, # map to \-decode some chars in the header (STOMP >= 1.2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | $_EncSet2, # set of chars to encode in the header (STOMP >= 1.2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # public | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | $DebugBodyLength = 256; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | $StrictEncode = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # private | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | $_HeaderNameRE = q/[_a-zA-Z0-9\-\.]+/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | %_EncMap1 = %_EncMap2 = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | "\r" => "\\r", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | "\n" => "\\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ":" => "\\c", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | "\\" => "\\\\", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | delete($_EncMap1{"\r"}); # \r encoding is only for STOMP >= 1.2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | %_DecMap1 = reverse(%_EncMap1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 6 | $_EncSet1 = "[".join("", map(sprintf("\\x%02x", ord($_)), keys(%_EncMap1)))."]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | %_DecMap2 = reverse(%_EncMap2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 6 | $_EncSet2 = "[".join("", map(sprintf("\\x%02x", ord($_)), keys(%_EncMap2)))."]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | #+++############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # helpers # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | #---############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # helper to guess the encoding to use from the content type header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | sub _encoding ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | ▶ | my($type) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encoding: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | ▶ | if ($type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | ▶ | if ($type =~ /^text\/[\w\-]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | return("UTF-8"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } elsif (";$type;" =~ /\;\s*charset=\"?([\w\-]+)\"?\s*\;/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | return(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 5 | return(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # debugging helpers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | sub _debug_command ($$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my($what, $command) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_debug_command: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | log_debug("%s %s frame", $what, $command); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | sub _debug_header ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my($header) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_debug_header: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my($offset, $length, $line, $char); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $length = length($header); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $offset = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | while ($offset < $length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $line = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $char = ord(substr($header, $offset, 1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $offset++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ($char == 0x0a) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ▶ | } elsif (0x20 <= $char and $char <= 0x7e and $char != 0x25) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
32 <= $char and $char <= 126 and $char != 37
32 <= $char and $char <= 126
MC/DC0%0/3
32 <= $char and $char <= 126 and $char != 37
32 <= $char
$char <= 126
$char != 37
Truth table0%0/4
A and B and C
A= 32 <= $charB= $char <= 126C= $char != 37
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $line .= sprintf("%c", $char); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $line .= sprintf("%%%02x", $char); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | last if $offset == $length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | log_debug(" H %s", $line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | sub _debug_body ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my($body) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_debug_body: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my($offset, $length, $line, $ascii, $char); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $length = length($body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if ($DebugBodyLength and $length > $DebugBodyLength) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Net::STOMP::Client::Frame::DebugBodyLength and $length > $Net::STOMP::Client::Frame::DebugBodyLength
MC/DC0%0/2
$Net::STOMP::Client::Frame::DebugBodyLength and $length > $Net::STOMP::Client::Frame::DebugBodyLength
$Net::STOMP::Client::Frame::DebugBodyLength
$length > $Net::STOMP::Client::Frame::DebugBodyLength
Truth table0%0/3
A and B
A= $Net::STOMP::Client::Frame::DebugBodyLengthB= $length > $Net::STOMP::Client::Frame::DebugBodyLength
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | substr($body, $DebugBodyLength, $length - $DebugBodyLength, ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $length = $DebugBodyLength; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $offset = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | while ($length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $line = sprintf("%04x", $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $ascii = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | foreach my $index (0 .. 15) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if (($index & 3) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $line .= " "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $ascii .= " "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ($index < $length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $char = ord(substr($body, $index, 1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $line .= sprintf("%02x", $char); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | $ascii .= sprintf("%c", (0x20 <= $char && $char <= 0x7e) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
32 <= $char and $char <= 126
MC/DC0%0/2
32 <= $char and $char <= 126
32 <= $char
$char <= 126
Truth table0%0/3
A and B
A= 32 <= $charB= $char <= 126
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | $char : 0x2e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $line .= " "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $ascii .= " "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | log_debug(" B %s %s", $line, $ascii); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $offset += 16; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $length -= 16; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | substr($body, 0, 16, ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | #+++############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # object oriented interface # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | #---############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # notes: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # - $self->[I_COMMAND] defaults to SEND so it's always defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # - $self->[I_HEADERS] defaults to {} so it's always set to a hash ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # - $self->[I_BODY] defaults to \"" so it's always set to a scalar ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 6 | my %new_options = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | "command" => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | optional => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | type => SCALAR, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | regex => qr/^[A-Z]{2,16}$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | "headers" => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | optional => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | type => HASHREF, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | "body_reference" => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | optional => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | type => SCALARREF, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | "body" => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | optional => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | type => SCALAR, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | sub new : method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 20 | ▶ | my($class, %option, $object); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 20 | ▶ | if ($Net::STOMP::Client::NoParamsValidation) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 11 | ($class, %option) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 9 | $class = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 9 | ▶ | %option = validate(@_, \%new_options) if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 18 | ▶ | if (defined($option{"body"})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # handle the convenient body option | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | dief("options body and body_reference are " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 3 | ▶ | "mutually exclusive") if $option{"body_reference"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | $option{"body_reference"} = \ delete($option{"body"}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 17 | ▶ | $option{"command"} ||= "SEND"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$option{"command"} ||= "SEND"
MC/DC100%1/1
$option{"command"} ||= "SEND"
$option{"command"}
Truth table100%2/2
A
A= $option{"command"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 17 | ▶ | $option{"headers"} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$option{"headers"} ||= {}
MC/DC100%1/1
$option{"headers"} ||= {}
$option{"headers"}
Truth table100%2/2
A
A= $option{"headers"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 17 | ▶ | $option{"body_reference"} ||= \ ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$option{"body_reference"} ||= \""
MC/DC100%1/1
$option{"body_reference"} ||= \""
$option{"body_reference"}
Truth table100%2/2
A
A= $option{"body_reference"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 17 | $object = [ @option{ qw(command headers body_reference) } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 17 | return(bless($object, $class)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # standard getters and setters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | sub command : method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 4 | ▶ | my($self, $value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=6 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | $self = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | ▶ | return($self->[I_COMMAND]) if @_ == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $value = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if (@_ == 1 and defined($value) and ref($value) eq "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
@_ == 1 and defined $value and ref $value eq "" and $value =~ /$new_options{"command"}{"regex"}/
@_ == 1 and defined $value and ref $value eq ""
@_ == 1 and defined $value
MC/DC0%0/4
@_ == 1 and defined $value and ref $value eq "" and $value =~ /$new_options{"command"}{"regex"}/
@_ == 1
defined $value
ref $value eq ""
$value =~ /$new_options{"command"}{"regex"}/
Truth table0%0/5
A and B and C and D
A= @_ == 1B= defined $valueC= ref $value eq ""D= $value =~ /$new_options{"command"}{"regex"}/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | and $value =~ $new_options{"command"}{"regex"}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $self->[I_COMMAND] = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | return($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # otherwise complain... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | validate_pos(@_, $new_options{"command"}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | sub headers : method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | my($self, $value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
headers: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $self = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | return($self->[I_HEADERS]) if @_ == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $value = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if (@_ == 1 and ref($value) eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and ref $value eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $value eq "HASH"
@_ == 1
ref $value eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $value eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $self->[I_HEADERS] = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | return($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # otherwise complain... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | validate_pos(@_, $new_options{"headers"}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | sub body_reference : method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | my($self, $value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_reference: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $self = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | return($self->[I_BODY]) if @_ == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $value = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if (@_ == 1 and ref($value) eq "SCALAR") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and ref $value eq "SCALAR"
MC/DC0%0/2
@_ == 1 and ref $value eq "SCALAR"
@_ == 1
ref $value eq "SCALAR"
Truth table0%0/3
A and B
A= @_ == 1B= ref $value eq "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $self->[I_BODY] = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | return($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # otherwise complain... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | validate_pos(@_, $new_options{"body_reference"}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # convenient body getter and setter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | sub body : method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 9 | ▶ | my($self, $value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body: called CC=5 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 9 | $self = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 9 | ▶ | return(${ $self->[I_BODY] }) if @_ == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $value = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if (@_ == 1 and defined($value) and ref($value) eq "") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@_ == 1 and defined $value and ref $value eq ""
@_ == 1 and defined $value
MC/DC0%0/3
@_ == 1 and defined $value and ref $value eq ""
@_ == 1
defined $value
ref $value eq ""
Truth table0%0/4
A and B and C
A= @_ == 1B= defined $valueC= ref $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $self->[I_BODY] = \$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | return($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # otherwise complain... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | validate_pos(@_, $new_options{"body"}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # convenient individual header getter and setter: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # - $frame->header($key): get | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # - $frame->header($key, $value): set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # - $frame->header($key, undef): delete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 6 | my @header_options = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | { optional => 0, type => SCALAR }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | { optional => 1, type => SCALAR|UNDEF }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | sub header : method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 8 | ▶ | my($self, $key, $value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header: called CC=7 SCAR=30.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 8 | $self = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 8 | $key = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 8 | ▶ | if (defined($key) and ref($key) eq "") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $key and ref $key eq ""
MC/DC0%0/2
defined $key and ref $key eq ""
defined $key
ref $key eq ""
Truth table33%1/3
A and B
A= defined $keyB= ref $key eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 8 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # get | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 8 | return($self->[I_HEADERS]{$key}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } elsif (@_ == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $value = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | if (defined($value)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if (ref($value) eq "") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $self->[I_HEADERS]{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | return($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # delete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | delete($self->[I_HEADERS]{$key}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | return($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # otherwise complain... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | validate_pos(@_, @header_options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | #+++############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # parsing # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | #---############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # parse the given buffer reference and return a hash of pointers to frame parts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # if the frame is complete or false otherwise; an optional hash can be given to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # represent state information from a previous parse on the exact same buffer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # note: for STOMP <1.2, we may miss a final \r in command or header as it would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # be part of the eol; up to the caller to be strict and check for its presence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # or to simply ignore this corner case for the sake of simplicity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 6 | my %parse_options = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | state => { optional => 1, type => HASHREF }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | sub parse ($@) { ## no critic 'ProhibitExcessComplexity' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 44 | ▶ | my($bufref, %option, $state, $index, $buflen, $eol, $tmp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=25 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # setup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 44 | ▶ | if ($Net::STOMP::Client::NoParamsValidation) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 11 | ($bufref, %option) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 33 | ▶ | validate_pos(@_, { type => SCALARREF }) unless ref($_[0]) eq "SCALAR"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 33 | $bufref = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 33 | ▶ | %option = validate(@_, \%parse_options) if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 44 | ▶ | $state = $option{state} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$option{'state'} || {}
MC/DC100%1/1
$option{'state'} || {}
$option{'state'}
Truth table100%2/2
A
A= $option{'state'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # before: allow 0 or more end-of-line characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # (note: we allow \n and \r\n but also \r as EOL, this should not be a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # problem in practice) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 44 | ▶ | unless (exists($state->{before_len})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 44 | ▶ | return(0) unless ${$bufref} =~ /^[\r\n]*[^\r\n]/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 35 | $state->{before_len} = pos(${$bufref}) - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # command: everything up to the first EOL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 35 | ▶ | unless (exists($state->{command_len})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 35 | $state->{command_idx} = $state->{before_len}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 35 | $index = index(${$bufref}, "\n", $state->{command_idx}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 35 | ▶ | return(0) if $index < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 33 | $state->{command_len} = $index - $state->{command_idx}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 33 | ▶ | if (substr(${$bufref}, $index - 1, 1) eq "\r") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 3 | $state->{command_len}--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 3 | $state->{command_eol} = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 30 | $state->{command_eol} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | # header: everything up to the first double EOL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 33 | ▶ | unless (exists($state->{header_len})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 33 | $state->{header_idx} = $state->{command_idx} + $state->{command_len}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 33 | $eol = $state->{command_eol}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 33 | $tmp = $state->{header_idx} + $eol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 33 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 56 | $index = index(${$bufref}, "\n", $tmp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 56 | ▶ | return(0) if $index < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 54 | ▶ | if ($index == $tmp) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 25 | $state->{header_eol} = $eol + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 25 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | ▶ | } elsif ($index == $tmp + 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$index == $tmp + 1 and substr(${$bufref;}, $tmp, 1) eq "\r"
MC/DC50%1/2
$index == $tmp + 1 and substr(${$bufref;}, $tmp, 1) eq "\r"
$index == $tmp + 1
substr(${$bufref;}, $tmp, 1) eq "\r"
Truth table66%2/3
A and B
A= $index == $tmp + 1B= substr(${$bufref;}, $tmp, 1) eq "\r"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 6 | and substr(${$bufref}, $tmp, 1) eq "\r") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 6 | $state->{header_eol} = $eol + 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 6 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 23 | ▶ | $eol = substr(${$bufref}, $index - 1, 1) eq "\r" ? 2 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 23 | $tmp = $index + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 31 | $index -= $state->{header_eol} - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 31 | ▶ | if ($index == $state->{header_idx}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # empty header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 12 | $state->{header_len} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # non-empty header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 19 | $state->{header_idx} += $state->{command_eol}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 19 | $state->{header_len} = $index - $state->{header_idx}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 19 | $tmp = substr(${$bufref}, $state->{header_idx} - 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 19 | $state->{header_len} + 3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 19 | ▶ | $state->{content_length} = $1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | if $tmp =~ /\ncontent-length *: *(\d+) *\r?\n/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # body: everything up to content-length bytes or the first NULL byte | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 31 | $buflen = length(${$bufref}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | $state->{body_idx} = $state->{header_idx} + $state->{header_len} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 31 | + $state->{header_eol}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 31 | ▶ | if (exists($state->{content_length})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # length is known | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | return(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 3 | ▶ | if $buflen < $state->{body_idx} + $state->{content_length} + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 3 | $state->{body_len} = $state->{content_length}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 3 | $tmp = substr(${$bufref}, $state->{body_idx} + $state->{body_len}, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 3 | ▶ | dief("missing NULL byte at end of frame") unless $tmp eq "\0"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # length is not known | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 28 | $index = index(${$bufref}, "\0", $state->{body_idx}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 28 | ▶ | return(0) if $index < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 24 | $state->{body_len} = $index - $state->{body_idx}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | # after: allow 0 or more end-of-line characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # (note: we allow \n and \r\n but also \r as EOL, this should not be a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | # problem in practice) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 26 | $state->{after_idx} = $state->{body_idx} + $state->{body_len} + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 26 | $state->{after_len} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 26 | ▶ | while ($buflen > $state->{after_idx} + $state->{after_len}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 13 | $tmp = substr(${$bufref}, $state->{after_idx} + $state->{after_len}, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 13 | ▶ | last unless $tmp eq "\r" or $tmp eq "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tmp eq "\r" or $tmp eq "\n"
MC/DC100%2/2
$tmp eq "\r" or $tmp eq "\n"
$tmp eq "\r"
$tmp eq "\n"
Truth table100%3/3
A or B
A= $tmp eq "\r"B= $tmp eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 9 | $state->{after_len}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 26 | $state->{total_len} = $state->{after_idx} + $state->{after_len}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # so far so good ;-) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 26 | return($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | #+++############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # decoding # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | #---############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # decode the given string reference and return a frame object if the frame is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # complete or false otherwise; take the same options as parse() plus debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # and version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # side effect: in case a frame is successfully decoded, the given string is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # _modified_ to remove the corresponding encoded frame | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 6 | my %decode_options = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | debug => { optional => 1, type => UNDEF|SCALAR }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | state => { optional => 1, type => HASHREF }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | strict => { optional => 1, type => BOOLEAN }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | version => { optional => 1, type => SCALAR, regex => qr/^1\.\d$/ }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | sub decode ($@) { ## no critic 'ProhibitExcessComplexity' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 11 | ▶ | my($bufref, %option, $check, $state, $key, $val, $errors, $tmp, %frame); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode: called CC=36 SCAR=43.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | # setup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 11 | ▶ | if ($Net::STOMP::Client::NoParamsValidation) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ($bufref, %option) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 11 | ▶ | validate_pos(@_, { type => SCALARREF }) unless ref($_[0]) eq "SCALAR"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 11 | $bufref = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 11 | ▶ | %option = validate(@_, \%decode_options) if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 11 | ▶ | $option{debug} ||= ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$option{"debug"} ||= ""
MC/DC0%0/1
$option{"debug"} ||= ""
$option{"debug"}
Truth table50%1/2
A
A= $option{"debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 11 | ▶ | $state = $option{state} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$option{'state'} || {}
MC/DC0%0/1
$option{'state'} || {}
$option{'state'}
Truth table50%1/2
A
A= $option{'state'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 11 | ▶ | $option{strict} = $StrictEncode unless defined($option{strict}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 11 | ▶ | $option{version} ||= "1.0"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$option{"version"} ||= "1.0"
MC/DC0%0/1
$option{"version"} ||= "1.0"
$option{"version"}
Truth table50%1/2
A
A= $option{"version"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 11 | ▶ | $check = $option{strict} ? Encode::FB_CROAK : Encode::FB_DEFAULT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | # frame parsing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 11 | local $Net::STOMP::Client::NoParamsValidation = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 11 | $tmp = parse($bufref, state => $state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 11 | ▶ | return(0) unless $tmp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # frame debugging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 11 | ▶ | if ($option{debug} =~ /\b(command|all)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | $tmp = substr(${$bufref}, $state->{command_idx}, $state->{command_len}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | _debug_command("decoding", $tmp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 11 | ▶ | if ($option{debug} =~ /\b(header|all)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | $tmp = substr(${$bufref}, $state->{header_idx}, $state->{header_len}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | _debug_header($tmp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 11 | ▶ | if ($option{debug} =~ /\b(body|all)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | $tmp = substr(${$bufref}, $state->{body_idx}, $state->{body_len}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | _debug_body($tmp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # frame decoding (command) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | $frame{"command"} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 11 | substr(${$bufref}, $state->{command_idx}, $state->{command_len}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | dief("invalid command: %s", $frame{"command"}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 11 | ▶ | unless $frame{"command"} =~ $new_options{"command"}{"regex"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | # frame decoding (headers) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 11 | ▶ | if ($state->{header_len}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 11 | $frame{"headers"} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 11 | $tmp = substr(${$bufref}, $state->{header_idx}, $state->{header_len}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 11 | ▶ | if ($option{version} ge "1.1") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | # STOMP >=1.1 behavior: the header is assumed to be UTF-8 encoded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 7 | $tmp = Encode::decode("UTF-8", $tmp, $check); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 11 | ▶ | if ($option{version} eq "1.0") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | # STOMP 1.0 behavior: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | # - we arbitrarily restrict the header name as a safeguard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # - space surrounding the comma and at end of line is not significant | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | # - last header wins (not specified explicitly but reasonable default) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 4 | foreach my $line (split(/\n/, $tmp)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 5 | ▶ | if ($line =~ /^($_HeaderNameRE)\s*:\s*(.*?)\s*$/o) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 5 | $frame{"headers"}{$1} = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | dief("invalid header: %s", $line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } elsif ($option{version} eq "1.1") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | # STOMP 1.1 behavior: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # - header names and values can contain any byte except \n or : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # - space is significant | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # - only the first header entry should be used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # - handle backslash escaping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 6 | foreach my $line (split(/\n/, $tmp)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 8 | ▶ | if ($line =~ /^([^\n\:]+):([^\n\:]*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 8 | ($key, $val, $errors) = ($1, $2, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | dief("invalid header: %s", $line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 8 | ▶ | $key =~ s/(\\.)/$_DecMap1{$1}||$errors++/eg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 8 | ▶ | $val =~ s/(\\.)/$_DecMap1{$1}||$errors++/eg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 8 | ▶ | dief("invalid header: %s", $line) if $errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | $frame{"headers"}{$key} = $val | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 8 | ▶ | unless exists($frame{"headers"}{$key}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # STOMP 1.2 behavior: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | # - header names and values can contain any byte except \r or \n or : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | # - space is significant | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | # - only the first header entry should be used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | # - handle backslash escaping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 1 | foreach my $line (split(/\r?\n/, $tmp)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 2 | ▶ | if ($line =~ /^([^\r\n\:]+):([^\r\n\:]*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 2 | ($key, $val, $errors) = ($1, $2, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | dief("invalid header: %s", $line) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 2 | ▶ | $key =~ s/(\\.)/$_DecMap2{$1}||$errors++/eg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 2 | ▶ | $val =~ s/(\\.)/$_DecMap2{$1}||$errors++/eg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 2 | ▶ | dief("invalid header: %s", $line) if $errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | $frame{"headers"}{$key} = $val | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 2 | ▶ | unless exists($frame{"headers"}{$key}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | # frame decoding (body) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 11 | ▶ | if ($state->{body_len}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 11 | $tmp = substr(${$bufref}, $state->{body_idx}, $state->{body_len}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 11 | ▶ | if ($option{version} ge "1.1" and $frame{"headers"}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$option{"version"} ge "1.1" and $frame{"headers"}
MC/DC50%1/2
$option{"version"} ge "1.1" and $frame{"headers"}
$option{"version"} ge "1.1"
$frame{"headers"}
Truth table66%2/3
A and B
A= $option{"version"} ge "1.1"B= $frame{"headers"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | # STOMP >=1.1 behavior: the body may be encoded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 7 | $val = _encoding($frame{"headers"}{"content-type"}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 7 | ▶ | if ($val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 1 | $tmp = Encode::decode($val, $tmp, $check); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 11 | $frame{"body_reference"} = \$tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | # so far so good | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 11 | substr(${$bufref}, 0, $state->{total_len}, ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 11 | %{ $state } = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 11 | local $Net::STOMP::Client::NoParamsValidation = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 11 | return(__PACKAGE__->new(%frame)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | #+++############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | # encoding # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | #---############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | # encode the given frame object and return a string reference; take the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | # options as decode() except state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 6 | my %encode_options = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | debug => { optional => 1, type => UNDEF|SCALAR }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | strict => { optional => 1, type => BOOLEAN }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | version => { optional => 1, type => SCALAR, regex => qr/^1\.\d$/ }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | sub encode : method { ## no critic 'ProhibitExcessComplexity' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | my($self, %option, $check, $header, $tmp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: not called CC=23 SCAR=63.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | my($body, $bodyref, $bodylen, $conlen, $key, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | # setup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | if ($Net::STOMP::Client::NoParamsValidation) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | ($self, %option) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | $self = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | ▶ | %option = validate(@_, \%encode_options) if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | ▶ | $option{debug} ||= ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$option{"debug"} ||= ""
MC/DC0%0/1
$option{"debug"} ||= ""
$option{"debug"}
Truth table0%0/2
A
A= $option{"debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | ▶ | $option{strict} = $StrictEncode unless defined($option{strict}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | ▶ | $option{version} ||= "1.0"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$option{"version"} ||= "1.0"
MC/DC0%0/1
$option{"version"} ||= "1.0"
$option{"version"}
Truth table0%0/2
A
A= $option{"version"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | ▶ | $check = $option{strict} ? Encode::FB_CROAK : Encode::FB_DEFAULT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | # body encoding (must be done first because of the content-length header) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | if ($option{version} ge "1.1") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | $tmp = _encoding($self->[I_HEADERS]{"content-type"}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | $tmp = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | if ($tmp) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | $body = Encode::encode($tmp, ${ $self->[I_BODY] }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | $check | Encode::LEAVE_SRC); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | $bodyref = \$body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | $bodyref = $self->[I_BODY]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | $bodylen = length(${ $bodyref }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | # content-length header handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | $tmp = $self->[I_HEADERS]{"content-length"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | if (defined($tmp)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | # content-length is defined: we use it unless it is the empty string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | # (which means do not set the content-length even with a body) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | ▶ | $conlen = $tmp unless $tmp eq ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # content-length is not defined (default behavior): we set it to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # body length only if the body is not empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | $conlen = $bodylen unless $bodylen == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | # header encoding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | $tmp = $self->[I_HEADERS]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | if ($option{version} eq "1.0") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # STOMP 1.0 behavior: no backslash escaping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | $header = join("\n", map($_ . ":" . $tmp->{$_}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | grep($_ ne "content-length", keys(%{ $tmp }))), ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | } elsif ($option{version} eq "1.1") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | # STOMP 1.1 behavior: backslash escaping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | $header = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | ▶ | while (($key, $val) = each(%{ $tmp })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | next if $key eq "content-length"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | $key =~ s/($_EncSet1)/$_EncMap1{$1}/ego; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | $val =~ s/($_EncSet1)/$_EncMap1{$1}/ego; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | $header .= $key . ":" . $val . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | # STOMP 1.2 behavior: backslash escaping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | $header = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | ▶ | while (($key, $val) = each(%{ $tmp })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | next if $key eq "content-length"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | $key =~ s/($_EncSet2)/$_EncMap2{$1}/ego; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | $val =~ s/($_EncSet2)/$_EncMap2{$1}/ego; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | $header .= $key . ":" . $val . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | ▶ | $header .= "content-length:" . $conlen . "\n" if defined($conlen); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | ▶ | if ($option{version} ge "1.1") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # STOMP >=1.1 behavior: the header must be UTF-8 encoded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | $header = Encode::encode("UTF-8", $header, $check); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # frame debugging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | ▶ | if ($option{debug} =~ /\b(command|all)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | _debug_command("encoding", $self->[I_COMMAND]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | ▶ | if ($option{debug} =~ /\b(header|all)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | _debug_header($header); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | if ($option{debug} =~ /\b(body|all)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | _debug_body(${ $bodyref }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | # assemble all the parts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | $tmp = $self->[I_COMMAND] . "\n" . $header . "\n" . ${ $bodyref } . "\0"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | # return a reference to the encoded frame | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | return(\$tmp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | # FIXME: compatibility hack for Net::STOMP::Client 1.x (to be removed one day) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | sub check : method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | ▶ | return(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | #+++############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | # integration with Messaging::Message # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | #---############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | # transform a frame into a message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | sub messagify : method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | ▶ | my($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
messagify: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | ▶ | unless ($Messaging::Message::VERSION) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | eval { require Messaging::Message }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | ▶ | dief("cannot load Messaging::Message: %s", $@) if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | ▶ | return(Messaging::Message->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | "header" => $self->headers(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | "body_ref" => $self->body_reference(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | "text" => _encoding($self->header("content-type")) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | # transform a message into a frame | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | sub demessagify ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | ▶ | my($message, $frame, $content_type); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
demessagify: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | # FIXME: compatibility hack for Net::STOMP::Client 1.x (to be removed one day) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | # normal API, to become: my($message) = @_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | $message = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | ▶ | } elsif (@_ == 2 and $_[0] eq "Net::STOMP::Client::Frame") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
@_ == 2 and $_[0] eq "Net::STOMP::Client::Frame"
MC/DC0%0/2
@_ == 2 and $_[0] eq "Net::STOMP::Client::Frame"
@_ == 2
$_[0] eq "Net::STOMP::Client::Frame"
Truth table0%0/3
A and B
A= @_ == 2B= $_[0] eq "Net::STOMP::Client::Frame"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | # old API, was a class method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | $message = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | validate_pos(@_, { isa => "Messaging::Message" }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | $frame = __PACKAGE__->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | "command" => "SEND", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | "headers" => $message->header(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | "body_reference" => $message->body_ref(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | # handle the text attribute wrt the content-type header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | $content_type = $frame->header("content-type"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | ▶ | if (defined($content_type)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | # make sure the content-type is consistent with the message type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | ▶ | if (_encoding($content_type)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | ▶ | dief("unexpected text content-type for binary message: %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | $content_type) unless $message->text(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | ▶ | dief("unexpected binary content-type for text message: %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | $content_type) if $message->text(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | # set a text content-type if it is missing (this is needed by STOMP >=1.1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | $frame->header("content-type", "text/unknown") if $message->text(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | return($frame); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | # export control | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | sub import : method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 4 | ▶ | my($pkg, %exported); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 4 | $pkg = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 4 | grep($exported{$_}++, qw(demessagify)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 4 | export_control(scalar(caller()), $pkg, \%exported, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||