PayPal/Role/OpenAPI.pm

filter: Statementstmt 80.7% 21 / 26 Branchbran 40.0% 4 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 70.2% 33 / 47 CC 7 SCAR 20.8
CC
7
Cov
68%
call_operation
20.0
_resolve_path
3.0
get_operation
2.0
CRAP 8.0
« PayPal/API/Plans.pm ↑ Summary PayPal.pm »
1 package WWW::PayPal::Role::OpenAPI;
2  
3 # ABSTRACT: operationId-based dispatch against a cached OpenAPI spec
4  
5 3 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '0.003';
10  
11  
12 3 requires 'client';
13 3 requires 'openapi_operations';
14  
15 13 ▶sub get_operation {
Subroutine get_operation: called CC=2 SCAR=6.9
Pod documented
16 13 my ($self, $operation_id) = @_;
17 13 ▶ my $op = $self->openapi_operations->{$operation_id}
Branch: 1 branch
BranchTrueFalseTotal
my $op = $self->openapi_operations->{$operation_id} or croak(ref($self) . ": unknown operationId '${operation_id}'") 11 2 13
18 or croak ref($self) . ": unknown operationId '$operation_id'";
19 11 return $op;
20 }
21  
22  
23 4 ▶sub _resolve_path {
Subroutine _resolve_path: called CC=3 SCAR=11.0
24 4 my ($self, $path, $params) = @_;
25 4 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
40
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
26 4 $path =~ s!\{([^}]+)\}!
27 defined $params->{$1}
28 4 ▶ ? $params->{$1}
Branch: 1 branch
BranchTrueFalseTotal
defined $params->{$1} ? : 3 1 4
29 : croak "missing path parameter '$1' for $path"
30 !ge;
31 3 return $path;
32 }
33  
34 0 ▶sub call_operation {
Subroutine call_operation: not called CC=4 SCAR=30.0
Pod documented
35 0 my ($self, $operation_id, %args) = @_;
36 0 my $op = $self->get_operation($operation_id);
37 0 my $path = $self->_resolve_path($op->{path}, $args{path});
38 0 $log->debugf('PayPal op %s -> %s %s', $operation_id, $op->{method}, $path);
39 return $self->client->request(
40 $op->{method},
41 $path,
42 (defined $args{body} ? (body => $args{body}) : ()),
43 (defined $args{query} ? (query => $args{query}) : ()),
44 (defined $op->{content_type}
45 0 ▶ ? (content_type => $op->{content_type}) : ()),
Branch: 3 branches
BranchTrueFalseTotal
defined $args{'body'} ? : 0 0 0
defined $args{'query'} ? : 0 0 0
defined $op->{'content_type'} ? : 0 0 0
46 );
47 }
48  
49  
50  
51 3 1;
52  
53 __END__
« PayPal/API/Plans.pm ↑ Summary PayPal.pm »