App-pmodinfo
view release on metacpan or search on metacpan
lib/App/pmodinfo.pm view on Meta::CPAN
package App::pmodinfo;
use strict;
use warnings;
use Getopt::Long ();
use File::stat;
use DateTime;
use Config;
use Parse::CPAN::Meta;
use LWP::Simple;
use ExtUtils::Installed;
use File::Which qw(which);
our $VERSION = '0.10'; # VERSION
sub new {
my $class = shift;
bless {
author => 0,
full => 0,
hash => 0,
@_
}, $class;
}
sub parse_options {
my $self = shift;
$self->{argv} = \@ARGV;
Getopt::Long::Configure("bundling");
Getopt::Long::GetOptions(
'v|version!' => sub { $self->show_version },
'f|full!' => sub { $self->{full} = 1 },
'h|hash!' => sub { $self->{hash} = 1 },
'c|cpan!' => sub { $self->{cpan} = 1 },
'l|local-modules!' => sub { $self->show_installed_modules },
'u|check-updates' => sub { $self->check_installed_modules_for_update },
);
}
sub show_version {
my $self = shift;
no strict; # Dist::Zilla, VERSION.
print "pmodinfo version $VERSION\n";
exit 0;
}
sub show_help {
my $self = shift;
if ( $_[0] ) {
die <<USAGE;
Usage: pmodinfo Module [...]
Try `pmodinfo --help` for more options.
USAGE
}
print <<HELP;
Usage: pmodinfo [options] [Module] [...]
-v --version Display software version
-f --full Turns on the most output
-h --hash Show module and version in a hash.
-l,--local-modules Display all local modules
-u,--check-updates Check updates, compare your local version to cpan.
-c,--cpan Show the last version of module in cpan.
HELP
exit 0;
}
sub print_block {
my $self = shift;
my ( $description, $data, @check ) = @_;
map { print " $description: $data\n" if $_ } @check;
}
sub format_date {
my ( $self, $epoch ) = @_;
return '' unless $epoch;
my $dt = DateTime->from_epoch( epoch => $epoch );
return join( ' ', $dt->ymd, $dt->hms );
}
sub run {
my $self = shift;
$self->show_help unless @{ $self->{argv} };
$self->ns_argv;
print "{\n" if $self->{hash};
for my $module ( @{ $self->{argv} } ) {
$self->{hash}
? $self->show_modules_hash($module)
: $self->show_modules($module);
}
print "};\n" if $self->{hash};
}
sub show_modules_hash {
my ( $self, $module ) = @_;
my ( $install, $meta ) = $self->check_module( $module, 0 );
return unless $meta and $meta->version;
my $version = $meta->version;
print "\t'$module' => $version,\n" if $install;
}
sub cpanpage {
my ( $self, $module ) = @_;
$module =~ s/::/-/g;
return "http://search.cpan.org/dist/$module";
}
sub update_modules {
my ( $self, @modules ) = @_;
my $cpan_util;
$cpan_util = which('cpanm') or which('cpan') or exit -1;
system( $cpan_util, @modules );
exit 0;
}
sub ns_argv {
my $self = shift;
my @nargv;
my @installed = $self->installed_modules;
foreach my $arg ( @{ $self->{argv} } ) {
if ($arg =~ /::$/) {
my $mod = $arg;
$mod =~ s/::$//;
push( @nargv, $mod);
} else {
push( @nargv, $arg );
}
}
foreach my $mod (@installed) {
foreach my $arg ( @{ $self->{argv} } ) {
( run in 1.089 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )