Gitea/Role/OpenAPI.pm

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