File Coverage

blib/lib/Protocol/SPDY/Frame/Control/RST_STREAM.pm
Criterion Covered Total %
statement 32 36 88.8
branch 4 6 66.6
condition 1 3 33.3
subroutine 11 12 91.6
pod 8 8 100.0
total 56 65 86.1


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