WebSocket/PMCE/deflate/Client.pm

filter: Statementstmt 100% 40 / 40 Branchbran 93.7% 15 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 98.3% 61 / 62 CC 9 SCAR 16.4
CC
9
Cov
98%
_consume_extension_options
8.0
_create_extension_header_parts
2.0
BEGIN
1.0
CRAP 5.1
« WebSocket/PMCE/deflate/Server.pm ↑ Summary WebSocket/Handshake/Client.pm »
1 package Net::WebSocket::PMCE::deflate::Client;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =encoding utf-8
7  
8 =head1 NAME
9  
10 Net::WebSocket::PMCE::deflate::Client - permessage-deflate for a client
11  
12 =head1 SYNOPSIS
13  
14 my $deflate = Net::WebSocket::PMCE::deflate::Server->new( %opts );
15  
16 #Send this to the server.
17 my $handshake = $deflate->create_handshake_object();
18  
19 #You’ll probably want Net::WebSocket::Handshake
20 #to do this for you, but just in case:
21 #$deflate->consume_parameters( @params_kv );
22  
23 #OPTIONAL: Inspect $deflate to be sure you’re happy with the setup
24 #that the client’s parameters allow.
25  
26 #...and now use this to send/receive messages.
27 my $data_obj = $deflate->create_data_object();
28  
29 =head1 DESCRIPTION
30  
31 See L<Net::WebSocket::PMCE::deflate> for general information about
32 this class.
33  
34 =head1 METHODS
35  
36 =head2 I<OBJ>->consume_parameters( KEY1 => VALUE1, .. )
37  
38 Inherited from the base class. The alterations made in response
39 to the different parameters are:
40  
41 =over
42  
43 =item * <client_no_context_takeover> - Sets the object’s
44 C<deflate_no_context_takeover> flag.
45  
46 =item * <server_no_context_takeover> - If the object’s
47 C<inflate_no_context_takeover> flag is set, and if
48 we do *not* receive this flag from the peer, then we C<die()>.
49 This option is ignored otherwise.
50  
51 =item * <client_max_window_bits> - If given and less than the object’s
52 C<deflate_max_window_bits> option, then that option is reduced to the
53 new value.
54  
55 =item * <server_max_window_bits> - If given and less than the object’s
56 C<inflate_max_window_bits> option, then that option is reduced to the
57 new value. If given and B<greater> than the object’s
58 C<inflate_max_window_bits> option, then we C<die()>.
59  
60 =back
61  
62 =cut
63  
64 2 ▶use parent qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
65 Net::WebSocket::PMCE::deflate
66 2 );
67  
68 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
69 2 _PEER_NO_CONTEXT_TAKEOVER_PARAM => 'server_no_context_takeover',
70 _LOCAL_NO_CONTEXT_TAKEOVER_PARAM => 'client_no_context_takeover',
71 _DEFLATE_MAX_WINDOW_BITS_PARAM => 'client_max_window_bits',
72 _INFLATE_MAX_WINDOW_BITS_PARAM => 'server_max_window_bits',
73  
74 _ENDPOINT_CLASS => 'Client',
75 2 };
76  
77 4 ▶sub _create_extension_header_parts {
Subroutine _create_extension_header_parts: called CC=2 SCAR=6.9
78 4 my ($self) = @_;
79  
80 4 my @parts = $self->SUPER::_create_extension_header_parts();
81  
82 #Let’s always advertise support for this feature.
83 4 ▶ if (!defined $self->{'deflate_max_window_bits'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"deflate_max_window_bits"}) 3 1 4
84 3 push @parts, _DEFLATE_MAX_WINDOW_BITS_PARAM() => undef;
85 }
86  
87 4 return @parts;
88 }
89  
90 6 ▶sub _consume_extension_options {
Subroutine _consume_extension_options: called CC=8 SCAR=20.8
91 6 my ($self, $opts_hr) = @_;
92  
93 6 ▶ if (exists $opts_hr->{'server_max_window_bits'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts_hr->{"server_max_window_bits"}) 2 4 6
94 2 $self->__validate_max_window_bits('server', $opts_hr->{'server_max_window_bits'});
95  
96 2 ▶ if ( $opts_hr->{'server_max_window_bits'} > $self->inflate_max_window_bits() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts_hr->{"server_max_window_bits"} > $self->inflate_max_window_bits) 1 1 2
97 1 die 'server_max_window_bits greater than client stipulated!';
98 }
99  
100 1 $self->{'inflate_max_window_bits'} = $opts_hr->{'server_max_window_bits'};
101 1 delete $opts_hr->{'server_max_window_bits'};
102 }
103  
104 5 ▶ if (exists $opts_hr->{'client_max_window_bits'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts_hr->{"client_max_window_bits"}) 1 4 5
105 1 $self->__validate_max_window_bits('client', $opts_hr->{'client_max_window_bits'});
106  
107 1 my $max = $self->deflate_max_window_bits();
108  
109 1 ▶ if ($opts_hr->{'client_max_window_bits'} < $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts_hr->{"client_max_window_bits"} < $max) 1 0 1
110 1 $self->{'deflate_max_window_bits'} = $opts_hr->{'client_max_window_bits'};
111 }
112  
113 #If the server requested a greater client_max_window_bits than
114 #we gave, that’s no problem, but we’re just going to ignore it.
115  
116 1 delete $opts_hr->{'client_max_window_bits'};
117 }
118  
119 5 ▶ if (exists $opts_hr->{'client_no_context_takeover'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts_hr->{"client_no_context_takeover"}) 1 4 5
120 1 $self->__validate_no_context_takeover( $opts_hr->{'client_no_context_takeover'} );
121  
122 1 $self->{'deflate_no_context_takeover'} = 1;
123  
124 1 delete $opts_hr->{'client_no_context_takeover'};
125 }
126  
127 5 ▶ if (exists $opts_hr->{'server_no_context_takeover'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts_hr->{'server_no_context_takeover'}) { } 1 4 5
elsif ($self->{'inflate_no_context_takeover'}) { } 1 3 4
128 1 $self->__validate_no_context_takeover( $opts_hr->{'server_no_context_takeover'} );
129 1 delete $opts_hr->{'server_no_context_takeover'};
130 }
131 elsif ($self->{'inflate_no_context_takeover'}) {
132  
133 #The RFC doesn’t seem to have a problem with a server that
134 #neglects a client’s server_no_context_takeover request.
135  
136 #die 'server didn’t accept server_no_context_takeover';
137  
138 1 delete $self->{'inflate_no_context_takeover'};
139 }
140  
141 5 return;
142 }
143  
144 2 1;
« WebSocket/PMCE/deflate/Server.pm ↑ Summary WebSocket/Handshake/Client.pm »