WebSocket/Constants.pm

filter: Statementstmt 86.6% 26 / 30 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 3 totaltotal 77.7% 35 / 45 CC 3 SCAR 7.9
CC
3
Cov
82%
opcode_to_type
6.0
status_code_to_name
2.0
BEGIN
1.0
CRAP 2.2
« WebSocket/HTTP_R.pm ↑ Summary WebSocket/PMCE/deflate/Data/Streamer.pm »
1 package Net::WebSocket::Constants;
2  
3 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 31 ▶use constant OPCODE => {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 continuation => 0,
8 text => 1,
9 binary => 2,
10 close => 8,
11 ping => 9,
12 pong => 10,
13 31 };
14  
15 31 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
16 31 PROTOCOL_VERSION => 13,
17 REQUIRED_HTTP_METHOD => 'GET',
18 REQUIRED_HTTP_STATUS => 101,
19 REQUIRED_REQUEST_PROTOCOL => 'HTTP/1.1',
20 31 };
21  
22 #These names are taken from:
23 #https://msdn.microsoft.com/en-us/library/windows/desktop/hh449350(v=vs.85).aspx
24 # … however, the up-to-date list of canonical codes is at:
25 #https://www.iana.org/assignments/websocket/websocket.xml
26 31 ▶use constant STATUS => {
Subroutine BEGIN: called CC=1 SCAR=0.0
27 SUCCESS => 1000,
28 ENDPOINT_UNAVAILABLE => 1001,
29 PROTOCOL_ERROR => 1002,
30 INVALID_DATA_TYPE => 1003,
31  
32 #These are never actually sent.
33 #EMPTY_CLOSE => 1005,
34 #ABORTED_CLOSE => 1006,
35  
36 INVALID_PAYLOAD => 1007,
37 POLICY_VIOLATION => 1008,
38 MESSAGE_TOO_BIG => 1009,
39 UNSUPPORTED_EXTENSIONS => 1010,
40  
41 #Post-RFC, “server error” was changed to “internal error”.
42 #We accept both names; code-to-name conversion always returns this one.
43 INTERNAL_ERROR => 1011,
44 SERVER_ERROR => 1011,
45  
46 #These are part of the IANA registry but are not in Microsoft’s enum.
47 SERVICE_RESTART => 1012,
48 TRY_AGAIN_LATER => 1013,
49 BAD_GATEWAY => 1014,
50  
51 #RFC says not to use this one,
52 #but MS has it in their enum.
53 #SECURE_HANDSHAKE_ERROR => 1015,
54 31 };
55  
56 #----------------------------------------------------------------------
57  
58 31 my %status_code_name;
59  
60 43 ▶sub status_name_to_code {
Subroutine status_name_to_code: called CC=1 SCAR=0.0
Pod undocumented
61 43 my ($name) = @_;
62  
63 43 return STATUS()->{$name};
64 }
65  
66 7 ▶sub status_code_to_name {
Subroutine status_code_to_name: called CC=2 SCAR=6.9
Pod undocumented
67 7 my ($code) = @_;
68  
69 7 ▶ if (!%status_code_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%status_code_name) 4 3 7
70 4 my %copy = %{ STATUS() };
71 4 delete $copy{'SERVER_ERROR'};
72 4 %status_code_name = reverse %copy;
73 }
74  
75 7 return $status_code_name{$code};
76 }
77  
78 #----------------------------------------------------------------------
79  
80 my %opcode_type;
81  
82 0 ▶sub opcode_to_type {
Subroutine opcode_to_type: not called CC=2 SCAR=17.9
Pod undocumented
83 0 my ($opcode) = @_;
84  
85 0 ▶ %opcode_type = reverse %{ OPCODE() } if !%opcode_type;
Branch: 1 branch
BranchTrueFalseTotal
unless %opcode_type 0 0 0
86  
87 0 return $opcode_type{$opcode};
88 }
89  
90 31 1;
« WebSocket/HTTP_R.pm ↑ Summary WebSocket/PMCE/deflate/Data/Streamer.pm »