| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Protocol::SPDY::Frame::Control; | 
| 2 |  |  |  |  |  |  | { | 
| 3 |  |  |  |  |  |  | $Protocol::SPDY::Frame::Control::VERSION = '1.000'; | 
| 4 |  |  |  |  |  |  | } | 
| 5 | 3 |  |  | 3 |  | 17 | use strict; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 104 |  | 
| 6 | 3 |  |  | 3 |  | 16 | use warnings; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 95 |  | 
| 7 | 3 |  |  | 3 |  | 16 | use parent qw(Protocol::SPDY::Frame); | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 36 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 NAME | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | Protocol::SPDY::Frame::Control - control frame subclass for the SPDY protocol | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | =head1 VERSION | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | version 1.000 | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | Support for control frames. Typically you'd interact with these through the top-level | 
| 20 |  |  |  |  |  |  | L object. | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | Subclass of L. See also L. | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =head2 TYPES | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | The following control frame types are known: | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | =over 4 | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =item * L | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =item * L | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =item * L | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =item * L | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =item * L | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =item * L | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =item * L | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =item * L | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =back | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =cut | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 3 |  |  | 3 |  | 219 | use Protocol::SPDY::Constants ':all'; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 2233 |  | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =head1 METHODS | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | =cut | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =head2 is_control | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | This is a control frame, so it will return true. | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | =cut | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 27 |  |  | 27 | 1 | 163 | sub is_control { 1 } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | =head2 is_data | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | This is not a data frame, so it returns false. | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =cut | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 16 |  |  | 16 | 1 | 69 | sub is_data { 0 } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =head2 version | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | The version for this frame - probably 3. | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =cut | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | sub version { | 
| 79 | 33 | 50 |  | 33 | 1 | 131 | die "no version for $_[0]" unless $_[0]->{version}; | 
| 80 | 33 |  |  |  |  | 172 | shift->{version} | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =head2 type | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | The numerical type for this frame. | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =cut | 
| 88 |  |  |  |  |  |  |  | 
| 89 | 31 |  |  | 31 | 1 | 133 | sub type { FRAME_TYPE_BY_NAME->{ shift->type_name } } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =head2 uni | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | Unidirectional flag (if set, we expect no response from the other side). | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =cut | 
| 96 |  |  |  |  |  |  |  | 
| 97 | 25 |  |  | 25 | 1 | 156 | sub uni { shift->{uni} } | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =head2 compress | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | The compression flag. Used on some frames. | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =cut | 
| 104 |  |  |  |  |  |  |  | 
| 105 | 21 |  |  | 21 | 1 | 120 | sub compress { shift->{compress} } | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =head2 as_packet | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | Returns the byte representation for this frame. | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | =cut | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | sub as_packet { | 
| 114 | 21 |  |  | 21 | 1 | 66 | my $self = shift; | 
| 115 | 21 |  |  |  |  | 58 | my %args = @_; | 
| 116 | 21 |  |  |  |  | 45 | my $len = length($args{payload}); | 
| 117 | 21 | 50 |  |  |  | 104 | my $pkt = pack 'n1n1C1n1C1', | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | ($self->is_control ? 0x8000 : 0x0000) | ($self->version & 0x7FFF), | 
| 119 |  |  |  |  |  |  | $self->type, | 
| 120 |  |  |  |  |  |  | ($self->fin ? FLAG_FIN : 0) | ($self->uni ? FLAG_UNI : 0) | ($self->compress ? FLAG_COMPRESS : 0), | 
| 121 |  |  |  |  |  |  | $len >> 8, | 
| 122 |  |  |  |  |  |  | $len & 0xFF; | 
| 123 | 21 |  |  |  |  | 59 | $pkt .= $args{payload}; | 
| 124 | 21 |  |  |  |  | 174 | return $pkt; | 
| 125 |  |  |  |  |  |  | } | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =head2 pairs_to_nv_header | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | Returns a name-value pair header block. | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | =cut | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | sub pairs_to_nv_header { | 
| 134 | 18 |  |  | 18 | 1 | 23 | shift; | 
| 135 | 18 |  |  |  |  | 40 | my @hdr = @_; | 
| 136 | 18 |  |  |  |  | 61 | my $data = pack 'N1', @hdr / 2; | 
| 137 | 18 |  |  |  |  | 73 | $data .= pack '(N/A*)*', @hdr; | 
| 138 | 18 |  |  |  |  | 66 | return $data; | 
| 139 |  |  |  |  |  |  | } | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =head2 find_class_for_type | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | Returns the class appropriate for the given type (can be numerical | 
| 144 |  |  |  |  |  |  | or string representation). | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | =cut | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | sub find_class_for_type { | 
| 149 | 34 |  |  | 34 | 1 | 44 | shift; | 
| 150 | 34 |  |  |  |  | 39 | my $type = shift; | 
| 151 | 34 | 100 |  |  |  | 162 | my $name = exists FRAME_TYPE_BY_NAME->{$type} ? $type : FRAME_TYPE_BY_ID->{$type} or die "No class for $type"; | 
|  |  | 50 |  |  |  |  |  | 
| 152 | 34 |  |  |  |  | 127 | return 'Protocol::SPDY::Frame::Control::' . $name; | 
| 153 |  |  |  |  |  |  | } | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | =head2 from_data | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | Instantiates a frame from the given bytes. | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | =cut | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | sub from_data { | 
| 162 | 24 |  |  | 24 | 1 | 38 | my $class = shift; | 
| 163 | 24 |  |  |  |  | 167 | my %args = @_; | 
| 164 | 24 |  |  |  |  | 41 | my $type = $args{type}; | 
| 165 | 24 |  |  |  |  | 73 | my $target_class = $class->find_class_for_type($type); | 
| 166 | 24 |  |  |  |  | 170 | return $target_class->from_data(%args); | 
| 167 |  |  |  |  |  |  | } | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | =head2 to_string | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | String representation for debugging. | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | =cut | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | sub to_string { | 
| 176 | 2 |  |  | 2 | 1 | 4 | my $self = shift; | 
| 177 | 2 |  |  |  |  | 15 | $self->SUPER::to_string . ', control'; | 
| 178 |  |  |  |  |  |  | } | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | 1; | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | __END__ |