Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created March 4, 2013 22:24
Show Gist options
  • Select an option

  • Save tobyink/5086241 to your computer and use it in GitHub Desktop.

Select an option

Save tobyink/5086241 to your computer and use it in GitHub Desktop.
MetaCPAN query to find all my distributions which depend on X, where X is some module I've decided to stop using.
#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
use HTTP::Tiny;
use JSON;
my @fields = qw< distribution version date >;
my ($module, $author) = @ARGV;
$module or die "usage: $0 MODULE [AUTHOR]\n";
my $query = {
size => 5000,
fields => \@fields,
query => { match_all => {} },
filter => {
and => [
{ term => { "release.dependency.module" => $module } },
{ term => { "release.status" => "latest"} },
]
}
};
push @{ $query->{filter}{and} }, { term => { "release.author" => $author } }
if $author;
my $response = "HTTP::Tiny"->new->post(
"http://api.metacpan.org/v0/release/_search" => {
content => to_json($query),
headers => {
"Content-Type" => "application/json",
},
},
);
my $result = from_json($response->{content});
for my $dist (@{ $result->{hits}{hits} }) {
printf("%s\t%s\t%s\n", map $dist->{fields}{$_}, @fields);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment