Skip to content

Commit

Permalink
added support for reverse dependencies search (returns array of dist.…
Browse files Browse the repository at this point in the history
… objects)
  • Loading branch information
mickeyn committed Apr 21, 2014
1 parent 4b87553 commit 560005f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/MetaCPAN/Client.pm
Expand Up @@ -109,6 +109,15 @@ sub release {
return $self->_get_or_search( 'release', $arg, $params );
}

sub reverse_dependencies {
my $self = shift;
my $dist = shift;

$dist =~ s/::/-/g;

return $self->_reverse_deps($dist);
}

sub pod {}

###
Expand Down Expand Up @@ -170,6 +179,26 @@ sub _get_or_search {
croak "$type: invalid args (takes scalar value or search parameters hashref)";
}

sub _reverse_deps {
my $self = shift;
my $dist = shift;

my $res = $self->fetch(
'/search/reverse_dependencies/'.$dist,
{
query => { match_all => {} },
filter => { term => { 'release.status' => 'latest' } },
size => 5000,
}
);

return +[
map { MetaCPAN::Client::Distribution->new_from_request($_->{'_source'}) }
@{ $res->{'hits'}{'hits'} }
];
}


1;

__END__
Expand Down Expand Up @@ -280,6 +309,13 @@ Return a L<MetaCPAN::Client::Release> object on a simple search (release name),
or a L<MetaCPAN::Client::ResultSet> object propagated with
L<MetaCPAN::Client::Release> objects on a complex (search spec based) search.
=head2 reverse_dependencies
my $deps = $mcpan->reverse_dependencies('ElasticSearch');
Return an array (ref) of L<MetaCPAN::Client::Distribution> matching all
distributions that are dependent on a given module.
=head2 pod
Not implemented yet.
Expand Down

0 comments on commit 560005f

Please sign in to comment.