| 1 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 2 | # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de> | ||||||||||||||||||||||||||||||||||
| 3 | # File: GX/HTTP/Headers.pm | ||||||||||||||||||||||||||||||||||
| 4 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | package GX::HTTP::Headers; | ||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 41 | ▶ | use GX::Exception; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 41 | ▶ | use GX::HTTP::Constants qw( CRLF CRLFSP REGEX_CRLF ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 41 | ▶ | use Storable (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 15 | # Header fields (see RFC 2616) | ||||||||||||||||||||||||||||||||||
| 16 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | 41 | ▶ | use constant GENERAL_HEADERS => qw( | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | Cache-Control | ||||||||||||||||||||||||||||||||||
| 20 | Connection | ||||||||||||||||||||||||||||||||||
| 21 | Date | ||||||||||||||||||||||||||||||||||
| 22 | Pragma | ||||||||||||||||||||||||||||||||||
| 23 | Trailer | ||||||||||||||||||||||||||||||||||
| 24 | Transfer-Encoding | ||||||||||||||||||||||||||||||||||
| 25 | Upgrade | ||||||||||||||||||||||||||||||||||
| 26 | Via | ||||||||||||||||||||||||||||||||||
| 27 | Warning | ||||||||||||||||||||||||||||||||||
| 28 | 41 | ); | |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | 41 | ▶ | use constant REQUEST_HEADERS => qw( | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 31 | Accept | ||||||||||||||||||||||||||||||||||
| 32 | Accept-Charset | ||||||||||||||||||||||||||||||||||
| 33 | Accept-Encoding | ||||||||||||||||||||||||||||||||||
| 34 | Accept-Language | ||||||||||||||||||||||||||||||||||
| 35 | Authorization | ||||||||||||||||||||||||||||||||||
| 36 | Expect | ||||||||||||||||||||||||||||||||||
| 37 | From | ||||||||||||||||||||||||||||||||||
| 38 | Host | ||||||||||||||||||||||||||||||||||
| 39 | If-Match | ||||||||||||||||||||||||||||||||||
| 40 | If-Modified-Since | ||||||||||||||||||||||||||||||||||
| 41 | If-None-Match | ||||||||||||||||||||||||||||||||||
| 42 | If-Range | ||||||||||||||||||||||||||||||||||
| 43 | If-Unmodified-Since | ||||||||||||||||||||||||||||||||||
| 44 | Max-Forwards | ||||||||||||||||||||||||||||||||||
| 45 | Proxy-Authorization | ||||||||||||||||||||||||||||||||||
| 46 | Range | ||||||||||||||||||||||||||||||||||
| 47 | Referer | ||||||||||||||||||||||||||||||||||
| 48 | TE | ||||||||||||||||||||||||||||||||||
| 49 | User-Agent | ||||||||||||||||||||||||||||||||||
| 50 | 41 | ); | |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | 41 | ▶ | use constant RESPONSE_HEADERS => qw( | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 53 | Accept-Ranges | ||||||||||||||||||||||||||||||||||
| 54 | Age | ||||||||||||||||||||||||||||||||||
| 55 | ETag | ||||||||||||||||||||||||||||||||||
| 56 | Location | ||||||||||||||||||||||||||||||||||
| 57 | Proxy-Authenticate | ||||||||||||||||||||||||||||||||||
| 58 | Retry-After | ||||||||||||||||||||||||||||||||||
| 59 | Server | ||||||||||||||||||||||||||||||||||
| 60 | Vary | ||||||||||||||||||||||||||||||||||
| 61 | WWW-Authenticate | ||||||||||||||||||||||||||||||||||
| 62 | 41 | ); | |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 41 | ▶ | use constant ENTITY_HEADERS => qw( | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 65 | Allow | ||||||||||||||||||||||||||||||||||
| 66 | Content-Encoding | ||||||||||||||||||||||||||||||||||
| 67 | Content-Language | ||||||||||||||||||||||||||||||||||
| 68 | Content-Length | ||||||||||||||||||||||||||||||||||
| 69 | Content-Location | ||||||||||||||||||||||||||||||||||
| 70 | Content-MD5 | ||||||||||||||||||||||||||||||||||
| 71 | Content-Range | ||||||||||||||||||||||||||||||||||
| 72 | Content-Type | ||||||||||||||||||||||||||||||||||
| 73 | Expires | ||||||||||||||||||||||||||||||||||
| 74 | Last-Modified | ||||||||||||||||||||||||||||||||||
| 75 | 41 | ); | |||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 41 | my %FIELD_NAMES; | |||||||||||||||||||||||||||||||||
| 78 | my %FIELD_PRIORITIES; | ||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | 41 | my $priority = 0; | |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 41 | for my $field ( | |||||||||||||||||||||||||||||||||
| 85 | GENERAL_HEADERS(), | ||||||||||||||||||||||||||||||||||
| 86 | sort( | ||||||||||||||||||||||||||||||||||
| 87 | REQUEST_HEADERS(), | ||||||||||||||||||||||||||||||||||
| 88 | 'Cookie' | ||||||||||||||||||||||||||||||||||
| 89 | ), | ||||||||||||||||||||||||||||||||||
| 90 | sort( | ||||||||||||||||||||||||||||||||||
| 91 | RESPONSE_HEADERS(), | ||||||||||||||||||||||||||||||||||
| 92 | 'Set-Cookie', | ||||||||||||||||||||||||||||||||||
| 93 | 'Set-Cookie2' | ||||||||||||||||||||||||||||||||||
| 94 | ), | ||||||||||||||||||||||||||||||||||
| 95 | sort( | ||||||||||||||||||||||||||||||||||
| 96 | ENTITY_HEADERS(), | ||||||||||||||||||||||||||||||||||
| 97 | 'Content-Disposition' | ||||||||||||||||||||||||||||||||||
| 98 | ) | ||||||||||||||||||||||||||||||||||
| 99 | ) { | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 2091 | my $key = uc $field; | |||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | 2091 | $FIELD_NAMES{$key} = $field; | |||||||||||||||||||||||||||||||||
| 104 | 2091 | $FIELD_PRIORITIES{$key} = ++$priority; | |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 112 | # Class setup | ||||||||||||||||||||||||||||||||||
| 113 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | 41 | ▶ | use GX::Class::Object; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||
| 117 | 41 | has 'headers' => ( | |||||||||||||||||||||||||||||||||
| 118 | isa => 'Hash::Ordered', | ||||||||||||||||||||||||||||||||||
| 119 | accessors => { | ||||||||||||||||||||||||||||||||||
| 120 | '_headers' => { type => 'get_reference' } | ||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | 41 | build; | |||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||
| 127 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 128 | # Public methods | ||||||||||||||||||||||||||||||||||
| 129 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | 2352 | ▶ | sub add { | ||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | 2352 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 134 | 2352 | my $field = shift; | |||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | 2352 | ▶ | if ( ! defined $field || ! length $field ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $field and length $field
MC/DC0%0/2
defined $field and length $field
defined $field
length $field
Truth table33%1/3
A and B
A= defined $fieldB= length $field
| |||||||||||||||||||||||||||||||||||
| 137 | 0 | complain "Invalid header name"; | |||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | 2352 | push @{$self->_headers->{ uc $field }}, @_; | |||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | 2352 | return; | |||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub as_hash { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_hash: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | # UNDOCUMENTED | ||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||
| 150 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | 0 | my %headers; | |||||||||||||||||||||||||||||||||
| 153 | 0 | my $headers = $self->_headers; | |||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | 0 | for my $field ( keys %$headers ) { | |||||||||||||||||||||||||||||||||
| 156 | 0 | $headers{$field} = Storable::dclone( $headers->{$field} ); | |||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | return wantarray ? %headers : \%headers; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||
| 163 | 21 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||
| 165 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | 21 | my $string = ''; | |||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | 21 | my $headers = $self->_headers; | |||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||
| 171 | 21 | for my $key ( $self->_sorted_field_keys ) { | |||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | 29 | ▶ | my $field = $FIELD_NAMES{$key} || $key; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$FIELD_NAMES{$key} || $key
MC/DC0%0/2
$FIELD_NAMES{$key} || $key
$FIELD_NAMES{$key}
$key
Truth table66%2/3
A || B
A= $FIELD_NAMES{$key}B= $key
| |||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | 29 | for my $value ( grep { defined } @{$headers->{$key}} ) { | |||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||
| 177 | # Handle newlines in the field value | ||||||||||||||||||||||||||||||||||
| 178 | 29 | ▶ | if ( $value =~ /\n/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 179 | # A leading SP indicates folding [RFC 2616] | ||||||||||||||||||||||||||||||||||
| 180 | 2 | $string .= "$field: " . join( CRLFSP, grep { length } split( /\n/, $value ) ); | |||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||
| 182 | else { | ||||||||||||||||||||||||||||||||||
| 183 | 27 | $string .= "$field: $value"; | |||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||
| 186 | 29 | $string .= CRLF; | |||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||
| 192 | 21 | return $string; | |||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||
| 196 | 3 | ▶ | sub count { | ||||||||||||||||||||||||||||||||
|
Subroutine
count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | 3 | return scalar keys %{$_[0]->_headers}; | |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||
| 202 | 6 | ▶ | sub field_names { | ||||||||||||||||||||||||||||||||
|
Subroutine
field_names: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||
| 204 | 6 | ▶ | return map { $FIELD_NAMES{$_} || $_ } keys %{$_[0]->_headers}; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$FIELD_NAMES{$_} || $_
MC/DC0%0/2
$FIELD_NAMES{$_} || $_
$FIELD_NAMES{$_}
$_
Truth table66%2/3
A || B
A= $FIELD_NAMES{$_}B= $_
| |||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||
| 208 | 21 | ▶ | sub get { | ||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 211 | 21 | my $field = shift; | |||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | 21 | ▶ | defined $field or return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||
| 215 | 21 | ▶ | my $values = $self->_headers->{ uc $field } or return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||
| 217 | 18 | ▶ | return wantarray ? @$values : $values->[0]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||
| 221 | 1339 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=9 SCAR=22.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||
| 223 | 1339 | my $invocant = shift; | |||||||||||||||||||||||||||||||||
| 224 | 1339 | my $string = shift; | |||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||
| 226 | 1339 | ▶ | my $self = ref $invocant ? $invocant : $invocant->new; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||
| 228 | 1339 | ▶ | return $self if ! defined $string; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||
| 230 | 1339 | my @lines; | |||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||
| 232 | 1339 | for my $line ( split( REGEX_CRLF, $string ) ) { | |||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||
| 234 | # An empty line (i.e., a line with nothing preceding the CRLF) | ||||||||||||||||||||||||||||||||||
| 235 | # indicates the end of the header fields. [RFC 2616] | ||||||||||||||||||||||||||||||||||
| 236 | 2344 | ▶ | last unless length $line; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||
| 238 | # Header fields can be extended over multiple lines by preceding each | ||||||||||||||||||||||||||||||||||
| 239 | # extra line with at least one SP or HT. A recipient MAY replace any | ||||||||||||||||||||||||||||||||||
| 240 | # linear white space with a single SP before interpreting the field | ||||||||||||||||||||||||||||||||||
| 241 | # value or forwarding the message downstream. [RFC 2616] | ||||||||||||||||||||||||||||||||||
| 242 | 2344 | ▶ | if ( $line =~ s/^[ \t]// ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 243 | 5 | ▶ | next unless @lines; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 244 | 5 | $lines[-1] .= "\n$line"; | |||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||
| 246 | else { | ||||||||||||||||||||||||||||||||||
| 247 | 2339 | push @lines, $line; | |||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||
| 252 | 1339 | for my $line ( @lines ) { | |||||||||||||||||||||||||||||||||
| 253 | 2339 | my ( $field, $value ) = split( /:\s*/, $line, 2 ); | |||||||||||||||||||||||||||||||||
| 254 | 2339 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 255 | 2339 | $value =~ s/\s+$//; | |||||||||||||||||||||||||||||||||
| 256 | 2339 | $self->add( $field, $value ); | |||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||
| 259 | 1339 | return $self; | |||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||
| 263 | 4 | ▶ | sub remove { | ||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||
| 265 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 266 | 4 | my $field = shift; | |||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||
| 268 | 4 | ▶ | defined $field or return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||
| 270 | 4 | ▶ | return delete $self->_headers->{ uc $field } ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||
| 274 | 31 | ▶ | sub set { | ||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||
| 276 | 31 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 277 | 31 | my $field = shift; | |||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||
| 279 | 31 | ▶ | if ( ! defined $field || ! length $field ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $field and length $field
MC/DC0%0/2
defined $field and length $field
defined $field
length $field
Truth table33%1/3
A and B
A= defined $fieldB= length $field
| |||||||||||||||||||||||||||||||||||
| 280 | 0 | complain "Invalid header name"; | |||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||
| 283 | 31 | $self->_headers->{ uc $field } = [ @_ ]; | |||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||
| 285 | 31 | return; | |||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | sub sorted_field_names { | ||||||||||||||||||||||||||||||||
|
Subroutine
sorted_field_names: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | return map { $FIELD_NAMES{$_} || $_ } $_[0]->_sorted_field_keys; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$FIELD_NAMES{$_} || $_
MC/DC0%0/2
$FIELD_NAMES{$_} || $_
$FIELD_NAMES{$_}
$_
Truth table0%0/3
A || B
A= $FIELD_NAMES{$_}B= $_
| |||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||
| 296 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 297 | # Private methods | ||||||||||||||||||||||||||||||||||
| 298 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||
| 300 | 69 | ▶ | sub _install_field_accessors { | ||||||||||||||||||||||||||||||||
|
Subroutine
_install_field_accessors: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||
| 302 | 69 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||
| 304 | 69 | for my $field ( @_ ) { | |||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||
| 306 | 448 | ( my $accessor = lc $field ) =~ tr/-/_/; | |||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||
| 308 | 448 | my $key = uc $field; | |||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||
| 310 | 1480 | ▶ | my $code = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||
| 312 | 1480 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||
| 314 | 1480 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 315 | 36 | $self->_headers->{$key} = [ @_ ]; | |||||||||||||||||||||||||||||||||
| 316 | 36 | return; | |||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||
| 319 | 1444 | ▶ | my $values = $self->_headers->{$key} or return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||
| 321 | 1079 | ▶ | return wantarray ? @$values : $values->[0]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||
| 323 | 448 | }; | |||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||
| 325 | 448 | $class->meta->add_method( $accessor, $code ); | |||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||
| 329 | 69 | return; | |||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||
| 333 | 21 | ▶ | sub _sorted_field_keys { | ||||||||||||||||||||||||||||||||
|
Subroutine
_sorted_field_keys: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||
| 335 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||
| 337 | my @keys = sort { | ||||||||||||||||||||||||||||||||||
| 338 | 39 | ▶ | ( $FIELD_PRIORITIES{$a} || 999 ) <=> ( $FIELD_PRIORITIES{$b} || 999 ) || $a cmp $b | ||||||||||||||||||||||||||||||||
|
Condition85%6/7
($FIELD_PRIORITIES{$a} || 999) <=> ($FIELD_PRIORITIES{$b} || 999) || $a cmp $b
$FIELD_PRIORITIES{$a} || 999
$FIELD_PRIORITIES{$b} || 999
MC/DC0%0/2
($FIELD_PRIORITIES{$a} || 999) <=> ($FIELD_PRIORITIES{$b} || 999) || $a cmp $b
$FIELD_PRIORITIES{$a}
$a cmp $b
MC/DC100%1/1
$FIELD_PRIORITIES{$b} || 999
$FIELD_PRIORITIES{$b}
Truth table66%2/3
A || B
A= $FIELD_PRIORITIES{$a}B= $a cmp $b
Truth table100%2/2
A
A= $FIELD_PRIORITIES{$b}
| |||||||||||||||||||||||||||||||||||
| 339 | 21 | } keys %{$self->_headers}; | |||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||
| 341 | 21 | return @keys; | |||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||
| 346 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 347 | # Field accessors | ||||||||||||||||||||||||||||||||||
| 348 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||
| 350 | 41 | __PACKAGE__->_install_field_accessors( qw( | |||||||||||||||||||||||||||||||||
| 351 | Content-Disposition | ||||||||||||||||||||||||||||||||||
| 352 | Content-Encoding | ||||||||||||||||||||||||||||||||||
| 353 | Content-Language | ||||||||||||||||||||||||||||||||||
| 354 | Content-Length | ||||||||||||||||||||||||||||||||||
| 355 | Content-Type | ||||||||||||||||||||||||||||||||||
| 356 | Date | ||||||||||||||||||||||||||||||||||
| 357 | Expires | ||||||||||||||||||||||||||||||||||
| 358 | Last-Modified | ||||||||||||||||||||||||||||||||||
| 359 | ) ); | ||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||
| 362 | 41 | 1; | |||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||
| 364 | __END__ | ||||||||||||||||||||||||||||||||||