File Coverage

blib/lib/MetaCPAN/Client/Release.pm
Criterion Covered Total %
statement 16 30 53.3
branch 0 4 0.0
condition n/a
subroutine 6 9 66.6
pod 3 3 100.0
total 25 46 54.3


line stmt bran cond sub pod time code
1 21     21   874 use strict;
  21         52  
  21         833  
2 21     21   100 use warnings;
  21         45  
  21         1555  
3             package MetaCPAN::Client::Release;
4             # ABSTRACT: A Release data object
5             $MetaCPAN::Client::Release::VERSION = '2.040000';
6 21     21   610 use Moo;
  21         532  
  21         258  
7 21     21   8345 use Ref::Util qw< is_hashref >;
  21         77  
  21         1717  
8 21     21   168 use JSON::MaybeXS qw< decode_json >;
  21         36  
  21         10074  
9              
10             with 'MetaCPAN::Client::Role::Entity',
11             'MetaCPAN::Client::Role::HasUA';
12              
13             my %known_fields = (
14             scalar => [qw<
15             abstract
16             archive
17             author
18             authorized
19             checksum_md5
20             checksum_sha256
21             date
22             deprecated
23             distribution
24             download_url
25             first
26             id
27             maturity
28             main_module
29             name
30             status
31             version
32             version_numified
33             >],
34              
35             arrayref => [qw<
36             dependency
37             license
38             provides
39             >],
40              
41             hashref => [qw<
42             metadata
43             resources
44             stat
45             tests
46             >],
47             );
48              
49             my @known_fields =
50             map { @{ $known_fields{$_} } } qw< scalar arrayref hashref >;
51              
52             foreach my $field (@known_fields) {
53             has $field => (
54             is => 'ro',
55             lazy => 1,
56             default => sub {
57             my $self = shift;
58             return $self->data->{$field};
59             },
60             );
61             }
62              
63 64     64   166 sub _known_fields { return \%known_fields }
64              
65             sub changes {
66 0     0 1   my $self = shift;
67 0           my $url = sprintf "https://fastapi.metacpan.org/changes/%s/%s", $self->author, $self->name;
68 0           my $res = $self->ua->get($url);
69 0 0         return unless is_hashref($res);
70 0           my $content = decode_json $res->{'content'};
71 0           return $content->{'content'};
72             }
73              
74             sub metacpan_url {
75 0     0 1   my $self = shift;
76 0           sprintf( "https://metacpan.org/release/%s/%s", $self->author, $self->name )
77             }
78              
79             sub contributors {
80 0     0 1   my $self = shift;
81 0           my $url = sprintf( "https://fastapi.metacpan.org/release/contributors/%s/%s", $self->author, $self->name );
82 0           my $res = $self->ua->get($url);
83 0 0         return unless is_hashref($res);
84 0           my $content = decode_json $res->{'content'};
85 0           return $content->{'contributors'};
86             }
87              
88             1;
89              
90             __END__