File Coverage

blib/lib/Protocol/SPDY/Frame/Control/SYN_REPLY.pm
Criterion Covered Total %
statement 35 37 94.5
branch 1 2 50.0
condition 1 2 50.0
subroutine 9 10 90.0
pod 6 6 100.0
total 52 57 91.2


line stmt bran cond sub pod time code
1             package Protocol::SPDY::Frame::Control::SYN_REPLY;
2             $Protocol::SPDY::Frame::Control::SYN_REPLY::VERSION = '1.001';
3 3     3   12 use strict;
  3         4  
  3         101  
4 3     3   11 use warnings;
  3         789  
  3         129  
5 3     3   13 use parent qw(Protocol::SPDY::Frame::HeaderSupport Protocol::SPDY::Frame::Control);
  3         5  
  3         13  
6              
7             =head1 NAME
8              
9             Protocol::SPDY::Frame::Control::SYN_REPLY - response to a SYN_STREAM
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   316 use Protocol::SPDY::Constants ':all';
  3         3  
  3         1654  
24              
25             =head2 type_name
26              
27             The string type for this frame ('SYN_REPLY').
28              
29             =cut
30              
31 33     33 1 127 sub type_name { 'SYN_REPLY' }
32              
33             =head2 new
34              
35             Instantiate.
36              
37             =cut
38              
39             sub new {
40 14     14 1 22 my $class = shift;
41 14         52 my %args = @_;
42 14 50 50     67 $args{headers} = $class->header_hashref_to_arrayref($args{headers}) if (ref($args{headers}) || '') eq 'HASH';
43 14         85 $class->SUPER::new(%args)
44             }
45              
46             =head2 from_data
47              
48             Instantiate from the given data.
49              
50             =cut
51              
52             sub from_data {
53 8     8 1 14 my $class = shift;
54 8         27 my %args = @_;
55 8         38 my ($stream_id) = unpack "N1", substr $args{data}, 0, 4, '';
56 8         13 $stream_id &= ~0x80000000;
57 8         26 my $zlib = delete $args{zlib};
58 8         32 my $out = $zlib->decompress($args{data});
59 8         52 my ($headers) = $class->extract_headers($out);
60 8         36 $class->new(
61             %args,
62             stream_id => $stream_id,
63             headers => $headers,
64             );
65             }
66              
67             =head2 stream_id
68              
69             The stream ID we're responding to.
70              
71             =cut
72              
73 15     15 1 2913 sub stream_id { shift->{stream_id} }
74              
75             =head2 as_packet
76              
77             Returns the packet as a byte string.
78              
79             =cut
80              
81             sub as_packet {
82 7     7 1 14 my $self = shift;
83 7         10 my $zlib = shift;
84 7         23 my $payload = pack 'N1', $self->stream_id & 0x7FFFFFFF;
85 7         12 my $block = $self->pairs_to_nv_header(map {; $_->[0], join "\0", @{$_}[1..$#$_] } @{$self->headers});
  2         5  
  2         16  
  7         40  
86 7         28 $payload .= $zlib->compress($block);
87 7         45 return $self->SUPER::as_packet(
88             payload => $payload,
89             );
90             }
91              
92             =head2 to_string
93              
94             String representation, for debugging.
95              
96             =cut
97              
98             sub to_string {
99 0     0 1   my $self = shift;
100 0           $self->SUPER::to_string . ', ' . $self->header_line;
101             }
102              
103             1;
104              
105             __END__