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