#!/usr/bin/perl
use strict;
require "getopts.pl";
&Getopts('v');
my $module = shift;
my $minimum = shift;
my($result, $version, $versionvar);
print "Checking installation status of Perl module $module...\n"
if $main::opt_v;
$versionvar = $module . "::VERSION";
$version = eval "require $module and defined \$$versionvar and \$$versionvar";
if ($@) {
print "Module $module is not installed.\n" if $main::opt_v;
exit 1;
}
if ($version >= $minimum) {
print "Module is installed and version number is okay\n" if $main::opt_v;
exit 0;
} else {
print "Module is installed but needs to be at least version $minimum (currently $version)\n"
if $main::opt_v;
# A major bug in perl makes this script return a 0 despite the "exit 1"
# below. It *does* execute it, but ignores the exit value completely!
# So to make it return a non-zero I make it bail out with an error when
# it tries to execute the following "require" statement.
# As a result this script must be run with 2>/dev/null.
require "foobarwibble";
exit 1;
}
syntax highlighted by Code2HTML, v. 0.9.1