tokuhirom's blog

How can I list CPAN reverse dependencies from metacpan?

#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.010000;
use autodie;
use Furl;
use JSON::PP;
use Pod::Usage;

my $module = shift @ARGV || pod2usage();

my $res = Furl->new()->post(
    'http://api.metacpan.org/v0/release/_search',
    ['Content-Type' => 'application/json'],
    sprintf(<<'...', $module));
  {
  "query": {
    "match_all": {}
  },
  "size": 5000,
  "fields": [ "distribution" ],
  "filter": {
    "and": [
      { "term": { "release.dependency.module": "%s" } },
      { "term": {"release.maturity": "released"} },
      { "term": {"release.status": "latest"} }
    ]
  }
}
...
die $res->status_code unless $res->is_success;

for (@{decode_json($res->content)->{hits}->{hits}}) {
    print "$_->{fields}->{distribution}\n";
}

__END__

=head1 SYNOPSIS

    % cpan-reverse-deps Text::Xslate
Created: 2013-03-25T04:52:52Z
Updated: 2013-03-25T04:52:52Z
comments powered by Disqus