App-pmdeps
view release on metacpan or search on metacpan
lib/App/pmdeps.pm view on Meta::CPAN
package App::pmdeps;
use strict;
use warnings;
use utf8;
use Carp;
use File::Spec::Functions qw/catfile rel2abs/;
use Furl;
use Getopt::Long qw/:config posix_default no_ignore_case bundling auto_help/;
use JSON;
use Module::CoreList;
use Term::ANSIColor qw/colored/;
our $VERSION = "0.02";
$ENV{ANSI_COLORS_DISABLED} = 1 if $^O eq 'MSWin32';
use constant METACPAN_API_URL => 'http://api.metacpan.org/v0/release/_search';
sub new {
my ($class) = @_;
bless { timeout => 10, }, $class;
}
sub run {
my ( $self, @args ) = @_;
local @ARGV = @args;
GetOptions(
't|timeout=i' => \$self->{timeout},
'p|perl-version=f' => \$self->{perl_version},
'l|local=s', => \$self->{local},
'without-phase=s@' => \$self->{without_phase},
'without-type=s@' => \$self->{without_type},
'h|help!' => \$self->{usage},
'v|version!' => \$self->{version},
) or $self->show_usage;
$self->show_version if $self->{version};
$self->show_usage if $self->{usage};
if ($self->{without_phase}) {
@{$self->{without_phase}} = split( /,/, join(',', @{$self->{without_phase}}) );
}
if ($self->{without_type}) {
@{$self->{without_type}} = split( /,/, join(',', @{$self->{without_type}}) );
}
$self->show_short_usage unless ( @ARGV || $self->{local} );
$self->{perl_version} ||= $];
$self->show_dependencies(@ARGV);
}
sub show_dependencies {
my ( $self, @args ) = @_;
my $deps;
if ( $self->{local} ) {
$deps = $self->_fetch_deps_from_metadata( $self->{local} );
}
else {
$deps = $self->_fetch_deps_from_metacpan( { name => $args[0], version => $args[1] } );
}
my ( $cores, $non_cores ) = $self->_divide_core_or_not($deps);
$self->_spew( $cores, $non_cores );
}
sub _spew {
my ( $self, $cores, $non_cores ) = @_;
my $core_index = $self->_make_index( scalar(@$cores) );
my $non_core_index = $self->_make_index( scalar(@$non_cores), 'non-' );
print "Target: perl-$self->{perl_version}\n";
print colored['green'], "$core_index";
print "\n";
print "\t$_\n" for (@$cores);
print colored['yellow'], "$non_core_index";
print "\n";
print "\t$_\n" for (@$non_cores);
}
sub _make_index {
my ( $self, $num, $optional ) = @_;
$optional ||= '';
( run in 2.146 seconds using v1.01-cache-2.11-cpan-302cb4679cc )