Skip to content

Instantly share code, notes, and snippets.

@und3f
Created August 9, 2011 22:10
Show Gist options
  • Save und3f/1135335 to your computer and use it in GitHub Desktop.
Save und3f/1135335 to your computer and use it in GitHub Desktop.
Find who depends on authors modules
#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
my $METACPAN = 'http://api.metacpan.org/v0';
my $author = shift @ARGV or die "usage: $0 <author>\n";
my $ua = LWP::UserAgent->new;
my $response = $ua->post(
"$METACPAN/release/_search",
Content => encode_json {
query => {match_all => {}},
filter => {term => {author => uc $author}}
}
);
die $response->status_line unless $response->is_success;
my $res = decode_json $response->decoded_content;
my %author_modules;
foreach my $module (@{$res->{hits}{hits}}) {
my $distr = $module->{_source}{distribution};
next if $author_modules{$distr}++ > 1;
my $modules = find_who_depends($distr);
say "$distr:";
if (@$modules) {
say "\thttp://metacpan.org/release/$_->{_source}{distribution}"
for @$modules;
} else {
say "\t<empty>";
}
}
sub find_who_depends {
my $module = shift;
my $response = $ua->post(
"$METACPAN/release/_search",
Content => encode_json {
query => {match_all => {}},
filter => {term => {'release.dependency.module' => [$module]}}
}
);
die $response->status_line unless $response->is_success;
my $res = decode_json $response->decoded_content;
my %modules;
foreach my $module (@{$res->{hits}{hits}}) {
$modules{$module->{_source}{distribution}} = $module;
}
return [values %modules];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment