This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mg.c: Remove poorly considered assertion
[perl5.git] / Porting / makemeta
index 882540c..6981048 100644 (file)
@@ -6,19 +6,31 @@
 
 use strict;
 use warnings;
+use Getopt::Std;
 
 my $opts = {
   'META.yml'  => { version => '1.4' },
   'META.json' => { version => '2' },
 };
 
-my $file = shift;
-die "Must specify META.yml or META.json" unless $file and defined $opts->{$file};
+my %switches;
+getopts('byj', \%switches);
 
-my $status = _determine_status();
+my @metafiles;
+if ( $switches{y} ) {
+  push @metafiles, 'META.yml';
+}
+elsif ( $switches{j} ) {
+  push @metafiles, 'META.json';
+}
+else {
+  push @metafiles, keys %$opts;
+}
+
+my ($vers, $stat ) = _determine_status();
 
 my $distmeta = {
-  'version' => $],
+  'version' => $vers,
   'name' => 'perl',
   'author' => [
     'perl5-porters@perl.org'
@@ -27,7 +39,7 @@ my $distmeta = {
     'perl_5'
   ],
   'abstract' => 'The Perl 5 language interpreter',
-  'release_status' => $status,
+  'release_status' => $stat,
   'dynamic_config' => 1,
   'resources' => {
     'repository' => {
@@ -35,7 +47,7 @@ my $distmeta = {
     },
     'homepage' => 'http://www.perl.org/',
     'bugtracker' => {
-      'web' => 'http://rt.perl.org/perlbug/'
+      'web' => 'https://rt.perl.org/'
     },
     'license' => [
       'http://dev.perl.org/licenses/'
@@ -58,7 +70,7 @@ my @CPAN  = grep { $Modules{$_}{CPAN} } keys %Modules;
 my @files = ('autodoc.pl', 'lib/unicore/mktables', 'TestInit.pm',
              'Porting/Maintainers.pm', 'Porting/perldelta_template.pod',
              map { get_module_files($_) } @CPAN);
-my @dirs  = ('cpan', 'win32', 'mad', grep { -d $_ && $_  !~ /^cpan/ } map { get_module_pat($_) } @CPAN);
+my @dirs  = ('cpan', 'win32', grep { -d $_ && $_  !~ /^cpan/ } map { get_module_pat($_) } @CPAN);
 
 my %dirs;
 @dirs{@dirs} = ();
@@ -86,15 +98,18 @@ $distmeta->{no_index}->{file} = \@files;
 $distmeta->{no_index}->{directory} = \@dirs;
 
 my $meta = CPAN::Meta->create( $distmeta );
-my $fh = open_new($file);
-print $fh $meta->as_string( $opts->{$file} );
-close_and_rename($fh);
+foreach my $file ( @metafiles ) {
+  my $fh = open_new($file);
+  print $fh $meta->as_string( $opts->{$file} );
+  close_and_rename($fh);
+}
 exit 0;
 
 sub _determine_status {
   my $patchlevel_h = 'patchlevel.h';
   return unless -e $patchlevel_h;
   my $status = '';
+  my $version = '';
   {
     my %defines;
     open my $fh, '<', $patchlevel_h;
@@ -114,6 +129,13 @@ sub _determine_status {
     unless ( $status ) {
       $status = $defines{PERL_VERSION} % 2 ? 'unstable' : 'stable';
     }
+    if ( my @wotsits = grep { defined $defines{$_} } qw(PERL_REVISION PERL_VERSION PERL_SUBVERSION) ) {
+      $version = sprintf '%d.%03d%03d', map { $defines{$_} } @wotsits;
+    }
+    else {
+      # Well, you never know
+      $version = sprintf '5.%03d_%02d', map { $defines{$_} } qw(PATCHLEVEL SUBVERSION);
+    }
   }
-  return $status;
+  return ( $version, $status );
 }