| 1 | package Net::HTTP::API::Role::Authentication; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 4 | $Net::HTTP::API::Role::Authentication::VERSION = '0.14'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Add authentication informations to request header | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | has api_username => ( | |||||||||||||||||||||||||||
| 11 | is => 'rw', | ||||||||||||||||||||||||||||
| 12 | isa => 'Str', | ||||||||||||||||||||||||||||
| 13 | predicate => 'has_api_username', | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | has api_password => ( | |||||||||||||||||||||||||||
| 17 | is => 'rw', | ||||||||||||||||||||||||||||
| 18 | isa => 'Str', | ||||||||||||||||||||||||||||
| 19 | predicate => 'has_api_password', | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # ugly :( | ||||||||||||||||||||||||||||
| 23 | 4 | ▶ | after BUILDALL => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=23.0
| |||||||||||||||||||||||||||||
| 24 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 4 | for (qw/api_username api_password/) { | |||||||||||||||||||||||||||
| 27 | 8 | my $predicate = 'has_' . $_; | |||||||||||||||||||||||||||
| 28 | 8 | my $value = $self->meta->get_api_option($_); | |||||||||||||||||||||||||||
| 29 | 8 | ▶ | $self->$_($value) if $value && !$self->$predicate; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$value and not $self->$predicate
MC/DC0%0/2
$value and not $self->$predicate
$value
not $self->$predicate
Truth table33%1/3
A and not(B)
A= $valueB= not $self->$predicate
| |||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 4 | ▶ | if ( $self->meta->get_api_option('authentication') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->meta->get_api_option("authentication") or $self->meta->get_api_option("authentication_method")
MC/DC50%1/2
$self->meta->get_api_option("authentication") or $self->meta->get_api_option("authentication_method")
$self->meta->get_api_option("authentication")
$self->meta->get_api_option("authentication_method")
Truth table66%2/3
A or B
A= $self->meta->get_api_option("authentication")B= $self->meta->get_api_option("authentication_method")
| |||||||||||||||||||||||||||||
| 33 | || $self->meta->get_api_option('authentication_method')) | ||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | 2 | my $auth_method = $self->meta->get_api_option('authentication_method'); | |||||||||||||||||||||||||||
| 36 | 2 | ▶ | if ($auth_method) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | $self->api_useragent->add_handler( | ||||||||||||||||||||||||||||
| 38 | 1 | ▶ | request_prepare => sub { $self->$auth_method(@_) }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||
| 41 | 1 | ▶ | if ($self->has_api_username && $self->has_api_password) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->has_api_username and $self->has_api_password
MC/DC0%0/2
$self->has_api_username and $self->has_api_password
$self->has_api_username
$self->has_api_password
Truth table33%1/3
A and B
A= $self->has_api_usernameB= $self->has_api_password
| |||||||||||||||||||||||||||||
| 42 | $self->api_useragent->add_handler( | ||||||||||||||||||||||||||||
| 43 | 1 | ▶ | request_prepare => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 1 | my $req = shift; | |||||||||||||||||||||||||||
| 45 | 1 | $req->headers->authorization_basic($self->api_username, | |||||||||||||||||||||||||||
| 46 | $self->api_password); | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 1 | ); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 4 | }; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | 1; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||