Created
November 4, 2016 16:13
-
-
Save perlancar/56169c041c48fc0ad80a958f745eb5e5 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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