Created
December 4, 2018 19:36
-
-
Save autarch/a8d6fad13f267c1f89427c86ba086ecb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use v5.24; | |
use strict; | |
use warnings; | |
use autodie qw( :all ); | |
use feature 'postderef', 'signatures'; | |
package T; | |
use Moo; | |
no warnings 'experimental::postderef', 'experimental::signatures'; | |
use Forest::Tree; | |
use Forest::Tree::Writer::ASCIIWithBranches; | |
use MetaCPAN::API; | |
use Module::CoreList; | |
has _mcpan => ( | |
is => 'ro', | |
lazy => 1, | |
default => sub { MetaCPAN::API->new }, | |
); | |
sub run ( $self, $for ) { | |
my $tree = Forest::Tree->new( node => $for ); | |
$self->_add_prereqs_to_tree( $tree, $for ); | |
print Forest::Tree::Writer::ASCIIWithBranches->new( tree => $tree ) | |
->as_string; | |
print "\n"; | |
} | |
sub _add_prereqs_to_tree ( $self, $tree, $distro ) { | |
for my $dep ( $self->_deps_for($distro) ) { | |
warn "$distro -> $dep\n"; | |
my $child = Forest::Tree->new( node => $dep ); | |
$tree->add_child($child); | |
$self->_add_prereqs_to_tree( $child, $dep ); | |
} | |
return; | |
} | |
sub _deps_for ( $self, $distro ) { | |
my %deps; | |
my $meta = $self->_mcpan->release( distribution => $distro ); | |
for my $module ( | |
map { $_->{module} } | |
grep { $_->{phase} eq 'runtime' && $_->{relationship} eq 'requires' } | |
$meta->{dependency}->@* | |
) { | |
next if $module eq 'perl'; | |
next if Module::CoreList::is_core($module); | |
my $module = $self->_mcpan->module($module); | |
$deps{ $module->{distribution} } = 1; | |
} | |
return sort keys %deps; | |
} | |
package main; | |
T->new->run(shift); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment