| 1 | package HTTP::Headers::ETag; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | 1 | our $VERSION = '7.04'; | |||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 1 | require HTTP::Date; | |||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 1 | require HTTP::Headers; | |||||||||||||||||||||
| 11 | package | ||||||||||||||||||||||
| 12 | HTTP::Headers; | ||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | sub _etags | ||||||||||||||||||||||
| 15 | 14 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_etags: called CC=3 SCAR=11.0
| |||||||||||||||||||||||
| 16 | 14 | my $self = shift; | |||||||||||||||||||||
| 17 | 14 | my $header = shift; | |||||||||||||||||||||
| 18 | 14 | my @old = _split_etag_list($self->_header($header)); | |||||||||||||||||||||
| 19 | 14 | ▶ | if (@_) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 20 | 8 | $self->_header($header => join(", ", _split_etag_list(@_))); | |||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||
| 22 | 14 | ▶ | wantarray ? @old : join(", ", @old); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||
| 24 | |||||||||||||||||||||||
| 25 | 11 | ▶ | sub etag { shift->_etags("ETag", @_); } | ||||||||||||||||||||
|
Subroutine
etag: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 26 | 1 | ▶ | sub if_match { shift->_etags("If-Match", @_); } | ||||||||||||||||||||
|
Subroutine
if_match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 27 | 1 | ▶ | sub if_none_match { shift->_etags("If-None-Match", @_); } | ||||||||||||||||||||
|
Subroutine
if_none_match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | 7 | ▶ | sub if_range { | ||||||||||||||||||||
|
Subroutine
if_range: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||
| 30 | # Either a date or an entity-tag | ||||||||||||||||||||||
| 31 | 7 | my $self = shift; | |||||||||||||||||||||
| 32 | 7 | my @old = $self->_header("If-Range"); | |||||||||||||||||||||
| 33 | 7 | ▶ | if (@_) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 34 | 3 | my $new = shift; | |||||||||||||||||||||
| 35 | 3 | ▶ | if (!defined $new) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 36 | 1 | $self->remove_header("If-Range"); | |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||
| 38 | elsif ($new =~ /^\d+$/) { | ||||||||||||||||||||||
| 39 | 1 | $self->_date_header("If-Range", $new); | |||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||
| 41 | else { | ||||||||||||||||||||||
| 42 | 1 | $self->_etags("If-Range", $new); | |||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||
| 45 | 7 | ▶ | return unless defined(wantarray); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 46 | 4 | for (@old) { | |||||||||||||||||||||
| 47 | 3 | my $t = HTTP::Date::str2time($_); | |||||||||||||||||||||
| 48 | 3 | ▶ | $_ = $t if $t; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||
| 50 | 4 | ▶ | wantarray ? @old : join(", ", @old); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | # Split a list of entity tag values. The return value is a list | ||||||||||||||||||||||
| 55 | # consisting of one element per entity tag. Suitable for parsing | ||||||||||||||||||||||
| 56 | # headers like C<If-Match>, C<If-None-Match>. You might even want to | ||||||||||||||||||||||
| 57 | # use it on C<ETag> and C<If-Range> entity tag values, because it will | ||||||||||||||||||||||
| 58 | # normalize them to the common form. | ||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||
| 60 | # entity-tag = [ weak ] opaque-tag | ||||||||||||||||||||||
| 61 | # weak = "W/" | ||||||||||||||||||||||
| 62 | # opaque-tag = quoted-string | ||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | |||||||||||||||||||||||
| 65 | sub _split_etag_list | ||||||||||||||||||||||
| 66 | 22 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_split_etag_list: called CC=11 SCAR=24.0
| |||||||||||||||||||||||
| 67 | 22 | my(@val) = @_; | |||||||||||||||||||||
| 68 | 22 | my @res; | |||||||||||||||||||||
| 69 | 22 | for (@val) { | |||||||||||||||||||||
| 70 | 19 | ▶ | while (length) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 71 | 29 | my $weak = ""; | |||||||||||||||||||||
| 72 | 29 | ▶ | $weak = "W/" if s,^\s*[wW]/,,; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 73 | 29 | my $etag = ""; | |||||||||||||||||||||
| 74 | 29 | ▶ | if (s/^\s*(\"[^\"\\]*(?:\\.[^\"\\]*)*\")//) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 75 | 13 | push(@res, "$weak$1"); | |||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||
| 77 | elsif (s/^\s*,//) { | ||||||||||||||||||||||
| 78 | 6 | ▶ | push(@res, qq(W/"")) if $weak; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | elsif (s/^\s*([^,\s]+)//) { | ||||||||||||||||||||||
| 81 | 8 | $etag = $1; | |||||||||||||||||||||
| 82 | 8 | $etag =~ s/([\"\\])/\\$1/g; | |||||||||||||||||||||
| 83 | 8 | push(@res, qq($weak"$etag")); | |||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||
| 85 | ▶ | elsif (s/^\s+// || !length) { | |||||||||||||||||||||
|
Condition66%2/3
s/^\s+// or not length $_
MC/DC0%0/2
s/^\s+// or not length $_
s/^\s+//
not length $_
Truth table66%2/3
A or not(B)
A= s/^\s+//B= not length $_
| |||||||||||||||||||||||
| 86 | 2 | ▶ | push(@res, qq(W/"")) if $weak; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||
| 89 | 0 | die "This should not happen: '$_'"; | |||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||
| 93 | 22 | @res; | |||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | 1 | 1; | |||||||||||||||||||||
| 97 | |||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||