File Coverage

blib/lib/WWW/Gitea/Role/OpenAPI.pm
Criterion Covered Total %
statement 22 22 100.0
branch 7 10 70.0
condition 1 2 50.0
subroutine 6 6 100.0
pod 2 2 100.0
total 38 42 90.4


line stmt bran cond sub pod time code
1             package WWW::Gitea::Role::OpenAPI;
2              
3             # ABSTRACT: operationId-based dispatch against a cached operation table
4              
5 4     4   35079 use Moo::Role;
  4         7  
  4         20  
6 4     4   1538 use Carp qw(croak);
  4         6  
  4         207  
7 4     4   1632 use Log::Any qw($log);
  4         31046  
  4         18  
8              
9              
10             requires 'client';
11             requires 'openapi_operations';
12              
13             sub get_operation {
14 14     14 1 7282 my ($self, $operation_id) = @_;
15 14 100       236 my $op = $self->openapi_operations->{$operation_id}
16             or croak ref($self) . ": unknown operationId '$operation_id'";
17 13         77 return $op;
18             }
19              
20              
21             sub _resolve_path {
22 6     6   26 my ($self, $path, $params) = @_;
23 6   50     17 $params ||= {};
24 6         36 $path =~ s!\{([^}]+)\}!
25             defined $params->{$1}
26 13 100       206 ? $params->{$1}
27             : croak "missing path parameter '$1' for $path"
28             !ge;
29 5         17 return $path;
30             }
31              
32             sub call_operation {
33 4     4 1 15 my ($self, $operation_id, %args) = @_;
34 4         67 my $op = $self->get_operation($operation_id);
35 4         18 my $path = $self->_resolve_path($op->{path}, $args{path});
36 4         25 $log->debugf('Gitea op %s -> %s %s', $operation_id, $op->{method}, $path);
37             return $self->client->request(
38             $op->{method},
39             $path,
40             (defined $args{body} ? (body => $args{body}) : ()),
41             (defined $args{query} ? (query => $args{query}) : ()),
42             (defined $op->{content_type}
43 4 50       37 ? (content_type => $op->{content_type}) : ()),
    50          
    50          
44             );
45             }
46              
47              
48              
49             1;
50              
51             __END__