Client/ResponseParser.pm

filter: Statementstmt 100% 27 / 27 Branchbran 100% 4 / 4 Conditioncond 62.5% 5 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 87.2% 48 / 55 CC 6 SCAR 11.2
CC
6
Cov
92%
parse
6.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.1
« Client/Role/ConfigurationChecker.pm ↑ Summary Client/Utils.pm »
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
BranchTrueFalseTotal
if ($res->is_success) { } 7 3 10
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
BranchTrueFalseTotal
$res->is_error ? : 2 1 3
Condition62%5/8
&try(sub { $res->json; } ) || {}
l!l
12
$res->message or $res->code
l!l&&r!l&&!r
110
$res->{"error"}{"message"} or $res->{"error"}{"code"}
l!l&&r!l&&!r
010
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; } )
Aresult
11
00
Truth table66%2/3
A or B
A= $res->messageB= $res->code
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $res->{"error"}{"message"}B= $res->{"error"}{"code"}
ABresult
1X1
011
000
53 }
54 }
55  
56 9 __PACKAGE__->meta->make_immutable;
57  
58 9 1;
« Client/Role/ConfigurationChecker.pm ↑ Summary Client/Utils.pm »