Revision 657 (by ahitrov, 2017/06/22 14:16:24) Shortcut for Perl Check Module task. Using PERL_CHECK_MODE=pass during 'make install' bypasses installation for all globally installed modules. Libnet now doesn't ask about tests

#!/usr/bin/perl

use strict;

my ($module, $version, $mode) = @ARGV;
$module =~ s/-/::/g;
my $installed;

unless ($module && $version) {
	print "export PERL_CHECKED=cancel";
	exit;
}

eval "require $module;";
if ($@) {
	print "export PERL_CHECKED=install";
	exit;
}


my @parts = split /\./, $module->VERSION();
$installed->{version} = join(".", $parts[0], join("", @parts[1 .. $#parts]) || ());
(my $path=$module)    =~ s/::/\//g;
$installed->{path}    = $INC{$path.".pm"};

if ($installed->{version} >= $version || $mode eq 'pass') {
	unless ($ENV{DRY_RUN}||'' eq 'yes') {
		print STDERR "##############################################################################\n";
		print STDERR "# Found installed module: $module\n";
		print STDERR "# Version:  $installed->{version}\n";
		print STDERR "# Location: $installed->{path}\n";
		print STDERR "#\n";
		print STDERR "# Skipped version:  $version\n";
		print STDERR "##############################################################################\n";
		sleep 2;
	}
	print "export PERL_CHECKED=skip";
	exit;
}

print STDERR "##############################################################################\n";
print STDERR "# Found installed module: $module\n";
print STDERR "# Version:  $installed->{version}\n";
print STDERR "# Location: $installed->{path}\n";
print STDERR "#\n";
print STDERR "# Would you like continue to install version: $version ?\n";
print STDERR "##############################################################################\n";

my $a;
while (1) {
	print STDERR "[I]nstall, [S]kip, [C]ancel ? ";
	$a = lc(scalar(<STDIN>));
	chomp $a;
	last if $a eq 'i' || $a eq 's' || $a eq 'c';
}
print "export PERL_CHECKED=install" if $a eq 'i';
print "export PERL_CHECKED=skip"    if $a eq 's';
print "export PERL_CHECKED=cancel"  if $a eq 'c';