Bonusly/Service.pm

filter: Statementstmt 95.6% 44 / 46 Branchbran 83.3% 10 / 12 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 87.5% 7 / 8 Podpod n/a totaltotal 89.4% 68 / 76 CC 10 SCAR 18.6
CC
10
Cov
92%
_perform_action
10.1
__ANON__
2.0
BEGIN
1.0
CRAP 6.4
« Bonusly/Users.pm ↑ Summary Bonusly/Leaderboards.pm »
1 package WebService::Bonusly::Service;
2 1 $WebService::Bonusly::Service::VERSION = '1.001';
3 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: A utility class for WebService::Bonusly services
10  
11  
12 1 has ws => (
13 is => 'ro',
14 isa => 'WebService::Bonusly',
15 required => 1,
16 weak_ref => 1,
17 handles => [ qw( token base_url ua _json_flags print_debug ) ],
18 );
19  
20 97 ▶sub _perform_action {
Subroutine _perform_action: called CC=10 SCAR=23.1
21 97 my ($self, $method, $path_info, $params, $tokenless) = @_;
22 97 my %clean = %$params;
23  
24 97 my $res;
25  
26 97 my $path = $self->base_url . $path_info;
27 97 $path =~ s/:(\w+)/delete $clean{$1}/ge;
28 97 ▶ if ($method eq 'GET' || $method eq 'DELETE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($method eq 'GET' or $method eq 'DELETE') { } 68 29 97
elsif ($method eq 'POST' or $method eq 'PUT') { } 29 0 29
Condition100%3/3
$method eq "GET" or $method eq "DELETE"
l!l&&r!l&&!r
66229
MC/DC100%2/2
$method eq "GET" or $method eq "DELETE"
$method eq "GET" $method eq "DELETE"
Truth table100%3/3
A or B
A= $method eq "GET"B= $method eq "DELETE"
ABresult
1X1
011
000
29 68 $path .= '?';
30 68 ▶ $path .= 'access_token=' . $self->token unless $tokenless;
Branch: 1 branch
BranchTrueFalseTotal
unless $tokenless 68 0 68
31 68 for my $k (sort keys %clean) {
32 174 my $v = $clean{$k};
33 174 $path .= '&' . uri_escape($k) . '=' . uri_escape($v);
34 }
35  
36 68 $self->print_debug("SEND>> $method $path");
37 68 ▶ if ($method eq 'GET') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq 'GET') { } 66 2 68
38 66 $res = $self->ua->get($path);
39 }
40 else {
41 2 $res = $self->ua->delete($path);
42 }
43 }
44 ▶ elsif ($method eq 'POST' || $method eq 'PUT') {
Condition66%2/3
$method eq "POST" or $method eq "PUT"
l!l&&r!l&&!r
16130
MC/DC0%0/2
$method eq "POST" or $method eq "PUT"
$method eq "POST" $method eq "PUT"
Truth table66%2/3
A or B
A= $method eq "POST"B= $method eq "PUT"
ABresult
1X1
011
000
45 29 ▶ $path .= '?access_token=' . $self->token unless $tokenless;
Branch: 1 branch
BranchTrueFalseTotal
unless $tokenless 27 2 29
46 29 my $content = to_json(\%clean, $self->_json_flags);
47  
48 29 $self->print_debug("SEND>> $method $path");
49 29 $self->print_debug("SEND>> Content-Type: application/json");
50 29 $self->print_debug("SEND>> $content");
51 29 ▶ if ($method eq 'POST') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq 'POST') { } 16 13 29
52 16 $res = $self->ua->post($path, 'Content-Type' => 'application/json', Content => $content);
53 }
54 else {
55 13 $res = $self->ua->put($path, 'Content-Type' => 'application/json', Content => $content);
56 }
57 }
58 else {
59 0 die "Bad Method " . $method;
60 }
61  
62 97 $self->print_debug("RECV>> ", $res->content);
63  
64 97 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
65 97 from_json($res->content);
66 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 +{
68 0 success => JSON::false,
69 message => $res->message,
70 content => $res->content,
71 status => $res->code,
72 response_object => $res,
73 }
74 97 };
75 }
76  
77 1 __PACKAGE__->meta->make_immutable;
78  
79 __END__
« Bonusly/Users.pm ↑ Summary Bonusly/Leaderboards.pm »