blib/lib/OAuth/Lite2/Client/TokenResponseParser.pm

filter: Statementstmt 94.7% 36 / 38 Branchbran 60.0% 6 / 10 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 2 totaltotal 72.0% 54 / 75 SCAR 22.8
CC
9
Cov
79%
parse
10.4
__ANON__
2.1
__ANON__
2.0
CRAP 9.8
« blib/lib/OAuth/Lite2/Server/GrantHandler/ClientCredentials.pm ↑ Summary blib/lib/OAuth/Lite2/Util.pm »
1 package OAuth::Lite2::Client::TokenResponseParser;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use Try::Tiny qw/try catch/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use OAuth::Lite2::Formatters;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use OAuth::Lite2::Client::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use OAuth::Lite2::Client::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub new {
12 10 ▶ bless {}, $_[0];
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13 }
14  
15 sub parse {
16 53 ▶ my ($self, $http_res) = @_;
Subroutine parse: called CC=8 SCAR=23.4
Pod undocumented
17  
18 53 my $formatter =
19 OAuth::Lite2::Formatters->get_formatter_by_type(
20 $http_res->content_type);
21  
22 53 my $token;
23  
24 53 ▶ if ($http_res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($http_res->is_success) { } 20 33 53
25  
26 20 ▶ OAuth::Lite2::Client::Error::InvalidResponse->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $formatter 0 20 20
Condition0%0/2
$http_res->content_type || ''
l!l
00
MC/DC0%0/1
$http_res->content_type || ''
$http_res->content_type
Truth table0%0/2
A
A= $http_res->content_type
Aresult
11
00
27 message => sprintf(q{Invalid response content-type: %s},
28 $http_res->content_type||'')
29 ) unless $formatter;
30  
31 my $result = try {
32 20 ▶ return $formatter->parse($http_res->content);
Subroutine __ANON__: called CC=1 SCAR=0.0
33 } catch {
34 0 ▶ OAuth::Lite2::Client::Error::InvalidResponse->throw(
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 message => sprintf(q{Invalid response format: %s}, $_),
36 );
37 20 };
38  
39 OAuth::Lite2::Client::Error::InvalidResponse->throw(
40 message => sprintf("Response doesn't include 'access_token'")
41 20 ▶ ) unless exists $result->{access_token};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $result->{"access_token"} 0 20 20
42  
43 20 $token = OAuth::Lite2::Client::Token->new($result);
44  
45 } else {
46  
47 33 ▶ my $errmsg = $http_res->content || $http_res->status_line;
Condition33%1/3
$http_res->content || $http_res->status_line
l!l&&r!l&&!r
3300
MC/DC0%0/2
$http_res->content || $http_res->status_line
$http_res->content $http_res->status_line
Truth table33%1/3
A || B
A= $http_res->contentB= $http_res->status_line
ABresult
1X1
011
000
48 33 ▶ if ($formatter && $http_res->content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($formatter and $http_res->content) 33 0 33
Condition33%1/3
$formatter and $http_res->content
!ll&&!rl&&r
0033
MC/DC0%0/2
$formatter and $http_res->content
$formatter $http_res->content
Truth table33%1/3
A and B
A= $formatterB= $http_res->content
ABresult
0X0
100
111
49 try {
50 33 ▶ my $result = $formatter->parse($http_res->content);
Subroutine __ANON__: called CC=2 SCAR=7.2
51 $errmsg = $result->{error}
52 33 ▶ if exists $result->{error};
Branch: 1 branch
BranchTrueFalseTotal
if exists $result->{"error"} 33 0 33
53 33 ▶ } catch { return };
Subroutine __ANON__: not called CC=1 SCAR=1.2
54 }
55 33 OAuth::Lite2::Client::Error::InvalidResponse->throw( message => $errmsg );
56 }
57 20 return $token;
58 }
59  
60  
61 7 1;
« blib/lib/OAuth/Lite2/Server/GrantHandler/ClientCredentials.pm ↑ Summary blib/lib/OAuth/Lite2/Util.pm »