Skip to content
Browse files

Moving from META.yml to META.json

  • Loading branch information...
1 parent 112c1b8 commit 3bb31ad313780571a6b1547b2e014085bafb1471 @sanko committed Jun 27, 2010
Showing with 41 additions and 4 deletions.
  1. +1 −1 .gitignore
  2. +0 −1 Build.PL
  3. +1 −1 MANIFEST
  4. +39 −1 inc/MBX/Developer.pm
View
2 .gitignore
@@ -17,7 +17,7 @@ MYMETA.yml
# metadata and other stuff generated by Module::Build
MANIFEST.bak
-META.yml
+META.json
# random clutter
*.bak
View
1 Build.PL
@@ -60,7 +60,6 @@ my $mb = $class->new(
}
},
meta_merge => {
- generated_by => 'Conversion, software version 7.0',
keywords => [qw[BitTorrent torrent ]],
resources => {
bugtracker => {
View
2 MANIFEST
@@ -35,7 +35,7 @@ lib/Net/BitTorrent/Storage/Node.pm
lib/Net/BitTorrent/Torrent.pm
lib/Net/BitTorrent/Types.pm
MANIFEST This list of files
-META.yml
+META.json
t/10000_by_class/Net/BitTorrent/DHT.t
t/10000_by_class/Net/BitTorrent/DHT/Standalone.t
t/10000_by_class/Net/BitTorrent/Storage/File.t
View
40 inc/MBX/Developer.pm
@@ -2,7 +2,45 @@ package inc::MBX::Developer;
{
use strict;
use warnings;
- use base 'Module::Build';
+ use parent 'Module::Build';
+ use 5.010;
+
+ sub new {
+ my $class = shift;
+ my $self = $class->SUPER::new(@_);
+ $self->metafile('META.json') if $self->metafile eq 'META.yml';
+ return $self;
+ }
+
+ sub write_metafile {
+ my $s = shift;
+ require CPAN::Meta::Converter;
+ require CPAN::Meta::Validator;
+ require JSON;
+ JSON->VERSION(2);
+ my $data = {};
+ $s->prepare_metadata($data);
+ $data->{'meta-spec'} = { # In reality, it's probably a hybrid...
+ url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
+ version => 2
+ };
+ my $metafile = $s->metafile;
+ my $cmc = CPAN::Meta::Converter->new($data); # ...so we convert
+ $data = $cmc->convert(version => 2); # ...and clean it up here
+ my $cmv = CPAN::Meta::Validator->new($data);
+ say $_ # ...and double check the result
+ for $cmv->is_valid
+ ? ()
+ : 'Invalid META structure. Errors found:', $cmv->errors;
+ $data->{generated_by} = 'Conversion, Software version 7.0';
+ open my ($fh), '>', # ...and eventually save it to disk.
+ $metafile || die "can't open $metafile for writing: $!";
+ syswrite $fh, JSON->new->ascii(1)->pretty->canonical(1)->encode($data)
+ || die "can't print metadata to $metafile: $!";
+ close $fh || die "error closing $metafile: $!";
+ $s->{'wrote_metadata'} = 1;
+ $s->_add_to_manifest('MANIFEST', $metafile);
+ }
sub make_tarball {
my ($self, $dir, $file, $quiet) = @_;

0 comments on commit 3bb31ad

Please sign in to comment.
Something went wrong with that request. Please try again.