| 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
| |||||||||||||||
| 10 | die "Only 1 authentication method can be supplied " | ||||||||||||||
| 11 | 7 | ▶ | unless keys( %{ $_[0] } ) <= 1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 20 | 2 | ▶ | return if ref($auth) eq 'CODE'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 32 | unless ( $self->can($handler) ); | ||||||||||||||
| 33 | 2 | ▶ | $self->$validator($data) if ( $self->can($validator) ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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; | |||||||||||||