Headers/Auth.pm

filter: Statementstmt 100% 59 / 59 Branchbran 96.4% 27 / 28 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 99.0% 101 / 102 CC 17 SCAR 21.2
CC
17
Cov
99%
_authenticate
13.0
_parse_authenticate
5.0
BEGIN
1.0
CRAP 8.3
« Headers/Util.pm ↑ Summary Headers/ETag.pm »
1 package HTTP::Headers::Auth;
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 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 package
11 HTTP::Headers;
12  
13 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 # we provide a new (and better) implementations below
15 1 undef(&www_authenticate);
16 1 undef(&proxy_authenticate);
17 }
18  
19 1 require HTTP::Headers::Util;
20  
21 sub _parse_authenticate
22 4 ▶{
Subroutine _parse_authenticate: called CC=5 SCAR=16.1
23 4 my @ret;
24 4 for (HTTP::Headers::Util::split_header_words(@_)) {
25 9 ▶ if (!defined($_->[1])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_->[1]) 6 3 9
26 # this is a new auth scheme
27 6 push(@ret, shift(@$_) => {});
28 6 shift @$_;
29 }
30 9 ▶ if (@ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ret) { } 9 0 9
31 # this a new parameter pair for the last auth scheme
32 9 ▶ while (@$_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$_) 6 9 15
33 6 my $k = shift @$_;
34 6 my $v = shift @$_;
35 6 $ret[-1]{$k} = $v;
36 }
37 }
38 else {
39 # something wrong, parameter pair without any scheme seen
40 # IGNORE
41 }
42 }
43 4 @ret;
44 }
45  
46 sub _authenticate
47 8 ▶{
Subroutine _authenticate: called CC=13 SCAR=25.6
48 8 my $self = shift;
49 8 my $header = shift;
50 8 my @old = $self->_header($header);
51 8 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 2 8
52 6 $self->remove_header($header);
53 6 my @new = @_;
54 6 ▶ while (@new) {
Branch: 1 branch
BranchTrueFalseTotal
if (@new) 8 6 14
55 8 my $a_scheme = shift(@new);
56 8 ▶ if ($a_scheme =~ /\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a_scheme =~ /\s/) { } 1 7 8
57 # assume complete valid value, pass it through
58 1 $self->push_header($header, $a_scheme);
59 }
60 else {
61 7 my @param;
62 7 ▶ if (@new) {
Branch: 1 branch
BranchTrueFalseTotal
if (@new) 5 2 7
63 5 my $p = $new[0];
64 5 ▶ if (ref($p) eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $p eq 'ARRAY') { } 1 4 5
elsif (ref $p eq 'HASH') { } 3 1 4
65 1 @param = @$p;
66 1 shift(@new);
67 }
68 elsif (ref($p) eq "HASH") {
69 3 @param = %$p;
70 3 shift(@new);
71 }
72 }
73 7 my $val = ucfirst(lc($a_scheme));
74 7 ▶ if (@param) {
Branch: 1 branch
BranchTrueFalseTotal
if (@param) 4 3 7
75 4 my $sep = " ";
76 4 ▶ while (@param) {
Branch: 1 branch
BranchTrueFalseTotal
if (@param) 6 4 10
77 6 my $k = shift @param;
78 6 my $v = shift @param;
79 6 ▶ if ($v =~ /[^0-9a-zA-Z]/ || lc($k) eq "realm") {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /[^0-9a-zA-Z]/ or lc $k eq "realm") 3 3 6
Condition100%3/3
$v =~ /[^0-9a-zA-Z]/ or lc $k eq "realm"
l!l&&r!l&&!r
123
MC/DC100%2/2
$v =~ /[^0-9a-zA-Z]/ or lc $k eq "realm"
$v =~ /[^0-9a-zA-Z]/ lc $k eq "realm"
Truth table100%3/3
A or B
A= $v =~ /[^0-9a-zA-Z]/B= lc $k eq "realm"
ABresult
1X1
011
000
80 # must quote the value
81 3 $v =~ s,([\\\"]),\\$1,g;
82 3 $v = qq("$v");
83 }
84 6 $val .= "$sep$k=$v";
85 6 $sep = ", ";
86 }
87 }
88 7 $self->push_header($header, $val);
89 }
90 }
91 }
92 8 ▶ return unless defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 3 5 8
93 5 ▶ wantarray ? _parse_authenticate(@old) : join(", ", @old);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 1 5
94 }
95  
96  
97 5 ▶sub www_authenticate { shift->_authenticate("WWW-Authenticate", @_) }
Subroutine www_authenticate: called CC=1 SCAR=0.0
Pod documented
98 3 ▶sub proxy_authenticate { shift->_authenticate("Proxy-Authenticate", @_) }
Subroutine proxy_authenticate: called CC=1 SCAR=0.0
Pod documented
99  
100 1 1;
101  
102 __END__
« Headers/Util.pm ↑ Summary Headers/ETag.pm »