ITPub博客

首页 > 应用开发 > IT综合 > 比较perl模块的版本(转)

比较perl模块的版本(转)

原创 IT综合 作者:post0 时间:2007-08-24 17:27:15 0 删除 编辑
比较perl模块的版本(转)[@more@]

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

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

  # Global definitions

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

  use diagnostics;

  use strict;

  use Devel::ptkdb;

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

  # Check required module

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

  #

  # Here we check for --MODULES--

  #

  print " Checking perl modules ... ";

  unless (eval "require 5.005") {

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

  }

  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 ");

  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")

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8225414/viewspace-965600/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    2031
  • 访问量
    7944286