VastAI/API/Endpoints.pm

filter: Statementstmt 100% 40 / 40 Branchbran 50.0% 8 / 16 Conditioncond 30.0% 3 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 76.7% 66 / 86 CC 13 SCAR 14.5
CC
13
Cov
77%
create
7.3
list
6.6
delete
2.0
CRAP 4.3
« VastAI/API/Templates.pm ↑ Summary VastAI/API/Volumes.pm »
1 package WWW::VastAI::API::Endpoints;
2 10 our $VERSION = '0.001';
3 # ABSTRACT: Serverless endpoint management for Vast.ai
4  
5 10 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use WWW::VastAI::Endpoint;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 10 has client => (
11 is => 'ro',
12 required => 1,
13 weak_ref => 1,
14 );
15  
16 2 ▶sub _wrap {
Subroutine _wrap: called CC=1 SCAR=0.0
17 2 my ($self, $data) = @_;
18 2 return WWW::VastAI::Endpoint->new(
19 client => $self->client,
20 data => $data,
21 );
22 }
23  
24 1 ▶sub list {
Subroutine list: called CC=5 SCAR=18.9
Pod documented
25 1 my ($self) = @_;
26 1 my $result = $self->client->request_op('listEndpoints');
27 1 ▶ my $endpoints = ref $result eq 'HASH' ? ($result->{endpoints} || $result->{results} || []) : ($result || []);
Branch: 1 branch
BranchTrueFalseTotal
ref $result eq 'HASH' ? : 1 0 1
Condition28%2/7
$result->{"endpoints"} or $result->{"results"} or []
l!l
10
$result->{"endpoints"} or $result->{"results"}
l!l&&r!l&&!r
100
$result or []
l!l
00
MC/DC0%0/2
$result->{"endpoints"} or $result->{"results"} or []
$result->{"endpoints"} $result->{"results"}
MC/DC0%0/1
$result or []
$result
Truth table33%1/3
A or B
A= $result->{"endpoints"}B= $result->{"results"}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $result
Aresult
11
00
28 1 return [ map { $self->_wrap($_) } @{$endpoints} ];
29 }
30  
31 1 ▶sub create {
Subroutine create: called CC=6 SCAR=19.9
Pod documented
32 1 my ($self, %params) = @_;
33 1 ▶ croak "endpoint_name required" unless $params{endpoint_name};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"endpoint_name"} 0 1 1
34 1 ▶ croak "min_load required" unless exists $params{min_load};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"min_load"} 0 1 1
35 1 ▶ croak "target_util required" unless exists $params{target_util};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"target_util"} 0 1 1
36  
37 1 my $result = $self->client->request_op('createEndpoint', body => \%params);
38 1 ▶ my $endpoint = ref $result eq 'HASH' ? ($result->{endpoint} || $result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
ref $result eq 'HASH' ? : 1 0 1
Condition33%1/3
$result->{"endpoint"} or $result
l!l&&r!l&&!r
100
MC/DC0%0/2
$result->{"endpoint"} or $result
$result->{"endpoint"} $result
Truth table33%1/3
A or B
A= $result->{"endpoint"}B= $result
ABresult
1X1
011
000
39 1 return $self->_wrap($endpoint);
40 }
41  
42 1 ▶sub delete {
Subroutine delete: called CC=2 SCAR=7.1
Pod documented
43 1 my ($self, $id) = @_;
44 1 ▶ croak "endpoint id required" unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 1 1
45 1 return $self->client->request_op('deleteEndpoint', path => { id => $id });
46 }
47  
48 1 ▶sub logs {
Subroutine logs: called CC=2 SCAR=7.0
Pod documented
49 1 my ($self, $endpoint_name, %params) = @_;
50 1 ▶ croak "endpoint_name required" unless $endpoint_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $endpoint_name 0 1 1
51 1 my %body = ( endpoint_name => $endpoint_name, %params );
52 1 return $self->client->request_op('getEndpointLogs', body => \%body);
53 }
54  
55 1 ▶sub workers {
Subroutine workers: called CC=2 SCAR=7.1
Pod documented
56 1 my ($self, $endpoint_id) = @_;
57 1 ▶ croak "endpoint id required" unless defined $endpoint_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $endpoint_id 0 1 1
58 1 return $self->client->request_op('getEndpointWorkers', body => { endpoint_id => $endpoint_id });
59 }
60  
61 10 1;
62  
63 __END__
« VastAI/API/Templates.pm ↑ Summary VastAI/API/Volumes.pm »