VastAI/API/SSHKeys.pm

filter: Statementstmt 100% 37 / 37 Branchbran 50.0% 7 / 14 Conditioncond 30.7% 4 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 72.6% 61 / 84 CC 13 SCAR 14.6
CC
13
Cov
75%
list
6.6
update
5.9
create
4.6
CRAP 4.3
« VastAI/API/Invoices.pm ↑ Summary VastAI/API/Templates.pm »
1 package WWW::VastAI::API::SSHKeys;
2 10 our $VERSION = '0.001';
3 # ABSTRACT: Account SSH key 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::SSHKey;
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 3 ▶sub _wrap {
Subroutine _wrap: called CC=1 SCAR=0.0
17 3 my ($self, $data) = @_;
18 3 return WWW::VastAI::SSHKey->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('listSSHKeys');
27 1 ▶ my $keys = ref $result eq 'HASH' ? ($result->{ssh_keys} || $result->{results} || []) : ($result || []);
Branch: 1 branch
BranchTrueFalseTotal
ref $result eq 'HASH' ? : 1 0 1
Condition28%2/7
$result->{"ssh_keys"} or $result->{"results"} or []
l!l
10
$result->{"ssh_keys"} or $result->{"results"}
l!l&&r!l&&!r
100
$result or []
l!l
00
MC/DC0%0/2
$result->{"ssh_keys"} or $result->{"results"} or []
$result->{"ssh_keys"} $result->{"results"}
MC/DC0%0/1
$result or []
$result
Truth table33%1/3
A or B
A= $result->{"ssh_keys"}B= $result->{"results"}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $result
Aresult
11
00
28 1 return [ map { $self->_wrap($_) } @{$keys} ];
29 }
30  
31 1 ▶sub create {
Subroutine create: called CC=4 SCAR=15.2
Pod documented
32 1 my ($self, $ssh_key) = @_;
33 1 ▶ croak "ssh key required" unless $ssh_key;
Branch: 1 branch
BranchTrueFalseTotal
unless $ssh_key 0 1 1
34 1 my $result = $self->client->request_op('createSSHKey', body => { ssh_key => $ssh_key });
35 1 ▶ my $key = ref $result eq 'HASH' ? ($result->{ssh_key} || $result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
ref $result eq 'HASH' ? : 1 0 1
Condition33%1/3
$result->{"ssh_key"} or $result
l!l&&r!l&&!r
100
MC/DC0%0/2
$result->{"ssh_key"} or $result
$result->{"ssh_key"} $result
Truth table33%1/3
A or B
A= $result->{"ssh_key"}B= $result
ABresult
1X1
011
000
36 1 return $self->_wrap($key);
37 }
38  
39 1 ▶sub update {
Subroutine update: called CC=5 SCAR=17.8
Pod documented
40 1 my ($self, $id, $ssh_key) = @_;
41 1 ▶ croak "ssh key id required" unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 1 1
42 1 ▶ croak "ssh key required" unless $ssh_key;
Branch: 1 branch
BranchTrueFalseTotal
unless $ssh_key 0 1 1
43  
44 1 my $result = $self->client->request_op(
45 'updateSSHKey',
46 path => { id => $id },
47 body => { ssh_key => $ssh_key },
48 );
49  
50 1 ▶ my $key = ref $result eq 'HASH' ? ($result->{ssh_key} || $result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
ref $result eq 'HASH' ? : 1 0 1
Condition33%1/3
$result->{"ssh_key"} or $result
l!l&&r!l&&!r
100
MC/DC0%0/2
$result->{"ssh_key"} or $result
$result->{"ssh_key"} $result
Truth table33%1/3
A or B
A= $result->{"ssh_key"}B= $result
ABresult
1X1
011
000
51 1 return $self->_wrap($key);
52 }
53  
54 1 ▶sub delete {
Subroutine delete: called CC=2 SCAR=7.1
Pod documented
55 1 my ($self, $id) = @_;
56 1 ▶ croak "ssh key id required" unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 1 1
57 1 return $self->client->request_op('deleteSSHKey', path => { id => $id });
58 }
59  
60 10 1;
61  
62 __END__
« VastAI/API/Invoices.pm ↑ Summary VastAI/API/Templates.pm »