File Coverage

blib/lib/WWW/VastAI/API/Offers.pm
Criterion Covered Total %
statement 17 17 100.0
branch 1 2 50.0
condition 1 4 25.0
subroutine 5 5 100.0
pod 1 1 100.0
total 25 29 86.2


line stmt bran cond sub pod time code
1             package WWW::VastAI::API::Offers;
2             our $VERSION = '0.001';
3             # ABSTRACT: Marketplace offer search for Vast.ai
4              
5 10     10   79 use Moo;
  10         21  
  10         78  
6 10     10   9612 use WWW::VastAI::Offer;
  10         71  
  10         369  
7 10     10   66 use namespace::clean;
  10         20  
  10         66  
8              
9             has client => (
10             is => 'ro',
11             required => 1,
12             weak_ref => 1,
13             );
14              
15             sub _wrap {
16 1     1   2 my ($self, $data) = @_;
17 1         13 return WWW::VastAI::Offer->new(
18             client => $self->client,
19             data => $data,
20             );
21             }
22              
23             sub search {
24 1     1 1 938 my ($self, %filters) = @_;
25              
26 1         9 my $result = $self->client->request_op('searchOffers', body => \%filters);
27 1 50 0     4 my $offers = ref $result eq 'HASH' ? ($result->{offers} || $result->{results} || []) : ($result || []);
      50        
28 1         2 return [ map { $self->_wrap($_) } @{$offers} ];
  1         4  
  1         2  
29             }
30              
31             1;
32              
33             __END__