File Coverage

blib/lib/WWW/PayPal/Role/OpenAPI.pm
Criterion Covered Total %
statement 17 22 77.2
branch 4 10 40.0
condition 1 2 50.0
subroutine 5 6 83.3
pod 2 2 100.0
total 29 42 69.0


line stmt bran cond sub pod time code
1             package WWW::PayPal::Role::OpenAPI;
2              
3             # ABSTRACT: operationId-based dispatch against a cached OpenAPI spec
4              
5 2     2   17815 use Moo::Role;
  2         5  
  2         15  
6 2     2   1178 use Carp qw(croak);
  2         5  
  2         176  
7 2     2   1262 use Log::Any qw($log);
  2         24168  
  2         32  
8              
9             our $VERSION = '0.002';
10              
11              
12             requires 'client';
13             requires 'openapi_operations';
14              
15             sub get_operation {
16 5     5 1 6343 my ($self, $operation_id) = @_;
17 5 100       124 my $op = $self->openapi_operations->{$operation_id}
18             or croak ref($self) . ": unknown operationId '$operation_id'";
19 4         19 return $op;
20             }
21              
22              
23             sub _resolve_path {
24 2     2   1335 my ($self, $path, $params) = @_;
25 2   50     6 $params ||= {};
26 2         14 $path =~ s!\{([^}]+)\}!
27             defined $params->{$1}
28 2 100       162 ? $params->{$1}
29             : croak "missing path parameter '$1' for $path"
30             !ge;
31 1         5 return $path;
32             }
33              
34             sub call_operation {
35 0     0 1   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 0         ? (content_type => $op->{content_type}) : ()),
    0          
    0          
46             );
47             }
48              
49              
50              
51             1;
52              
53             __END__