Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
use strict;
use warnings;
use HTTP::Tiny;
use JSON;
use App::cpanminus::fatscript;
my $dist = shift;
my $dep = shift;
my $version = shift;
my $cpanm = App::cpanminus::script->new;
my @filters = $cpanm->version_to_query($dep, $version);
my $query = {
sort => [
{ "version" => "desc" }
],
query => {
filtered => {
query => {
match_all => {}
},
filter => {
and => [
{
term => {
distribution => $dist,
}
},
{
nested => {
path => 'dependency',
filter => {
and => [
{ term => { 'dependency.module' => $dep } },
@filters,
]
}
}
}
]
}
}
}
};
my $query_json = encode_json($query);
$query_json =~ s/"module\.version/"dependency.version/g; # :P
my $http = HTTP::Tiny->new;
my $resp = $http->get("http://api.metacpan.org/v0/release/_search?source=$query_json");
my $data = decode_json($resp->{content});
foreach my $hit (@{$data->{hits}->{hits}}) {
print $hit->{_source}->{name}, "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.