File Coverage

blib/lib/WWW/Gitea/Role/OpenAPI.pm
Criterion Covered Total %
statement 22 22 100.0
branch 9 12 75.0
condition 1 2 50.0
subroutine 6 6 100.0
pod 2 2 100.0
total 40 44 90.9


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 5     5   53543 use Moo::Role;
  5         9  
  5         31  
6 5     5   2388 use Carp qw(croak);
  5         8  
  5         346  
7 5     5   2571 use Log::Any qw($log);
  5         51058  
  5         24  
8              
9              
10             requires 'client';
11             requires 'openapi_operations';
12              
13             sub get_operation {
14 23     23 1 8258 my ($self, $operation_id) = @_;
15 23 100       463 my $op = $self->openapi_operations->{$operation_id}
16             or croak ref($self) . ": unknown operationId '$operation_id'";
17 22         182 return $op;
18             }
19              
20              
21             sub _resolve_path {
22 9     9   46 my ($self, $path, $params) = @_;
23 9   50     27 $params ||= {};
24 9         67 $path =~ s!\{([^}]+)\}!
25             defined $params->{$1}
26 23 100       279 ? $params->{$1}
27             : croak "missing path parameter '$1' for $path"
28             !ge;
29 8         37 return $path;
30             }
31              
32             sub call_operation {
33 6     6 1 33 my ($self, $operation_id, %args) = @_;
34 6         32 my $op = $self->get_operation($operation_id);
35 6         31 my $path = $self->_resolve_path($op->{path}, $args{path});
36 6         54 $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 $args{upload} ? (upload => $args{upload}) : ()),
43             (defined $op->{content_type}
44 6 50       104 ? (content_type => $op->{content_type}) : ()),
    50          
    100          
    50          
45             );
46             }
47              
48              
49              
50             1;
51              
52             __END__