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