Foursquare/Response.pm

filter: Statementstmt 100% 23 / 23 Branchbran 100% 2 / 2 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 78.5% 33 / 42 CC 5 SCAR 12.2
CC
5
Cov
88%
process
5.3
BEGIN
1.0
BEGIN
1.0
CRAP 3.4
« Foursquare/Request.pm ↑ Summary Foursquare/Users.pm »
1 package WWW::Foursquare::Response;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 our %ERROR_TYPE = (
9 invalid_auth => 'OAuth token was not provided or was invalid',
10 param_error => 'A required parameter was missing or a parameter was malformed. This is also used if the resource ID in the path is incorrect',
11 endpoint_error => 'The requested path does not exist',
12 not_authorized => 'Although authentication succeeded, the acting user is not allowed to see this information due to privacy restrictions',
13 rate_limit_exceeded => 'Rate limit for this hour exceeded',
14 deprecated => 'Something about this request is using deprecated functionality, or the response format may be about to change',
15 server_error => 'erver is currently experiencing issues. Check status.foursquare.com for updates',
16 other => 'Some other type of error occurred',
17 unknown => 'Unknown error',
18 );
19  
20 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
21 1 my ($class, $params) = @_;
22  
23 1 my $self = {};
24 1 bless $self, $class;
25 1 return $self;
26 }
27  
28 2 ▶sub process {
Subroutine process: called CC=5 SCAR=16.7
Pod undocumented
29 2 my ($self, $res) = @_;
30  
31 2 my $data = decode_json($res->content());
32 2 my $code = $res->code();
33  
34 # response is OK
35 2 ▶ return $data->{response} if $code == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $code == 200 1 1 2
36  
37 # need error handling
38 1 ▶ my $error_type = $data->{meta}->{errorType} || 'unkwown';
Condition50%1/2
$data->{'meta'}{'errorType'} || 'unkwown'
l!l
10
MC/DC0%0/1
$data->{'meta'}{'errorType'} || 'unkwown'
$data->{'meta'}{'errorType'}
Truth table50%1/2
A
A= $data->{'meta'}{'errorType'}
Aresult
11
00
39 1 ▶ my $error_desc = $ERROR_TYPE{$error_type} || $data->{meta}->{errorDetail} || 'no details';
Condition40%2/5
$WWW::Foursquare::Response::ERROR_TYPE{$error_type} || $data->{'meta'}{'errorDetail'} || 'no details'
l!l
10
$WWW::Foursquare::Response::ERROR_TYPE{$error_type} or $data->{"meta"}{"errorDetail"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$WWW::Foursquare::Response::ERROR_TYPE{$error_type} || $data->{'meta'}{'errorDetail'} || 'no details'
$WWW::Foursquare::Response::ERROR_TYPE{$error_type} $data->{"meta"}{"errorDetail"}
Truth table33%1/3
A or B
A= $WWW::Foursquare::Response::ERROR_TYPE{$error_type}B= $data->{"meta"}{"errorDetail"}
ABresult
1X1
011
000
40 1 my $error_text = sprintf "%s %s", $error_type, $error_desc;
41  
42 # raise exception
43 1 die $error_text;
44 }
45  
46  
47 5 1;
« Foursquare/Request.pm ↑ Summary Foursquare/Users.pm »