File Coverage

blib/lib/MetaCPAN/API/Distribution.pm
Criterion Covered Total %
statement 31 31 100.0
branch 9 10 90.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 1 1 100.0
total 48 51 94.1


line stmt bran cond sub pod time code
1 17     17   153515 use strict;
  17         35  
  17         628  
2 17     17   81 use warnings;
  17         40  
  17         1377  
3             package MetaCPAN::API::Distribution;
4              
5             our $VERSION = '0.52';
6              
7 17     17   101 use Carp;
  17         31  
  17         1047  
8 17     17   568 use Moo::Role;
  17         12683  
  17         106  
9 17     17   9408 use namespace::autoclean;
  17         18224  
  17         178  
10              
11             # /distribution/{distribution}
12             sub distribution {
13 5     5 1 4575 my $self = shift;
14 5         15 my $url = '';
15 5         10 my $error = "Either provide a distribution or 'search'";
16              
17 5         15 my %extra_opts = ();
18              
19 5 100       27 if ( @_ == 1 ) {
    100          
20 1         3 $url = 'distribution/' . shift;
21             } elsif ( @_ ) {
22 3         14 my %opts = @_;
23              
24 3 100       18 if ( defined ( my $dist = $opts{'distribution'} ) ) {
    100          
25 1         5 $url = "distribution/$dist";
26             } elsif ( defined ( my $search_opts = $opts{'search'} ) ) {
27 1 50 33     20 croak $error
28             unless ref $search_opts && ref $search_opts eq 'HASH';
29              
30 1         3 %extra_opts = %{$search_opts};
  1         6  
31 1         5 $url = 'distribution/_search';
32             } else {
33 1         172 croak $error;
34             }
35             } else {
36 1         168 croak $error;
37             }
38              
39 3         22 return $self->fetch( $url, %extra_opts );
40             }
41              
42             1;
43              
44             __END__