blib/lib/Parse/WWWAuthenticate.pm

filter: Statementstmt 100% 43 / 43 Branchbran 100% 10 / 10 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 100% 76 / 76 CC 12 SCAR 18.5
CC
12
Cov
100%
parse_wwwa
10.0
split_header_words
3.0
BEGIN
1.0
CRAP 6.3
↑ Summary
1 package Parse::WWWAuthenticate;
2  
3 # ABSTRACT: Parse the WWW-Authenticate HTTP header
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use HTTP::Headers::Util qw(_split_header_words);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = '0.04';
14  
15 1 our @EXPORT_OK = qw(parse_wwwa);
16  
17 32 ▶sub parse_wwwa {
Subroutine parse_wwwa: called CC=10 SCAR=23.0
Pod documented
18 32 my ($string) = @_;
19  
20 32 my @parts = split_header_words( $string);
21  
22 32 my $challenge;
23 my @challenges;
24  
25 PART:
26 32 for my $part ( @parts ) {
27 58 my ($maybe_challenge, $challenge_check) = @{$part};
28  
29 58 ▶ if ( !defined $challenge_check ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $challenge_check) 41 17 58
30 41 $challenge = ucfirst lc $maybe_challenge;
31 41 push @challenges, { name => $challenge, params => {} };
32 }
33  
34 58 my ($key, $value) = ($part->[-2], $part->[-1]);
35 58 ▶ if ( !defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 5 53 58
36 5 next PART;
37 }
38  
39 53 my $lc_key = lc $key;
40 53 ▶ if ( $challenge eq 'Basic' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($challenge eq "Basic" and $lc_key eq "realm" and exists $challenges[-1]{"params"}{$lc_key}) 1 52 53
Condition100%6/6
$challenge eq "Basic" and $lc_key eq "realm" and exists $challenges[-1]{"params"}{$lc_key}
!ll&&!rl&&r
28241
$challenge eq "Basic" and $lc_key eq "realm"
!ll&&!rl&&r
22625
MC/DC100%3/3
$challenge eq "Basic" and $lc_key eq "realm" and exists $challenges[-1]{"params"}{$lc_key}
$challenge eq "Basic" $lc_key eq "realm" exists $challenges[-1]{"params"}{$lc_key}
Truth table100%4/4
A and B and C
A= $challenge eq "Basic"B= $lc_key eq "realm"C= exists $challenges[-1]{"params"}{$lc_key}
ABCresult
0XX0
10X0
1100
1111
41 $lc_key eq 'realm' &&
42 exists $challenges[-1]->{params}->{$lc_key}
43 ) {
44 1 croak 'only one realm is allowed';
45 }
46  
47 52 $challenges[-1]->{params}->{lc $key} = $value;
48 }
49  
50 31 for my $challenge ( @challenges ) {
51 40 ▶ if ( $challenge->{name} eq 'Basic' && !exists $challenge->{params}->{realm} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($challenge->{"name"} eq "Basic" and not exists $challenge->{"params"}{"realm"}) 1 39 40
Condition100%3/3
$challenge->{"name"} eq "Basic" and not exists $challenge->{"params"}{"realm"}
!ll&&!rl&&r
16231
MC/DC100%2/2
$challenge->{"name"} eq "Basic" and not exists $challenge->{"params"}{"realm"}
$challenge->{"name"} eq "Basic" not exists $challenge->{"params"}{"realm"}
Truth table100%3/3
A and not(B)
A= $challenge->{"name"} eq "Basic"B= not exists $challenge->{"params"}{"realm"}
ABresult
0X0
100
111
52 1 croak 'realm parameter is missing';
53 }
54 }
55  
56 30 return @challenges;
57 }
58  
59 32 ▶sub split_header_words {
Subroutine split_header_words: called CC=3 SCAR=11.0
Pod documented
60 32 my @res = &_split_header_words;
61 32 for my $arr (@res) {
62 58 ▶ for (my $i = @$arr - 2; $i >= 0; $i -= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 94 58 152
63 94 $arr->[$i] = $arr->[$i];
64 }
65 }
66 32 return @res;
67 }
68  
69 1 1;
70  
71 __END__
↑ Summary