blib/lib/OIDC/Lite/Client/TokenResponseParser.pm

filter: Statementstmt 100% 38 / 38 Branchbran 100% 10 / 10 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 2 totaltotal 97.3% 73 / 75 CC 9 SCAR 13.6
CC
9
Cov
100%
parse
8.0
__ANON__
2.0
BEGIN
1.0
CRAP 3.9
« Build ↑ Summary blib/lib/OIDC/Lite/Client/WebServer.pm »
1 package OIDC::Lite::Client::TokenResponseParser;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use Try::Tiny qw/try catch/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use OIDC::Lite::Client::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use OAuth::Lite2::Formatters;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use OAuth::Lite2::Client::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11 6 ▶ bless {}, $_[0];
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
12 }
13  
14 sub parse {
15 26 ▶ my ($self, $http_res) = @_;
Subroutine parse: called CC=8 SCAR=20.8
Pod undocumented
16  
17 26 my $formatter =
18 OAuth::Lite2::Formatters->get_formatter_by_type(
19 $http_res->content_type);
20  
21 26 my $token;
22  
23 26 ▶ if ($http_res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($http_res->is_success) { } 10 16 26
24  
25 10 ▶ OAuth::Lite2::Client::Error::InvalidResponse->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $formatter 2 8 10
Condition100%2/2
$http_res->content_type || ''
l!l
11
MC/DC100%1/1
$http_res->content_type || ''
$http_res->content_type
Truth table100%2/2
A
A= $http_res->content_type
Aresult
11
00
26 message => sprintf(q{Invalid response content-type: %s},
27 $http_res->content_type||'')
28 ) unless $formatter;
29  
30 my $result = try {
31 8 ▶ return $formatter->parse($http_res->content);
Subroutine __ANON__: called CC=1 SCAR=0.0
32 } catch {
33 1 ▶ OAuth::Lite2::Client::Error::InvalidResponse->throw(
Subroutine __ANON__: called CC=1 SCAR=0.0
34 message => sprintf(q{Invalid response format: %s}, $_),
35 );
36 8 };
37  
38 OAuth::Lite2::Client::Error::InvalidResponse->throw(
39 message => sprintf("Response doesn't include 'access_token'")
40 7 ▶ ) unless exists $result->{access_token};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $result->{"access_token"} 1 6 7
41  
42 6 $token = OIDC::Lite::Client::Token->new($result);
43  
44 } else {
45  
46 16 ▶ my $errmsg = $http_res->content || $http_res->status_line;
Condition100%3/3
$http_res->content || $http_res->status_line
l!l&&r!l&&!r
1312
MC/DC100%2/2
$http_res->content || $http_res->status_line
$http_res->content $http_res->status_line
Truth table100%3/3
A || B
A= $http_res->contentB= $http_res->status_line
ABresult
1X1
011
000
47 16 ▶ if ($formatter && $http_res->content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($formatter and $http_res->content) 13 3 16
Condition100%3/3
$formatter and $http_res->content
!ll&&!rl&&r
1213
MC/DC100%2/2
$formatter and $http_res->content
$formatter $http_res->content
Truth table100%3/3
A and B
A= $formatterB= $http_res->content
ABresult
0X0
100
111
48 try {
49 13 ▶ my $result = $formatter->parse($http_res->content);
Subroutine __ANON__: called CC=2 SCAR=6.9
50 $errmsg = $result->{error}
51 12 ▶ if exists $result->{error};
Branch: 1 branch
BranchTrueFalseTotal
if exists $result->{"error"} 11 1 12
52 } catch {
53 1 ▶ return OAuth::Lite2::Client::Error::InvalidResponse->throw;
Subroutine __ANON__: called CC=1 SCAR=0.0
54 13 };
55 }
56 15 OAuth::Lite2::Client::Error::InvalidResponse->throw( message => $errmsg );
57 }
58 6 return $token;
59 }
60  
61 =head1 AUTHOR
62  
63 Ryo Ito, E<lt>ritou.06@gmail.comE<gt>
64  
65 =head1 COPYRIGHT AND LICENSE
66  
67 Copyright (C) 2012 by Ryo Ito
68  
69 This library is free software; you can redistribute it and/or modify
70 it under the same terms as Perl itself, either Perl version 5.8.8 or,
71 at your option, any later version of Perl 5 you may have available.
72  
73 =cut
74  
75 3 1;
« Build ↑ Summary blib/lib/OIDC/Lite/Client/WebServer.pm »