File Coverage

blib/lib/Protocol/SPDY/Frame/HeaderSupport.pm
Criterion Covered Total %
statement 26 43 60.4
branch 1 2 50.0
condition n/a
subroutine 7 10 70.0
pod 7 7 100.0
total 41 62 66.1


line stmt bran cond sub pod time code
1             package Protocol::SPDY::Frame::HeaderSupport;
2             {
3             $Protocol::SPDY::Frame::HeaderSupport::VERSION = '0.999_007';
4             }
5 3     3   1054 use strict;
  3         3  
  3         63  
6 3     3   9 use warnings;
  3         2  
  3         65  
7              
8             =head1 NAME
9              
10             Protocol::SPDY::Frame::HeaderSupport - helper methods for frames which contain header data
11              
12             =head1 VERSION
13              
14             version 0.999_007
15              
16             =head1 SYNOPSIS
17              
18             =head1 DESCRIPTION
19              
20             The SYN_STREAM, SYN_REPLY and HEADERS frame types all use the same method for specifying
21             HTTP-style headers. This class provides common methods for interacting with that header
22             data.
23              
24             Mainly for internal use - see L and L
25             instead.
26              
27             =cut
28              
29 3     3   8 use Protocol::SPDY::Constants ':all';
  3         2  
  3         1340  
30              
31             =head2 header
32              
33             Returns undef if the given header is not found, otherwise returns
34             a scalar holding the \0-separated values found for this header.
35              
36             =cut
37              
38             sub header {
39 26     26 1 7341 my $self = shift;
40 26         31 my $k = shift;
41 26         32 my ($hdr) = grep $_->[0] eq $k, @{$self->{headers}};
  26         139  
42 26 50       61 return undef unless $hdr;
43 26         186 return join "\0", @$hdr[1..$#$hdr];
44             }
45              
46             =head2 headers
47              
48             Returns the arrayref structure of headers.
49              
50             [ [ header1 => value1, value2 ], [ header2 => value... ] ]
51              
52             =cut
53              
54 18     18 1 74 sub headers { shift->{headers} }
55              
56             =head2 header_list
57              
58             Returns the list of header names (in the order in which we received them).
59              
60             =cut
61              
62             sub header_list {
63 4     4 1 7 my $self = shift;
64 4         5 map $_->[0], @{$self->{headers}};
  4         81  
65             }
66              
67             =head2 header_line
68              
69             Returns a string describing the current header values, for debugging.
70              
71             =cut
72              
73             sub header_line {
74 0     0 1 0 my $self = shift;
75 0         0 join ',', map { $_->[0] . '=' . join ',', @{$_}[ 1 .. $#{$_} ] } @{$self->{headers}};
  0         0  
  0         0  
  0         0  
  0         0  
76             }
77              
78             =head2 headers_as_hashref
79              
80             Returns a hashref representation of the headers. Values
81             are all arrayrefs.
82              
83             =cut
84              
85             sub headers_as_hashref {
86 0     0 1 0 my $self = shift;
87             # this all seems needlessly overcomplicated
88             my %h = map {
89 0         0 $_->[0] => [ @{$_}[ 1 .. $#{$_} ] ]
  0         0  
  0         0  
90 0         0 } @{$self->{headers}};
  0         0  
91 0         0 \%h
92             }
93              
94             =head2 headers_as_simple_hashref
95              
96             Returns a hashref representation of the headers where values
97             are comma-separated strings.
98              
99             =cut
100              
101             sub headers_as_simple_hashref {
102 8     8 1 13 my $self = shift;
103             # this all seems needlessly overcomplicated
104             my %h = map {
105 2         5 $_->[0] => join ',', @{$_}[ 1 .. $#{$_} ]
  2         13  
  2         5  
106 8         9 } @{$self->{headers}};
  8         26  
107 8         22 \%h
108             }
109              
110             =head2 header_hashref_to_arrayref
111              
112             Converts a hashref of key=>value information into an arrayref structure.
113              
114             =cut
115              
116             sub header_hashref_to_arrayref {
117 0     0 1   my $self = shift;
118 0           my $hdr = shift;
119             return [
120 0           map {; [ $_ => split /\0/, $hdr->{$_} ] } sort keys %$hdr
  0            
121             ]
122             }
123              
124             1;
125              
126             __END__