Hi fellow monks,
I want to monitor that a list of
CPAN modules are installed and
correct versioned on a number of computers. (I intend to to run the
script using the excellent GPL'ed tool
cfengine www.cfengine.org,
but that beside the point.)
Several modules, including CPAN.pm, have a
non-numeric version number
(i.e. "$VERSION = '1.59_54';"). Without knowing how future versions
of modules evolve, how would you create a
general version
comparison that checks the desired modules are installed in (at least) the
version you want?
Sample script:
#!/usr/bin/perl
use strict;
use warnings;
use ExtUtils::Installed;
use constant TRUE => 0;
use constant FALSE => -1;
use constant DEBUG => 1;
my $params = shift; # cfengine sends params as single string
my ($modulename, $requiredversion) = split(' ', $params);
die "missing modulename!" unless $modulename;
my $instmod = ExtUtils::Installed->new();
foreach my $module ((grep /^$modulename$/, $instmod->modules())) {
my $version = $instmod->version($module);
if ($version >= $requiredversion){
print STDERR "$modulename installed:$version required:$requiredve
+rsion - ok\n" if DEBUG;
exit(TRUE); # installed and in correct version
} else {
print STDERR "$modulename installed:$version required:$requiredve
+rsion - failed\n" if DEBUG;
exit(FALSE); # installed, but not correct version
}
}
print STDERR "$modulename not installed - failed\n" if DEBUG;
exit(FALSE); # false
__END__
# ./cpanModVer.pl HTML::Mason 1.1
HTML::Mason installed:1.23 required:1.1 - ok
# ./cpanModVer.pl CPAN 1.0
Argument "1.59_54" isn't numeric in numeric ge (>=) at ./cpanModVer.pl
+ line 36.
Linux 2.4.20-28.7 i686
This is perl, v5.6.1 built for i386-linux
(GNU cfengine 2.1.7p1)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.