OAuth/Lite2/Client/StateResponseParser.pm

filter: Statementstmt 79.4% 31 / 39 Branchbran 33.3% 4 / 12 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 75.0% 9 / 12 Podpod 0.0% 0 / 2 totaltotal 56.4% 44 / 78 CC 10 SCAR 25.7
CC
10
Cov
59%
parse
27.9
__ANON__
6.0
__ANON__
2.0
CRAP 13.1
« OAuth/Lite2/Client/WebServer.pm ↑ Summary OAuth/Lite2/Server/GrantHandler/ExternalService.pm »
1 package OAuth::Lite2::Client::StateResponseParser;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Try::Tiny qw/try catch/;
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 3 ▶use OAuth::Lite2::Client::ServerState;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 OAuth::Lite2::Client::StateResponseParser - Server state response parser
14  
15 =head1 DESCRIPTION
16  
17 Server state response parser
18  
19 =cut
20  
21 4 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
22 4 bless {}, $_[0];
23 }
24  
25 1 ▶sub parse {
Subroutine parse: called CC=9 SCAR=33.3
Pod undocumented
26 1 my ($self, $http_res) = @_;
27  
28 1 my $formatter =
29 OAuth::Lite2::Formatters->get_formatter_by_type(
30 $http_res->content_type);
31  
32 1 my $state;
33  
34 1 ▶ if ($http_res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($http_res->is_success) { } 1 0 1
35  
36 1 ▶ OAuth::Lite2::Client::Error::InvalidResponse->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $formatter 0 1 1
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
37 message => sprintf(q{Invalid response content-type: %s},
38 $http_res->content_type||'')
39 ) unless $formatter;
40  
41 1 ▶ my $result = try {
Subroutine __ANON__: called CC=1 SCAR=0.0
42 1 return $formatter->parse($http_res->content);
43 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 0 OAuth::Lite2::Client::Error::InvalidResponse->throw(
45 message => sprintf(q{Invalid response format: %s}, $_),
46 );
47 1 };
48  
49 OAuth::Lite2::Client::Error::InvalidResponse->throw(
50 message => sprintf("Response doesn't include 'server_state'")
51 1 ▶ ) unless exists $result->{server_state};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $result->{"server_state"} 0 1 1
52  
53 OAuth::Lite2::Client::Error::InvalidResponse->throw(
54 message => sprintf("Response doesn't include 'expires_in'")
55 1 ▶ ) unless exists $result->{expires_in};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $result->{"expires_in"} 0 1 1
56  
57 1 $state = OAuth::Lite2::Client::ServerState->new($result);
58  
59 } else {
60  
61 0 ▶ my $errmsg = $http_res->content || $http_res->status_line;
Condition0%0/3
$http_res->content || $http_res->status_line
l!l&&r!l&&!r
000
MC/DC0%0/2
$http_res->content || $http_res->status_line
$http_res->content $http_res->status_line
Truth table0%0/3
A || B
A= $http_res->contentB= $http_res->status_line
ABresult
1X1
011
000
62  
63 0 ▶ if ($formatter && $http_res->content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($formatter and $http_res->content) 0 0 0
Condition0%0/3
$formatter and $http_res->content
!ll&&!rl&&r
000
MC/DC0%0/2
$formatter and $http_res->content
$formatter $http_res->content
Truth table0%0/3
A and B
A= $formatterB= $http_res->content
ABresult
0X0
100
111
64 0 ▶ try {
Subroutine __ANON__: not called CC=2 SCAR=17.9
65 0 my $result = $formatter->parse($http_res->content);
66 $errmsg = $result->{error}
67 0 ▶ if exists $result->{error};
Branch: 1 branch
BranchTrueFalseTotal
if exists $result->{"error"} 0 0 0
68 0 ▶ } catch { return };
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 }
70 0 OAuth::Lite2::Client::Error::InvalidResponse->throw( message => $errmsg );
71 }
72 1 return $state;
73 }
74  
75 =head1 AUTHOR
76  
77 Ryo Ito, E<lt>ritou.06@gmail.comE<gt>
78  
79 Lyo Kato, E<lt>lyo.kato@gmail.comE<gt>
80  
81 =head1 COPYRIGHT AND LICENSE
82  
83 Copyright (C) 2010 by Lyo Kato
84  
85 This library is free software; you can redistribute it and/or modify
86 it under the same terms as Perl itself, either Perl version 5.8.8 or,
87 at your option, any later version of Perl 5 you may have available.
88  
89 =cut
90  
91 3 1;
« OAuth/Lite2/Client/WebServer.pm ↑ Summary OAuth/Lite2/Server/GrantHandler/ExternalService.pm »