tokuhirom's Blog

How can I get a latest release information from metacpan API?

for id:punitan

#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use 5.010000;

use JSON;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new();

my $res = $ua->post(
    'http://api.metacpan.org/v0/release/_search',
    Content => encode_json(
        {   
            size => 20,
            from => 0,
            sort => [ { 'date' => { order => "desc" } } ],
            query  => { match_all => {} },
            fields => [
                qw( author version distribution download_url date)
            ],
        }
    )
);
$res->is_success or die "Fail to get the latest modules information: " . $res->status_line;
my $dat = JSON::decode_json($res->decoded_content);
for my $row (map { $_->{fields} } @{$dat->{hits}->{hits}}) {
    say "$row->{distribution} $row->{version} by $row->{author} - $row->{download_url}";
}