From: H.Merijn Brand - Tux Date: Fri, 25 Jan 2013 15:58:50 +0000 (+0100) Subject: meta modernization X-Git-Tag: v0.16~4 X-Git-Url: https://repo.or.cz/w/Config-Perl-V.git/commitdiff_plain/f15e05213561aba01e194840df0a9c4618c1282e meta modernization --- diff --git a/sandbox/genMETA.pm b/sandbox/genMETA.pm index 490cffd..3eeb63e 100644 --- a/sandbox/genMETA.pm +++ b/sandbox/genMETA.pm @@ -11,6 +11,7 @@ use Carp; use List::Util qw( first ); use Encode qw( encode decode ); use Test::CPAN::Meta::YAML::Version; +use CPAN::Meta::Converter; use Test::MinimumVersion; use Test::More (); use Parse::CPAN::Meta; @@ -18,7 +19,7 @@ use File::Find; use YAML::Syck; use Data::Peek; use Text::Diff; -use JSON; +use JSON::PP; sub new { @@ -62,7 +63,7 @@ sub version_from my $version; open my $pm, "<", $src or croak "Cannot read $src"; while (<$pm>) { - m/^(?:our\s+)? \$VERSION \s*=\s* "? ([-0-9._]+) "? \s*;\s*$/x or next; + m/^(?:our\s+)? \$VERSION \s*=\s* ["']? ([-0-9._]+) ['"]? \s*;\s*$/x or next; $version = $1; last; } @@ -207,9 +208,9 @@ sub check_yaml $self->{verbose} and print Dump $h; - my $t = Test::CPAN::Meta::YAML::Version->new (yaml => $h); + my $t = Test::CPAN::Meta::YAML::Version->new (data => $h); $t->parse () and - croak join "\n", "Test::YAML::Meta reported failure:", $t->errors, ""; + croak join "\n", "Test::CPAN::Meta::YAML reported failure:", $t->errors, ""; eval { Parse::CPAN::Meta::Load ($yml) }; $@ and croak "$@\n"; @@ -255,23 +256,67 @@ sub fix_meta { my $self = shift; + # Convert to meta-spec version 2 + # licenses are lists now + my $jsn = $self->{h}; + $jsn->{"meta-spec"} = { + version => "2", + url => "https://metacpan.org/module/CPAN::Meta::Spec?#meta-spec", + }; + exists $jsn->{resources}{license} and + $jsn->{resources}{license} = [ $jsn->{resources}{license} ]; + delete $jsn->{distribution_type}; + if (exists $jsn->{license}) { + $jsn->{license} =~ s/^perl$/perl_5/; + $jsn->{license} = [ $jsn->{license} ]; + } + if (exists $jsn->{resources}{repository}) { + my $url = $jsn->{resources}{repository}; + my $web = $url; + $url =~ s{repo.or.cz/w/}{repo.or.cz/r/}; + $web =~ s{repo.or.cz/r/}{repo.or.cz/w/}; + $jsn->{resources}{repository} = { + type => "git", + web => $web, + url => $url, + }; + } + foreach my $sct ("", "configure_", "build_", "test_") { + (my $x = $sct || "runtime") =~ s/_$//; + for (qw( requires recommends suggests )) { + exists $jsn->{"$sct$_"} and + $jsn->{prereqs}{$x}{$_} = delete $jsn->{"$sct$_"}; + } + } + $jsn = CPAN::Meta::Converter->new ($jsn)->convert (version => "2"); + $jsn->{generated_by} = "Author"; + + my $yml = $jsn; + # 1.4 does not know about test_*, move them to * + if (my $tp = delete $yml->{prereqs}{test}) { + DDumper $tp; + foreach my $phase (keys %{$tp}) { + my $p = $tp->{$phase}; + $yml->{runtime}{$phase}{$_} //= $p->{$_} for keys %{$p}; + } + } + #DDumper $yml; + $yml = CPAN::Meta::Converter->new ($yml)->convert (version => "1.4"); + my @my = glob <*/META.yml> or croak "No META files"; my $yf = $my[0]; - @my == 1 && open my $my, ">", $yf or croak "Cannot update $yf\n"; - print $my @{$self->{yml}}; + print $my Dump $yml; # @{$self->{yml}}; close $my; $yf =~ s/yml$/json/; - my $jsn = $self->{h}; - $jsn->{"meta-spec"} = { - version => 2, - url => "https://metacpan.org/module/CPAN::Meta::Spec?#meta-spec", - }; open $my, ">", $yf or croak "Cannot update $yf\n"; - print $my JSON->new->utf8 (1)->pretty (1)->encode ($jsn); + #rint JSON::PP->new->utf8 (1)->pretty (1)->encode ($jsn); + print $my JSON::PP->new->utf8 (1)->pretty (1)->encode ($jsn); + close $my; chmod 0644, glob "*/META.*"; + unlink glob "MYMETA*"; } # fix_meta 1;