Gitea/Role/OpenAPI.pm

filter: Statementstmt 100% 25 / 25 Branchbran 75.0% 9 / 12 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 89.5% 43 / 48 CC 8 SCAR 11.9
CC
8
Cov
90%
call_operation
5.3
_resolve_path
3.0
get_operation
2.0
CRAP 3.3
« Gitea/API/Orgs.pm ↑ Summary Gitea/API/Users.pm »
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
BranchTrueFalseTotal
my $op = $self->openapi_operations->{$operation_id} or croak(ref($self) . ": unknown operationId '${operation_id}'") 22 1 23
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 ||= {}
l!l
90
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
24 9 $path =~ s!\{([^}]+)\}!
25 defined $params->{$1}
26 23 ▶ ? $params->{$1}
Branch: 1 branch
BranchTrueFalseTotal
defined $params->{$1} ? : 22 1 23
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
BranchTrueFalseTotal
defined $args{'body'} ? : 0 6 6
defined $args{'query'} ? : 6 0 6
defined $args{'upload'} ? : 2 4 6
defined $op->{'content_type'} ? : 0 6 6
45 );
46 }
47  
48  
49  
50 5 1;
51  
52 __END__
« Gitea/API/Orgs.pm ↑ Summary Gitea/API/Users.pm »