Headers/ETag.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 96.8% 31 / 32 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 4 totaltotal 90.7% 88 / 97 CC 20 SCAR 20.0
CC
20
Cov
96%
_split_etag_list
11.1
if_range
8.0
_etags
3.0
CRAP 7.4
« Headers/Auth.pm ↑ Summary Request.pm »
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
BranchTrueFalseTotal
if (@_) 8 6 14
20 8 $self->_header($header => join(", ", _split_etag_list(@_)));
21 }
22 14 ▶ wantarray ? @old : join(", ", @old);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 13 14
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
BranchTrueFalseTotal
if (@_) 3 4 7
34 3 my $new = shift;
35 3 ▶ if (!defined $new) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $new) { } 1 2 3
elsif ($new =~ /^\d+$/) { } 1 1 2
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
BranchTrueFalseTotal
unless defined wantarray 3 4 7
46 4 for (@old) {
47 3 my $t = HTTP::Date::str2time($_);
48 3 ▶ $_ = $t if $t;
Branch: 1 branch
BranchTrueFalseTotal
if $t 2 1 3
49 }
50 4 ▶ wantarray ? @old : join(", ", @old);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 3 4
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
BranchTrueFalseTotal
if (length $_) 29 19 48
71 29 my $weak = "";
72 29 ▶ $weak = "W/" if s,^\s*[wW]/,,;
Branch: 1 branch
BranchTrueFalseTotal
if s[^\s*[wW]/][] 11 18 29
73 29 my $etag = "";
74 29 ▶ if (s/^\s*(\"[^\"\\]*(?:\\.[^\"\\]*)*\")//) {
Branch: 4 branches
BranchTrueFalseTotal
if (s/^\s*(\"[^\"\\]*(?:\\.[^\"\\]*)*\")//) { } 13 16 29
elsif (s/^\s*,//) { } 6 10 16
elsif (s/^\s*([^,\s]+)//) { } 8 2 10
elsif (s/^\s+// or not length $_) { } 2 0 2
75 13 push(@res, "$weak$1");
76 }
77 elsif (s/^\s*,//) {
78 6 ▶ push(@res, qq(W/"")) if $weak;
Branch: 1 branch
BranchTrueFalseTotal
if $weak 1 5 6
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 $_
l!l&&r!l&&!r
110
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 $_
ABresult
1X1
011
000
86 2 ▶ push(@res, qq(W/"")) if $weak;
Branch: 1 branch
BranchTrueFalseTotal
if $weak 1 1 2
87 }
88 else {
89 0 die "This should not happen: '$_'";
90 }
91 }
92 }
93 22 @res;
94 }
95  
96 1 1;
97  
98 __END__
« Headers/Auth.pm ↑ Summary Request.pm »