The Lancaster Consensus changes the META-2.0 to 1.4 conversion
authorH.Merijn Brand - Tux <h.m.brand@xs4all.nl>
Sun, 14 Apr 2013 22:25:33 +0000 (15 00:25 +0200)
committerH.Merijn Brand - Tux <h.m.brand@xs4all.nl>
Sun, 14 Apr 2013 22:25:33 +0000 (15 00:25 +0200)
sandbox/genMETA.pl
sandbox/genMETA.pm

index d46bb58..3f79b16 100755 (executable)
@@ -59,8 +59,8 @@ test_requires:
     Test::More:          0.88
     Test::NoWarnings:    0
 recommends:
-    perl:                5.016002
-    Data::Dumper:        2.139
+    perl:                5.016003
+    Data::Dumper:        2.145
     Perl::Tidy:          0
 test_recommends:
     Test::More:          0.98
index dfaa812..7cdf019 100644 (file)
@@ -326,14 +326,40 @@ sub fix_meta
     if (my $tp = delete $yml->{prereqs}{test}) {
        foreach my $phase (keys %{$tp}) {
            my $p = $tp->{$phase};
-           $yml->{runtime}{$phase}{$_} //= $p->{$_} for keys %{$p};
+           #DDumper { $phase => $p };
+           $yml->{prereqs}{runtime}{$phase}{$_} //= $p->{$_} for keys %{$p};
            }
        }
+
+    # Optional features in 1.4 knows requires, but not recommends.
+    # The Lancaster Consensus moves 2.0 optional recommends promote to
+    # requires in 1.4
+    if (my $of = $yml->{optional_features}) {
+       foreach my $f (keys %$of) {
+           if (my $r = delete $of->{$f}{prereqs}{runtime}{recommends}) {
+               $of->{$f}{requires} = $r;
+               }
+           }
+       }
+    # runtime and test_requires are unknown as top-level in 1.4
+    foreach my $phase (qw( xuntime test_requires )) {
+       if (my $p = delete $yml->{$phase}) {
+           foreach my $f (keys %$p) {
+               $yml->{$f}{$_} ||= $p->{$f}{$_} for keys %{$p->{$f}};
+               }
+           }
+       }
+
     #DDumper $yml;
     # This does NOT create a correct YAML id the source does not comply!
     $yml = CPAN::Meta::Converter->new ($yml)->convert (version => "1.4");
+    $yml->{requires}{perl} //= $jsn->{prereqs}{runtime}{requires}{perl}
+                          //  $self->{h}{requires}{perl}
+                          //  "";
+    $yml->{build_requires} && !keys %{$yml->{build_requires}} and
+       delete $yml->{build_requires};
     #DDumper $yml;
-    exit;
+    #exit;
 
     @my == 1 && open my $my, ">", $yf or croak "Cannot update $yf\n";
     print $my Dump $yml; # @{$self->{yml}};