比较perl模块的版本

王朝perl·作者佚名  2008-05-18
窄屏简体版  字體: |||超大  

#!/usr/local/bin/perl -w

###########################################################################

# Global definitions

###########################################################################

use diagnostics;

use strict;

use Devel::ptkdb;

###########################################################################

# Check required module

###########################################################################

#

# Here we check for --MODULES--

#

print "\nChecking perl modules ...\n";

unless (eval "require 5.005") {

die "Sorry, you need at least Perl 5.005\n";

}

sub vers_cmp {

if (@_ < 2) { die "not enough parameters for vers_cmp" }

if (@_ > 2) { die "too many parameters for vers_cmp" }

my ($a, $b) = @_;

my (@A) = ($a =~ /(\.|\d+|[^\.\d]+)/g);

my (@B) = ($b =~ /(\.|\d+|[^\.\d]+)/g);

my ($A,$B);

while (@A and @B) {

$A = shift @A;

$B = shift @B;

if ($A eq "." and $B eq ".") {

next;

} elsif ( $A eq "." ) {

return -1;

} elsif ( $B eq "." ) {

return 1;

} elsif ($A =~ /^\d+$/ and $B =~ /^\d+$/) {

return $A <=> $B if $A <=> $B;

} else {

$A = uc $A;

$B = uc $B;

return $A cmp $B if $A cmp $B;

}

}

@A <=> @B;

}

# This was originally clipped from the libnet Makefile.PL, adapted here to

# use the above vers_cmp routine for accurate version checking.

sub have_vers {

my ($pkg, $wanted) = @_;

my ($msg, $vnum, $vstr);

no strict 'refs';

printf("Checking for %15s %-9s ", $pkg, !$wanted?'(any)':"(v$wanted)");

eval { my $p; ($p = $pkg . ".pm") =~ s!::!/!g; require $p; };

$vnum = ${"${pkg}::VERSION"} || ${"${pkg}::Version"} || 0;

$vnum = -1 if $@;

if ($vnum eq "-1") { # string compare just in case it's non-numeric

$vstr = "not found";

}

elsif (vers_cmp($vnum,"0") > -1) {

$vstr = "found v$vnum";

}

else {

$vstr = "found unknown version";

}

my $vok = (vers_cmp($vnum,$wanted) > -1);

print ((($vok) ? "ok: " : " "), "$vstr\n");

return $vok;

}

# Check versions of dependencies. 0 for version = any version acceptible

my $modules = [

{

name => 'Getopt::Long',

version => ''

},

{

name => 'File::Find',

version => ''

},

{

name => 'File::Copy',

version => ''

},

{

name => 'FileHandle',

version => ''

},

{

name => 'mod_perl',

version => ''

}

];

my %missing = ();

foreach my $module (@{$modules}) {

unless (have_vers($module->{name}, $module->{version})) {

$missing{$module->{name}} = $module->{version};

}

}

system("perl -v");

system("cvs -v");

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航