| 1 | package OIDC::Client::ResponseParser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use OIDC::Client::Error::InvalidResponse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use OIDC::Client::Error::Provider; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | OIDC::Client::ResponseParser - Provider response parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | Provider response parser. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | =head2 parse( $response ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | Analyse the result of the L<Mojo::Message::Response> object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | If all is well, returns the Perl structure corresponding to the JSON response. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | On the other hand, if the response is not correctly parsed into JSON format, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | an L<OIDC::Client::Error::InvalidResponse> error is thrown or if the provider | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | returned an error, an L<OIDC::Client::Error::Provider> error is thrown. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 10 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 10 | my ($self, $res) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 10 | ▶ | if ($res->is_success) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | ▶ | return try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | $res->json; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | OIDC::Client::Error::InvalidResponse->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | sprintf(q{Invalid response: %s}, $_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | OIDC::Client::Error::Provider->throw({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | response_parameters => try { $res->json } || {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | alternative_error => $res->is_error ? $res->message || $res->code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | : $res->{error}{message} || $res->{error}{code}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition62%5/8
&try(sub {
$res->json;
}
) || {}
$res->message or $res->code
$res->{"error"}{"message"} or $res->{"error"}{"code"}
MC/DC100%1/1
&try(sub {
$res->json;
}
) || {}
&try(sub {
$res->json;
}
)
MC/DC0%0/2
$res->message or $res->code
$res->message
$res->code
MC/DC0%0/2
$res->{"error"}{"message"} or $res->{"error"}{"code"}
$res->{"error"}{"message"}
$res->{"error"}{"code"}
Truth table100%2/2
A
A= &try(sub {
$res->json;
}
)
Truth table66%2/3
A or B
A= $res->messageB= $res->code
Truth table33%1/3
A or B
A= $res->{"error"}{"message"}B= $res->{"error"}{"code"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||