File Coverage

blib/lib/Protocol/SPDY/Frame/Control/GOAWAY.pm
Criterion Covered Total %
statement 12 32 37.5
branch 0 4 0.0
condition 0 3 0.0
subroutine 4 11 36.3
pod 7 7 100.0
total 23 57 40.3


line stmt bran cond sub pod time code
1             package Protocol::SPDY::Frame::Control::GOAWAY;
2             $Protocol::SPDY::Frame::Control::GOAWAY::VERSION = '1.001';
3 3     3   11 use strict;
  3         3  
  3         82  
4 3     3   10 use warnings;
  3         3  
  3         59  
5 3     3   10 use parent qw(Protocol::SPDY::Frame::Control);
  3         2  
  3         22  
6              
7             =head1 NAME
8              
9             Protocol::SPDY::Frame::Control::GOAWAY - connection termination request
10              
11             =head1 VERSION
12              
13             version 1.001
14              
15             =head1 SYNOPSIS
16              
17             use Protocol::SPDY;
18              
19             =head1 DESCRIPTION
20              
21             See L and L.
22              
23             =cut
24              
25 3     3   143 use Protocol::SPDY::Constants ':all';
  3         3  
  3         1049  
26              
27             =head2 type_name
28              
29             The string type for this frame ('GOAWAY').
30              
31             =cut
32              
33 0     0 1   sub type_name { 'GOAWAY' }
34              
35             =head2 status_code
36              
37             Numerical status code to use for the response.
38              
39             =cut
40              
41             sub status_code {
42 0     0 1   my $self = shift;
43 0 0         return $self->{status_code} unless @_;
44 0           $self->{status_code} = shift;
45 0           return $self;
46             }
47              
48             =head2 from_data
49              
50             Instantiates from the given data.
51              
52             =cut
53              
54             sub from_data {
55 0     0 1   my $class = shift;
56 0           my %args = @_;
57 0           my ($stream_id, $status_code) = unpack "N1N1", substr $args{data}, 0, 8, '';
58 0           $stream_id &= ~0x80000000;
59 0           $class->new(
60             %args,
61             last_stream_id => $stream_id,
62             status_code => $status_code,
63             );
64             }
65              
66             =head2 last_stream_id
67              
68             The last stream ID we accepted, or 0 if no streams were accepted.
69              
70             =cut
71              
72 0     0 1   sub last_stream_id { shift->{last_stream_id} }
73              
74             =head2 status_code_as_text
75              
76             Text representation of the status code. You can pass a numerical code to look
77             up the text reason for that code rather than using the current value.
78              
79             =cut
80              
81             sub status_code_as_text {
82 0     0 1   my $self = shift;
83 0   0       my $code = shift // $self->status_code;
84 0 0         die "Invalid status code $code" unless exists RST_STATUS_CODE_BY_ID->{$code};
85 0           return RST_STATUS_CODE_BY_ID->{$code};
86             }
87              
88             =head2 as_packet
89              
90             Returns the packet as a byte string.
91              
92             =cut
93              
94             sub as_packet {
95 0     0 1   my $self = shift;
96 0           my $payload = pack 'N1N1', $self->last_stream_id & 0x7FFFFFFF, $self->status_code;
97 0           return $self->SUPER::as_packet(
98             payload => $payload,
99             );
100             }
101              
102             =head2 to_string
103              
104             String representation, for debugging.
105              
106             =cut
107              
108             sub to_string {
109 0     0 1   my $self = shift;
110 0           $self->SUPER::to_string . ', stream ' . $self->last_stream_id . ', reason ' . $self->status_code_as_text;
111             }
112              
113             1;
114              
115             __END__