WebSocket.pm

filter: Statementstmt 90.2% 65 / 72 Branchbran 50.0% 1 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 86.9% 20 / 23 Podpod 100% 4 / 4 totaltotal 85.8% 91 / 106 CC 3 SCAR 3.2
CC
3
Cov
87%
init
3.2
client
2.0
compression_threshold
2.0
CRAP 1.4
« WebSocket/Handshake.pm ↑ Summary WebSocket/Exception.pm »
1 ##----------------------------------------------------------------------------
2 ## WebSocket Client & Server - ~/lib/WebSocket.pm
3 ## Version v0.2.1
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/09/13
7 ## Modified 2024/09/05
8 ## You can use, copy, modify and redistribute this package and associated
9 ## files under the same terms as Perl itself.
10 ##----------------------------------------------------------------------------
11 package WebSocket;
12 BEGIN
13 8 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 # <https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1>
19 8 ▶ use constant WS_OK => 1000;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶ use constant WS_GONE => 1001;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶ use constant WS_PROTOCOL_ERROR => 1002;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 8 ▶ use constant WS_NOT_ACCEPTABLE => 1003;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 # 1004 is reserved and undefined
24 8 ▶ use constant WS_NO_STATUS => 1005;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 8 ▶ use constant WS_CLOSED_ABNORMALLY => 1006;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 # 1007 indicates that an endpoint is terminating the connection
27 # because it has received data that was supposed to be UTF-8 (such
28 # as in a text frame) that was in fact not valid UTF-8 [RFC3629].
29 8 ▶ use constant WS_BAD_MESSAGE => 1007;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 8 ▶ use constant WS_FORBIDDEN => 1008;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 8 ▶ use constant WS_MESSAGE_TOO_LARGE => 1009;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 8 ▶ use constant WS_EXTENSIONS_NOT_AVAILABLE => 1010;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 8 ▶ use constant WS_INTERNAL_SERVER_ERROR => 1011;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 # Nothing defined for 1012, 1013 and 1014 yet as of 2021-09-14
35 8 ▶ use constant WS_TLS_HANDSHAKE_FAIL => 1015;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 8 ▶ use constant WEBSOCKET_DRAFT_VERSION_DEFAULT => 'draft-ietf-hybi-17';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 # 10kb
38 8 ▶ use constant WEBSOCKET_COMPRESSION_THRESHOLD => 10240;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 8 our %EXPORT_TAGS = ( all => [qw( WS_OK WS_GONE WS_PROTOCOL_ERROR WS_NOT_ACCEPTABLE WS_NO_STATUS WS_CLOSED_ABNORMALLY WS_BAD_MESSAGE WS_FORBIDDEN WS_MESSAGE_TOO_LARGE WS_EXTENSIONS_NOT_AVAILABLE WS_INTERNAL_SERVER_ERROR WS_TLS_HANDSHAKE_FAIL WEBSOCKET_DRAFT_VERSION_DEFAULT )] );
40 8 $EXPORT_TAGS{ws} = $EXPORT_TAGS{all};
41 8 our @EXPORT_OK = qw( WS_OK WS_GONE WS_PROTOCOL_ERROR WS_NOT_ACCEPTABLE WS_NO_STATUS WS_CLOSED_ABNORMALLY WS_BAD_MESSAGE WS_FORBIDDEN WS_MESSAGE_TOO_LARGE WS_EXTENSIONS_NOT_AVAILABLE WS_INTERNAL_SERVER_ERROR WS_TLS_HANDSHAKE_FAIL WEBSOCKET_DRAFT_VERSION_DEFAULT );
42 8 our $VERSION = 'v0.2.1';
43 };
44  
45 sub init
46 76 ▶{
Subroutine init: called CC=3 SCAR=11.6
Pod documented
47 76 my $self = shift( @_ );
48 76 ▶ $self->{compression_threshold} = WEBSOCKET_COMPRESSION_THRESHOLD unless( defined( $self->{compression_threshold} ) && length( $self->{compression_threshold} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"compression_threshold"} and length $self->{"compression_threshold"} 76 0 76
Condition33%1/3
defined $self->{"compression_threshold"} and length $self->{"compression_threshold"}
!ll&&!rl&&r
7600
MC/DC0%0/2
defined $self->{"compression_threshold"} and length $self->{"compression_threshold"}
defined $self->{"compression_threshold"} length $self->{"compression_threshold"}
Truth table33%1/3
A and B
A= defined $self->{"compression_threshold"}B= length $self->{"compression_threshold"}
ABresult
0X0
100
111
49 76 $self->{_init_strict_use_sub} = 1;
50 76 $self->{_exception_class} = 'WebSocket::Exception';
51 76 $self->SUPER::init( @_ );
52 76 return( $self );
53 }
54  
55 sub client
56 0 ▶{
Subroutine client: not called CC=1 SCAR=6.9
Pod documented
57 0 my $self = shift( @_ );
58 0 require WebSocket::Client;
59 0 return( WebSocket::Client->new( @_ ) );
60 }
61  
62 0 ▶sub compression_threshold { return( shift->_set_get_number( 'compression_threshold', @_ ) ); }
Subroutine compression_threshold: not called CC=1 SCAR=6.9
Pod documented
63  
64 sub server
65 0 ▶{
Subroutine server: not called CC=1 SCAR=6.9
Pod documented
66 0 my $self = shift( @_ );
67 0 require WebSocket::Server;
68 0 return( WebSocket::Server->new( @_ ) );
69 }
70  
71 8 1;
72 # NOTE: POD
73 __END__
« WebSocket/Handshake.pm ↑ Summary WebSocket/Exception.pm »