Created
June 28, 2016 05:27
-
-
Save motemen/8278f616102a707767bc26afc5b4ab07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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