| 1 | package WWW::Gitea::Role::OpenAPI; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | # ABSTRACT: operationId-based dispatch against a cached operation table | ||||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | 5 | ▶ | use Moo::Role; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 5 | ▶ | use Carp qw(croak); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 5 | ▶ | use Log::Any qw($log); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 5 | requires 'client'; | |||||||||||||||||||||
| 11 | 5 | requires 'openapi_operations'; | |||||||||||||||||||||
| 12 | |||||||||||||||||||||||
| 13 | 23 | ▶ | sub get_operation { | ||||||||||||||||||||
|
Subroutine
get_operation: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 14 | 23 | my ($self, $operation_id) = @_; | |||||||||||||||||||||
| 15 | 23 | ▶ | my $op = $self->openapi_operations->{$operation_id} | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 16 | or croak ref($self) . ": unknown operationId '$operation_id'"; | ||||||||||||||||||||||
| 17 | 22 | return $op; | |||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | 9 | ▶ | sub _resolve_path { | ||||||||||||||||||||
|
Subroutine
_resolve_path: called CC=3 SCAR=11.0
| |||||||||||||||||||||||
| 22 | 9 | my ($self, $path, $params) = @_; | |||||||||||||||||||||
| 23 | 9 | ▶ | $params ||= {}; | ||||||||||||||||||||
|
Condition50%1/2
$params ||= {}
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
| |||||||||||||||||||||||
| 24 | 9 | $path =~ s!\{([^}]+)\}! | |||||||||||||||||||||
| 25 | defined $params->{$1} | ||||||||||||||||||||||
| 26 | 23 | ▶ | ? $params->{$1} | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 27 | : croak "missing path parameter '$1' for $path" | ||||||||||||||||||||||
| 28 | !ge; | ||||||||||||||||||||||
| 29 | 8 | return $path; | |||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | 6 | ▶ | sub call_operation { | ||||||||||||||||||||
|
Subroutine
call_operation: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||
| 33 | 6 | my ($self, $operation_id, %args) = @_; | |||||||||||||||||||||
| 34 | 6 | my $op = $self->get_operation($operation_id); | |||||||||||||||||||||
| 35 | 6 | my $path = $self->_resolve_path($op->{path}, $args{path}); | |||||||||||||||||||||
| 36 | 6 | $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 | ▶ | ? (content_type => $op->{content_type}) : ()), | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||
| 47 | |||||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | 5 | 1; | |||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||