| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | next PART; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 53 | my $lc_key = lc $key; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 53 | ▶ | if ( $challenge eq 'Basic' && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$challenge eq "Basic" and $lc_key eq "realm" and exists $challenges[-1]{"params"}{$lc_key}
$challenge eq "Basic" and $lc_key eq "realm"
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}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$challenge->{"name"} eq "Basic" and not exists $challenge->{"params"}{"realm"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 94 | $arr->[$i] = $arr->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 32 | return @res; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||||||||||||||||