Comply to new(er) Meta: generate correct JSON
[Data-Peek.git] / sandbox / genMETA.pl
blob467673c004e2e3c90fae527924b179385ee980e6
1 #!/pro/bin/perl
3 use strict;
4 use warnings;
6 use Getopt::Long qw(:config bundling nopermute);
7 my $check = 0;
8 my $opt_v = 0;
9 GetOptions (
10 "c|check" => \$check,
11 "v|verbose:1" => \$opt_v,
12 ) or die "usage: $0 [--check]\n";
14 use YAML::Syck;
15 use JSON;
17 my $version;
18 open my $pm, "<", "Peek.pm" or die "Cannot read Peek.pm";
19 while (<$pm>) {
20 m/^.VERSION\s*=\s*"?([-0-9._]+)"?\s*;\s*$/ or next;
21 $version = $1;
22 last;
24 close $pm;
26 my @yml;
27 while (<DATA>) {
28 s/VERSION/$version/o;
29 push @yml, $_;
32 if ($check) {
33 print STDERR "Check required and recommended module versions ...\n";
34 BEGIN { $V::NO_EXIT = $V::NO_EXIT = 1 } require V;
35 my %vsn = map { m/^\s*([\w:]+):\s+([0-9.]+)$/ ? ($1, $2) : () } @yml;
36 delete @vsn{qw( perl version )};
37 for (sort keys %vsn) {
38 $vsn{$_} eq "0" and next;
39 my $v = V::get_version ($_);
40 $v eq $vsn{$_} and next;
41 printf STDERR "%-35s %-6s => %s\n", $_, $vsn{$_}, $v;
44 print STDERR "Checking generated YAML ...\n";
45 use Test::YAML::Meta::Version;
46 my $h;
47 my $yml = join "", @yml;
48 eval { $h = Load ($yml) };
49 $@ and die "$@\n";
50 $opt_v and print Dump $h;
51 my $t = Test::YAML::Meta::Version->new (yaml => $h);
52 $t->parse () and
53 die join "\n", "Test::YAML::Meta reported failure:", $t->errors, "";
55 use Parse::CPAN::Meta;
56 eval { Parse::CPAN::Meta::Load ($yml) };
57 $@ and die "$@\n";
59 my $req_vsn = $h->{requires}{perl};
60 print "Checking if $req_vsn is still OK as minimal version for examples\n";
61 use Test::MinimumVersion;
62 # All other minimum version checks done in xt
63 all_minimum_version_ok ($req_vsn, { paths => [ "examples" ]});
65 elsif ($opt_v) {
66 print @yml;
68 else {
69 my @my = glob <*/META.yml>;
70 my $yf = $my[0];
71 @my == 1 && open my $my, ">", $yf or die "Cannot update $yf\n";
72 print $my @yml;
73 close $my;
75 $yf =~ s/yml$/json/;
76 my $jsn = Load ("@yml");
77 $jsn->{"meta-spec"} = {
78 version => "2.0",
79 url => "https://metacpan.org/module/CPAN::Meta::Spec?#meta-spec",
81 open $my, ">", $yf or die "Cannot update $yf\n";
82 print $my JSON->new->utf8 (1)->pretty (1)->encode ($jsn);
84 chmod 0644, glob "*/META.*";
87 __END__
88 --- #YAML:1.0
89 name: Data::Peek
90 version: VERSION
91 abstract: Modified and extended debugging facilities
92 license: perl
93 author:
94 - H.Merijn Brand <h.m.brand@xs4all.nl>
95 generated_by: Author
96 distribution_type: module
97 provides:
98 Data::Peek:
99 file: Peek.pm
100 version: VERSION
101 requires:
102 perl: 5.008
103 DynaLoader: 0
104 Data::Dumper: 0
105 recommends:
106 perl: 5.014001
107 Perl::Tidy: 0
108 Test::More: 0.98
109 configure_requires:
110 ExtUtils::MakeMaker: 0
111 build_requires:
112 perl: 5.008
113 test_requires:
114 Test::Harness: 0
115 Test::More: 0.88
116 Test::NoWarnings: 0
117 resources:
118 license: http://dev.perl.org/licenses/
119 repository: http://repo.or.cz/w/Data-Peek.git
120 meta-spec:
121 version: 1.4
122 url: http://module-build.sourceforge.net/META-spec-v1.4.html