Gitea/Role/OpenAPI.pm

filter: Statementstmt 100% 25 / 25 Branchbran 70.0% 7 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 89.1% 41 / 46 CC 7 SCAR 10.2
CC
7
Cov
89%
call_operation
4.3
_resolve_path
3.0
get_operation
2.0
CRAP 2.8
« Gitea/API/Users.pm ↑ Summary Gitea/Comment.pm »
1 package WWW::Gitea::Role::OpenAPI;
2  
3 # ABSTRACT: operationId-based dispatch against a cached operation table
4  
5 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 4 requires 'client';
11 4 requires 'openapi_operations';
12  
13 sub get_operation {
14 14 ▶ my ($self, $operation_id) = @_;
Subroutine get_operation: called CC=2 SCAR=6.9
Pod documented
15 14 ▶ 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}'") 1 13 14
16 or croak ref($self) . ": unknown operationId '$operation_id'";
17 13 return $op;
18 }
19  
20  
21 sub _resolve_path {
22 6 ▶ my ($self, $path, $params) = @_;
Subroutine _resolve_path: called CC=3 SCAR=11.0
23 6 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
60
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
24 6 $path =~ s!\{([^}]+)\}!
25 defined $params->{$1}
26 13 ▶ ? $params->{$1}
Branch: 1 branch
BranchTrueFalseTotal
defined $params->{$1} ? : 12 1 13
27 : croak "missing path parameter '$1' for $path"
28 !ge;
29 5 return $path;
30 }
31  
32 sub call_operation {
33 4 ▶ my ($self, $operation_id, %args) = @_;
Subroutine call_operation: called CC=4 SCAR=14.6
Pod documented
34 4 my $op = $self->get_operation($operation_id);
35 4 my $path = $self->_resolve_path($op->{path}, $args{path});
36 4 $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 ▶ ? (content_type => $op->{content_type}) : ()),
Branch: 3 branches
BranchTrueFalseTotal
defined $args{'body'} ? : 0 4 4
defined $args{'query'} ? : 4 0 4
defined $op->{'content_type'} ? : 0 4 4
44 );
45 }
46  
47  
48  
49 4 1;
50  
51 __END__
« Gitea/API/Users.pm ↑ Summary Gitea/Comment.pm »