App-pmodinfo
view release on metacpan or search on metacpan
lib/App/pmodinfo.pm view on Meta::CPAN
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} } ) {
next unless $arg =~ /::$/;
next unless $mod =~ /^$arg/;
push( @nargv, $mod );
}
}
$self->{argv} = \@nargv;
}
sub check_installed_modules_for_update {
my $self = shift;
my @need_update;
$self->ns_argv;
foreach my $module ( scalar( @{ $self->{argv} } ) ? @{ $self->{argv} } : $self->installed_modules ) {
my ( $install, $meta ) = $self->check_module( $module, 0 );
next unless $install and defined($meta);
my $local_version = $meta->version;
my $cpan_version = $self->get_last_version_from_cpan($module);
next unless $cpan_version and $local_version;
next if $cpan_version eq $local_version;
print "$module local version: $local_version, last version in cpan: $cpan_version\n";
push( @need_update, $module );
}
if ( scalar(@need_update) ) {
my $ans = lc $self->prompt( "Do you need to update this modules now ? (y/n)", "n" );
$self->update_modules(@need_update) if $ans eq 'y';
}
else {
print "already up to date.";
}
( run in 0.486 second using v1.01-cache-2.11-cpan-39bf76dae61 )