File Coverage

blib/lib/MetaCPAN/API/Release.pm
Criterion Covered Total %
statement 26 30 86.6
branch 9 12 75.0
condition 2 6 33.3
subroutine 6 6 100.0
pod 1 1 100.0
total 44 55 80.0


line stmt bran cond sub pod time code
1 17     17   237452 use strict;
  17         42  
  17         724  
2 17     17   90 use warnings;
  17         32  
  17         1370  
3             package MetaCPAN::API::Release;
4              
5             our $VERSION = '0.52';
6              
7 17     17   130 use Carp;
  17         228  
  17         1465  
8 17     17   763 use Moo::Role;
  17         19662  
  17         212  
9 17     17   10012 use namespace::autoclean;
  17         24218  
  17         158  
10              
11             # /release/{distribution}
12             # /release/{author}/{release}
13             sub release {
14 4     4 1 4066 my $self = shift;
15 4 100       20 my %opts = @_ ? @_ : ();
16 4         7 my $url = '';
17 4         7 my $error = "Either provide 'distribution', or 'author' and 'release', " .
18             "or 'search'";
19              
20 4 100       152 %opts or croak $error;
21              
22 3         6 my %extra_opts = ();
23              
24 3 100 66     21 if ( defined ( my $dist = $opts{'distribution'} ) ) {
    100          
    50          
25 1         2 $url = "release/$dist";
26             } elsif (
27             defined ( my $author = $opts{'author'} ) &&
28             defined ( my $release = $opts{'release'} )
29             ) {
30 1         3 $url = "release/$author/$release";
31             } elsif ( defined ( my $search_opts = $opts{'search'} ) ) {
32 0 0 0     0 croak "search option must by a hashref"
33             unless ref $search_opts && ref $search_opts eq 'HASH';
34              
35 0         0 %extra_opts = %{$search_opts};
  0         0  
36 0         0 $url = 'release/_search';
37             } else {
38 1         79 croak $error;
39             }
40              
41 2         13 return $self->fetch( $url, %extra_opts );
42             }
43              
44             1;
45              
46             __END__