Skip to content

Instantly share code, notes, and snippets.

@perlancar
Created November 4, 2016 16:13
Show Gist options
  • Save perlancar/56169c041c48fc0ad80a958f745eb5e5 to your computer and use it in GitHub Desktop.
Save perlancar/56169c041c48fc0ad80a958f745eb5e5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use HTTP::Tiny;
use JSON::PP ();
use DDP;
my $name = shift || "cpm";
my $query = {
"fields" => [
"author",
"binary",
"date",
"directory",
"distribution",
"documentation",
"indexed",
"maturity",
"name",
"path",
"release",
"version",
"version_numified"
],
"query" => {
"bool" => {
"must" => [
{ "term" => { "authorized" => "true" } },
{ "term" => { "indexed" => "true" } },
{ "term" => { "mime" => "text/x-script.perl" } },
{ "term" => { "name" => $name } },
{ "term" => { "status" => "latest" } },
{ "bool" => {
"should" => [
{ "term" => { "path" => $name } },
{ "term" => { "path" => "bin/$name" } },
{ "term" => { "path" => "script/$name" } },
{ "term" => { "path" => "scripts/$name" } },
],
},
},
],
},
}
};
my $res = HTTP::Tiny->new->get('http://api.metacpan.org/v0/file/_search?pretty=true', {
content => JSON::PP::encode_json($query),
});
if ($res->{success}) {
my $hash = JSON::PP::decode_json($res->{content});
p $hash->{hits}{hits};
} else {
p $res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment