| 1 | package HTTP::Headers::ActionPack::Authorization::Basic; | ||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: The Basic Authorization Header | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '0.10'; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Carp qw[ confess ]; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use MIME::Base64 qw[ encode_base64 decode_base64 ]; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use parent 'HTTP::Headers::ActionPack::Core::Base'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 15 | 12 | my $class = shift; | |||||||||||||||||||||||||||||||
| 16 | 12 | ▶ | my $type = shift || confess "Must specify type"; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || confess('Must specify type')
MC/DC0%0/1
shift() || confess('Must specify type')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | my $credentials = shift || confess "Must provide credentials"; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || confess('Must provide credentials')
MC/DC0%0/1
shift() || confess('Must provide credentials')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 12 | ▶ | if ( ref $credentials && ref $credentials eq 'HASH' ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
ref $credentials and ref $credentials eq "HASH"
MC/DC100%2/2
ref $credentials and ref $credentials eq "HASH"
ref $credentials
ref $credentials eq "HASH"
Truth table100%3/3
A and B
A= ref $credentialsB= ref $credentials eq "HASH"
| |||||||||||||||||||||||||||||||||
| 20 | 3 | return +{ auth_type => $type, %$credentials }; | |||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||
| 22 | ▶ | elsif ( ref $credentials && ref $credentials eq 'ARRAY' ) { | |||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $credentials and ref $credentials eq "ARRAY"
MC/DC50%1/2
ref $credentials and ref $credentials eq "ARRAY"
ref $credentials
ref $credentials eq "ARRAY"
Truth table66%2/3
A and B
A= ref $credentialsB= ref $credentials eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 23 | 3 | my ($username, $password) = @$credentials; | |||||||||||||||||||||||||||||||
| 24 | 3 | return +{ auth_type => $type, username => $username, password => $password }; | |||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||
| 26 | else { | ||||||||||||||||||||||||||||||||
| 27 | 6 | my ($username, $password) = decode_base64( $credentials ) =~ /^([^:]+):(.*)$/; | |||||||||||||||||||||||||||||||
| 28 | 6 | return +{ auth_type => $type, username => $username, password => $password }; | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | sub new_from_string { | ||||||||||||||||||||||||||||||
|
Subroutine
new_from_string: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 33 | 3 | my ($class, $header_string) = @_; | |||||||||||||||||||||||||||||||
| 34 | 3 | my ($type, $credentials) = split /\s/ => $header_string; | |||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | ($type eq 'Basic') | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | || confess "The type must be 'Basic', not '$type'"; | ||||||||||||||||||||||||||||||||
| 37 | 3 | $class->new( $type, $credentials ); | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 24 | ▶ | sub auth_type { (shift)->{'auth_type'} } | ||||||||||||||||||||||||||||||
|
Subroutine
auth_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 41 | 24 | ▶ | sub username { (shift)->{'username'} } | ||||||||||||||||||||||||||||||
|
Subroutine
username: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 42 | 24 | ▶ | sub password { (shift)->{'password'} } | ||||||||||||||||||||||||||||||
|
Subroutine
password: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 12 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 45 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||
| 46 | 12 | join ' ' => $self->auth_type, encode_base64( (join ':' => $self->username, $self->password), '' ) | |||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 3 | 1; | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | __END__ | ||||||||||||||||||||||||||||||||