| 1 | package Net::Async::Keycloak::Role::HTTP; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Sending requests to Keycloak through Net::Async::HTTP | ||||||||||
| 4 | |||||||||||
| 5 | 8 | ▶ | use Future; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 8 | ▶ | use Net::Async::Keycloak::Error::API; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 8 | ▶ | use Net::Async::Keycloak::Error::Network; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 8 | ▶ | use Net::Async::Keycloak::Error::Validation; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 8 | ▶ | use Scalar::Util qw( blessed ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 8 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 8 | our $VERSION = '0.001'; | |||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | 27 | ▶ | sub api_error_class { 'Net::Async::Keycloak::Error::API' } | ||||||||
|
Subroutine
api_error_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 16 | 2 | ▶ | sub network_error_class { 'Net::Async::Keycloak::Error::Network' } | ||||||||
|
Subroutine
network_error_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 17 | 52 | ▶ | sub validation_error_class { 'Net::Async::Keycloak::Error::Validation' } | ||||||||
|
Subroutine
validation_error_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 18 | |||||||||||
| 19 | 6 | ▶ | sub fail_validation { | ||||||||
|
Subroutine
fail_validation: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 20 | 6 | my ( $self, $message ) = @_; | |||||||||
| 21 | 6 | return Future->fail( $self->validation_error_class->new( message => $message ) ); | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | 178 | ▶ | sub send_request_f { | ||||||||
|
Subroutine
send_request_f: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 26 | 178 | my ( $self, $method, $url, %arg ) = @_; | |||||||||
| 27 | 178 | my $request = $self->build_request( $method, $url, %arg ); | |||||||||
| 28 | # Net::Async::HTTP dies instead of failing when it is in no loop | ||||||||||
| 29 | 178 | my $sent = eval { $self->http->do_request( request => $request ) }; | |||||||||
| 30 | 178 | ▶ | return Future->fail( $self->network_error_class->new( message => $method.' '.$url.': could not send (' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | .( $@ =~ s/ at \S+ line \d+.*//sr ).'); was the Net::Async::Keycloak added to a loop?' ) ) unless $sent; | ||||||||||
| 32 | 1 | ▶ | return $sent->else( sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||
| 33 | 1 | my ( $message ) = @_; | |||||||||
| 34 | 1 | ▶ | return Future->fail($message) if blessed $message; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 1 | return Future->fail( $self->network_error_class->new( message => $method.' '.$url.': '.$message ) ); | |||||||||
| 36 | 176 | ▶ | } )->then( sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 37 | 176 | my ( $response ) = @_; | |||||||||
| 38 | 176 | my $result = eval { $self->read_response( $response, $method, $url, %arg ) }; | |||||||||
| 39 | 176 | ▶ | return $result ? Future->done($result) : Future->fail($@); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 177 | } ); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | 8 | 1; | |||||||||
| 45 | |||||||||||
| 46 | __END__ | ||||||||||