比較perl模組的版本(轉)

post0發表於2007-08-24
比較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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章