File Coverage

blib/lib/MetaCPAN/API/Release.pm
Criterion Covered Total %
statement 23 27 85.1
branch 9 12 75.0
condition 2 6 33.3
subroutine 5 5 100.0
pod 1 1 100.0
total 40 51 78.4


line stmt bran cond sub pod time code
1 15     15   9222 use strict;
  15         31  
  15         492  
2 15     15   79 use warnings;
  15         27  
  15         702  
3             package MetaCPAN::API::Release;
4             # ABSTRACT: Distribution and releases information for MetaCPAN::API
5             $MetaCPAN::API::Release::VERSION = '0.44';
6 15     15   73 use Carp;
  15         24  
  15         910  
7 15     15   88 use Any::Moose 'Role';
  15         32  
  15         83  
8              
9             # /release/{distribution}
10             # /release/{author}/{release}
11             sub release {
12 4     4 1 2838     my $self = shift;
13 4 100       22     my %opts = @_ ? @_ : ();
14 4         7     my $url = '';
15 4         8     my $error = "Either provide 'distribution', or 'author' and 'release', " .
16                             "or 'search'";
17              
18 4 100       213     %opts or croak $error;
19              
20 3         7     my %extra_opts = ();
21              
22 3 100 66     28     if ( defined ( my $dist = $opts{'distribution'} ) ) {
    100          
    50          
23 1         3         $url = "release/$dist";
24                 } elsif (
25                     defined ( my $author = $opts{'author'} ) &&
26                     defined ( my $release = $opts{'release'} )
27                   ) {
28 1         7         $url = "release/$author/$release";
29                 } elsif ( defined ( my $search_opts = $opts{'search'} ) ) {
30 0 0 0     0         ref $search_opts && ref $search_opts eq 'HASH'
31                         or croak $error;
32              
33 0         0         %extra_opts = %{$search_opts};
  0         0  
34 0         0         $url = 'release/_search';
35                 } else {
36 1         98         croak $error;
37                 }
38              
39 2         14     return $self->fetch( $url, %extra_opts );
40             }
41              
42             1;
43              
44             __END__
45            
46             =pod
47            
48             =head1 NAME
49            
50             MetaCPAN::API::Release - Distribution and releases information for MetaCPAN::API
51            
52             =head1 VERSION
53            
54             version 0.44
55            
56             =head1 DESCRIPTION
57            
58             This role provides MetaCPAN::API with fetching information about distribution
59             and releases.
60            
61             =head1 METHODS
62            
63             =head2 release
64            
65             my $result = $mcpan->release( distribution => 'Moose' );
66            
67             # or
68             my $result = $mcpan->release( author => 'DOY', release => 'Moose-2.0001' );
69            
70             Searches MetaCPAN for a dist.
71            
72             You can do complex searches using 'search' parameter:
73            
74             # example lifted from MetaCPAN docs
75             my $result = $mcpan->release(
76             search => {
77             author => "OALDERS AND ",
78             filter => "status:latest",
79             fields => "name",
80             size => 1,
81             },
82             );
83            
84             =head1 AUTHOR
85            
86             Sawyer X <xsawyerx@cpan.org>
87            
88             =head1 COPYRIGHT AND LICENSE
89            
90             This software is copyright (c) 2011 by Sawyer X.
91            
92             This is free software; you can redistribute it and/or modify it under
93             the same terms as the Perl 5 programming language system itself.
94            
95             =cut
96