File Coverage

blib/lib/WWW/Gitea/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::Gitea::Role::OpenAPI;
2              
3             # ABSTRACT: operationId-based dispatch against a cached operation table
4              
5 3     3   26644 use Moo::Role;
  3         5  
  3         19  
6 3     3   1493 use Carp qw(croak);
  3         5  
  3         197  
7 3     3   1427 use Log::Any qw($log);
  3         30742  
  3         12  
8              
9              
10             requires 'client';
11             requires 'openapi_operations';
12              
13             sub get_operation {
14 10     10 1 7353 my ($self, $operation_id) = @_;
15 10 100       154 my $op = $self->openapi_operations->{$operation_id}
16             or croak ref($self) . ": unknown operationId '$operation_id'";
17 9         55 return $op;
18             }
19              
20              
21             sub _resolve_path {
22 2     2   18 my ($self, $path, $params) = @_;
23 2   50     5 $params ||= {};
24 2         13 $path =~ s!\{([^}]+)\}!
25             defined $params->{$1}
26 4 100       159 ? $params->{$1}
27             : croak "missing path parameter '$1' for $path"
28             !ge;
29 1         5 return $path;
30             }
31              
32             sub call_operation {
33 0     0 1   my ($self, $operation_id, %args) = @_;
34 0           my $op = $self->get_operation($operation_id);
35 0           my $path = $self->_resolve_path($op->{path}, $args{path});
36 0           $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 0 0         ? (content_type => $op->{content_type}) : ()),
    0          
    0          
44             );
45             }
46              
47              
48              
49             1;
50              
51             __END__