FYI -- version tuples/objects in META.yml will be normalized
('v1.2.3'), as will generated distribution version numbers if they
come from a tuple/object.

Please make sure any downstream tools will accept this.  (It's in the
wild on CPAN, so hopefully, this will not take anyone by surprise.)

-- David

---------- Forwarded message ----------
From:  <[email protected]>
Date: Mon, May 18, 2009 at 9:04 AM
Subject: [svn:Module-Build] r12774 - in Module-Build/trunk: . lib/Module/Build
To: [email protected]


Author: dagolden
Date: Mon May 18 06:04:25 2009
New Revision: 12774

Modified:
  Module-Build/trunk/Changes
  Module-Build/trunk/lib/Module/Build/Base.pm

Log:
Normalize versions in META.yml; add M::B to configure_requires

>From Changes:
 - Adds current Module::Build to configure_requires (and build_requires)
  if no configure_requires is specified
 - Always normalizes version number tuples in META.yml (e.g. 'v1.2.0')
  (Partially addresses RT#46150)
 - Normalizes a generated dist_version (e.g. from a .pm file) --
  dist_version set manually in Build.PL is not normalized



Modified: Module-Build/trunk/Changes
==============================================================================
--- Module-Build/trunk/Changes  (original)
+++ Module-Build/trunk/Changes  Mon May 18 06:04:25 2009
@@ -5,6 +5,14 @@
 Bug-fixes:
 - Fixed RT#42724: consolidated VMS fixes [patch by CBERRY]

+ Other:
+ - Adds current Module::Build to configure_requires (and build_requires)
+   if no configure_requires is specified
+ - Always normalizes version number tuples in META.yml (e.g. 'v1.2.0')
+   (Partially addresses RT#46150)
+ - Normalizes a generated dist_version (e.g. from a .pm file) --
+   dist_version set manually in Build.PL is not normalized
+
 0.33 - Sun May  3 20:16:34 PDT 2009

 Bug-fixes:

Modified: Module-Build/trunk/lib/Module/Build/Base.pm
==============================================================================
--- Module-Build/trunk/lib/Module/Build/Base.pm (original)
+++ Module-Build/trunk/lib/Module/Build/Base.pm Mon May 18 06:04:25 2009
@@ -1040,7 +1040,7 @@
    my $version_from = File::Spec->catfile( split( qr{/},
$dist_version_from ) );
    my $pm_info = Module::Build::ModuleInfo->new_from_file( $version_from )
      or die "Can't find file $version_from to determine version";
-    $p->{dist_version} = $pm_info->version();
+    $p->{dist_version} = $self->normalize_version( $pm_info->version() );
  }

  die ("Can't determine distribution version, must supply either
'dist_version',\n".
@@ -3613,6 +3613,27 @@
  return 1;
 }

+sub normalize_version {
+  my ($self, $version) = @_;
+  if ( $version =~ /[=<>!,]/ ) { # logic, not just version
+    # take as is without modification
+  }
+  elsif ( ref $version eq 'version' ||
+          ref $version eq 'Module::Build::Version' ) { # version objects
+    my $string = $version->stringify;
+    # normalize leading-v: "v1.2" -> "v1.2.0"
+    $version = substr($string,0,1) eq 'v' ? $version->normal : $string;
+  }
+  elsif ( $version =~ /^[^v][^.]*\.[^.]+\./ ) { # no leading v, multiple dots
+    # normalize string tuples without "v": "1.2.3" -> "v1.2.3"
+    $version = "v$version";
+  }
+  else {
+    # leave alone
+  }
+  return $version;
+}
+
 sub prepare_metadata {
  my ($self, $node, $keys) = @_;
  my $p = $self->{properties};
@@ -3630,7 +3651,7 @@
    die "ERROR: Missing required field '$_' for META.yml\n"
      unless defined($node->{$name}) && length($node->{$name});
  }
-  $node->{version} = '' . $node->{version}; # Stringify version objects
+  $node->{version} = $self->normalize_version($node->{version});

  if (defined( my $l = $self->license )) {
    die "Unknown license string '$l'"
@@ -3652,18 +3673,35 @@
  if (exists $p->{configure_requires}) {
    foreach my $spec (keys %{$p->{configure_requires}}) {
      warn ("Warning: $spec is listed in 'configure_requires', but ".
-           "it is not found in any of the other prereq fields.\n")
-       unless grep exists $p->{$_}{$spec},
-              grep !/conflicts$/, @{$self->prereq_action_types};
+            "it is not found in any of the other prereq fields.\n")
+        unless grep exists $p->{$_}{$spec},
+              grep !/conflicts$/, @{$self->prereq_action_types};
    }
  }

-  foreach ( 'configure_requires', @{$self->prereq_action_types} ) {
-    if (exists $p->{$_} and keys %{ $p->{$_} }) {
-      $add_node->($_, $p->{$_});
+  # copy prereq data structures so we can modify them before writing to META
+  my %prereq_types;
+  for my $type ( 'configure_requires', @{$self->prereq_action_types} ) {
+    if (exists $p->{$type}) {
+      for my $mod ( keys %{ $p->{$type} } ) {
+        $prereq_types{$type}{$mod} =
+          $self->normalize_version($p->{$type}{$mod});
+      }
    }
  }

+  # add current Module::Build to configure_requires if there
+  # isn't a configure_requires already specified
+  if ( ! $prereq_types{'configure_requires'} ) {
+    for my $t ('configure_requires', 'build_requires') {
+      $prereq_types{$t}{'Module::Build'} = $VERSION;
+    }
+  }
+
+  for my $t ( keys %prereq_types ) {
+      $add_node->($t, $prereq_types{$t});
+  }
+
  if (exists $p->{dynamic_config}) {
    $add_node->('dynamic_config', $p->{dynamic_config});
  }
@@ -3820,9 +3858,10 @@
    }
  }

-  # Stringify versions.  Can't use exists() here because of bug in YAML::Node.
+  # Normalize versions.  Can't use exists() here because of bug in YAML::Node.
+  # XXX "bug in YAML::Node" comment seems irrelvant -- dagolden, 2009-05-18
  for (grep defined $_->{version}, values %prime) {
-    $_->{version} = '' . $_->{version};
+    $_->{version} = $self->normalize_version( $_->{version} );
  }

  return \%prime;

Reply via email to