blib/lib/WWW/JSON/Role/Authentication.pm

filter: Statementstmt 96.4% 27 / 28 Branchbran 55.5% 10 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 82.3% 42 / 51 SCAR 23.7
CC
10
Cov
80%
_trigger_authentication
6.6
__ANON__
3.2
__ANON__
3.1
CRAP 10.7
« blib/lib/WWW/JSON.pm ↑ Summary Build »
1 package WWW::JSON::Role::Authentication;
2 8 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 has authentication => (
4 is => 'rw',
5 lazy => 1,
6 clearer => 1,
7 5 ▶ default => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
8 isa => sub {
9 7 ▶ return if ref( $_[0] ) eq 'CODE';
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "CODE" 0 7 7
10 die "Only 1 authentication method can be supplied "
11 7 ▶ unless keys( %{ $_[0] } ) <= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$_[0];} <= 1 0 7 7
12 },
13 8 trigger => 1,
14  
15 );
16  
17 sub _trigger_authentication {
18 2 ▶ my ( $self, $auth ) = @_;
Subroutine _trigger_authentication: called CC=6 SCAR=18.8
19 2 ▶ return unless ($auth);
Branch: 1 branch
BranchTrueFalseTotal
unless $auth 0 2 2
20 2 ▶ return if ref($auth) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $auth eq "CODE" 0 2 2
21  
22 2 my ( $name, $data ) = %$auth;
23 2 my $role = __PACKAGE__ . '::' . $name;
24  
25 2 ▶ Moo::Role->apply_roles_to_object( $self, $role )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->does($role) 0 2 2
26 unless $self->does($role);
27  
28 2 my $handler = '_auth_' . $name;
29 2 my $validator = '_validate_' . $name;
30  
31 2 ▶ die "No handler found for auth type [$name]"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($handler) 0 2 2
32 unless ( $self->can($handler) );
33 2 ▶ $self->$validator($data) if ( $self->can($validator) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($validator) 2 0 2
34 }
35  
36 around http_request => sub {
37 18 ▶ my ( $orig, $self ) = ( shift, shift );
Subroutine __ANON__: called CC=3 SCAR=11.2
38 18 ▶ if ( ref( $self->authentication ) eq 'CODE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->authentication eq 'CODE') { } 0 18 18
elsif (() = %{$self->authentication;}) { } 3 15 18
39 0 $self->authentication->( $self, @_ );
40 }
41 18 elsif ( my ( $auth_type, $auth ) = %{ $self->authentication } ) {
42 3 my $handler = '_auth_' . $auth_type;
43 3 $self->$handler( $auth, @_ );
44 }
45 18 $self->$orig(@_);
46 8 };
47  
48 8 with qw/WWW::JSON::Role::Authentication::Basic
49 WWW::JSON::Role::Authentication::OAuth1
50 WWW::JSON::Role::Authentication::OAuth2
51 WWW::JSON::Role::Authentication::Header
52 /;
53 8 1;
« blib/lib/WWW/JSON.pm ↑ Summary Build »