Create a gist now

Instantly share code, notes, and snippets.

@genehack /moose-dep.pl Secret
Created May 20, 2012

What would you like to do?
find all things that depend on moose
#! perl
use strict;
use warnings;
use feature 'say';
use DDP;
use HTTP::Tiny;
use JSON;
use LWP::UserAgent;
my( $data , $counter ) = find_all_deps( 'Moose' , 0 , 1 , {} );
my @deps = sort keys %$data;
open( my $OUT , '>' , 'all_moose_deps' );
foreach ( @deps ) {
say $_;
say $OUT $_
}
close( $OUT );
say "TOTAL: " . scalar @deps;
sub find_all_deps {
my( $dist , $counter , $depth , $data ) = @_;
my @deps = deps_for_dist( $dist );
sleep 1;
foreach my $dep ( @deps ) {
printf "[%3d] #%5d -> %s\n" , $depth , $counter++ , $dep;
next if $data->{$dep};
$data->{$dep}++;
( $data , $counter ) = find_all_deps( $dep , $counter , $depth+1 , $data );
}
return( $data , $counter );
}
sub deps_for_dist {
my $dist = shift;
my $res = `curl -s -XPOST api.metacpan.org/v0/release/_search -d '{
"query": {
"match_all": {}
},
"size": 5000,
"fields": [ "distribution" ],
"filter": {
"and": [
{ "term": { "release.dependency.module": "$dist" } },
{ "term": {"release.maturity": "released"} },
{ "term": {"release.status": "latest"} }
]
}
}'`;
my $data = from_json $res;
my @return;
foreach ( @{ $data->{hits}{hits} }) {
my $dist = $_->{fields}{distribution};
$dist =~ s/-/::/g;
push @return , $dist;
}
return @return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment