Skip to content

Commit

Permalink
Release: support 'changes' method (GH#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Mar 24, 2017
1 parent 9db93cc commit 9f7e257
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions examples/changes.pl
@@ -0,0 +1,9 @@
use strict;
use warnings;
use MetaCPAN::Client;

my $dist = shift || 'Moose';

my $mcpan = MetaCPAN::Client->new();
my $rel = $mcpan->release($dist);
print $rel->changes;
18 changes: 17 additions & 1 deletion lib/MetaCPAN/Client/Release.pm
Expand Up @@ -4,8 +4,11 @@ package MetaCPAN::Client::Release;
# ABSTRACT: A Release data object

use Moo;
use Ref::Util qw< is_hashref >;
use JSON::MaybeXS qw< decode_json >;

with 'MetaCPAN::Client::Role::Entity';
with 'MetaCPAN::Client::Role::Entity',
'MetaCPAN::Client::Role::HasUA';

my %known_fields = (
scalar => [qw<
Expand Down Expand Up @@ -55,6 +58,15 @@ foreach my $field (@known_fields) {

sub _known_fields { return \%known_fields }

sub changes {
my $self = shift;
my $url = sprintf "https://fastapi.metacpan.org/changes/%s/%s", $self->author, $self->name;
my $res = $self->ua->get($url);
return unless is_hashref($res);
my $content = decode_json $res->{'content'};
return $content->{'content'};
}

sub metacpan_url {
my $self = shift;
sprintf( "https://metacpan.org/release/%s/%s", $self->author, $self->name )
Expand Down Expand Up @@ -207,6 +219,10 @@ the count of that particular result on CPAN Testers for this release.
=head1 METHODS
=head2 changes
Returns the Changes text for the release.
=head2 metacpan_url
Returns a link to the release page on MetaCPAN.

0 comments on commit 9f7e257

Please sign in to comment.