File Coverage

blib/lib/MetaCPAN/API/File.pm
Criterion Covered Total %
statement 28 28 100.0
branch 8 8 100.0
condition 4 5 80.0
subroutine 6 6 100.0
pod 1 1 100.0
total 47 48 97.9


line stmt bran cond sub pod time code
1 17     17   161582 use strict;
  17         36  
  17         639  
2 17     17   81 use warnings;
  17         91  
  17         1418  
3             package MetaCPAN::API::File;
4              
5             our $VERSION = '0.52';
6              
7 17     17   163 use Carp;
  17         50  
  17         1305  
8 17     17   493 use Moo::Role;
  17         24795  
  17         116  
9 17     17   9311 use namespace::autoclean;
  17         18590  
  17         165  
10              
11             # /module/{module}
12             # /file/{author}/{release}/{path}
13             # /file/{author}/{release}
14             # /file/{id}
15             sub file {
16 6     6 1 5246 my $self = shift;
17 6         18 my $url = '';
18 6         14 my $error = "Either provide a module name, 'id', or 'author and 'release' and an optional 'path'";
19              
20 6 100       28 if ( @_ == 1 ) {
    100          
21 1         3 $url = 'module/' . shift;
22             } elsif ( @_ ) {
23 4         21 my %opts = @_;
24              
25 4 100 66     34 if ( defined ( my $id = $opts{'id'} ) ) {
    100          
26 1         4 $url = "file/$id";
27             } elsif (
28             defined ( my $author = $opts{'author'} ) &&
29             defined ( my $release = $opts{'release'} )
30             ) {
31 2   100     14 my $path = $opts{'path'} || '';
32 2         9 $url = "file/$author/$release/$path";
33             } else {
34 1         112 croak $error;
35             }
36             } else {
37 1         173 croak $error;
38             }
39              
40              
41 4         26 return $self->fetch( $url );
42             }
43              
44             1;
45              
46             __END__