Skip to content

Commit

Permalink
restrict [MetaYAML] to metaspec v1.4, [MetaJSON] to v2.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
karenetheridge committed Jul 5, 2016
1 parent e96691f commit 09462bc
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 46 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- restrict [MetaYAML] to metaspec v1.4, [MetaJSON] to v2.0+, as other
version combinations are not well-supported by the toolchain

6.006 2016-07-04 10:56:36-04:00 America/New_York
- add some documentation to Dist::Zilla::App::Tester (thanks, Alberto
Expand Down
3 changes: 1 addition & 2 deletions corpus/dist/AuthorDeps/dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ copyright_year = 2009

[AutoPrereqs]
:version = 5.0

skip = ^DZPA::Skip

[MetaYAML]
version = 2

[Encoding / WithDescription]
:version = 5.0
Expand Down
2 changes: 0 additions & 2 deletions corpus/dist/AutoPrereqs/dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ copyright_year = 2009
[ExecDir]
[AutoPrereqs]
skip = ^DZPA::Skip
[MetaYAML]
version = 2

[Encoding]
encoding = bytes
Expand Down
9 changes: 8 additions & 1 deletion lib/Dist/Zilla/Plugin/MetaJSON.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package Dist::Zilla::Plugin::MetaJSON;

use Moose;
with 'Dist::Zilla::Role::FileGatherer';
use Moose::Util::TypeConstraints;

use namespace::autoclean;

Expand Down Expand Up @@ -36,9 +37,15 @@ If you want a fixed version, specify it.
=cut

my $version_type = subtype(
as 'Num',
where { $_ >= 2 },
message { "MetaJSON version must be 2 or greater" },
);

has version => (
is => 'ro',
isa => 'Num',
isa => $version_type,
default => '2',
);

Expand Down
21 changes: 1 addition & 20 deletions lib/Dist/Zilla/Plugin/MetaYAML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,6 @@ has filename => (
default => 'META.yml',
);

=attr version
This parameter lets you pick what version of the spec to use when generating
the output. It defaults to 1.4, the most commonly supported version at
present.
B<This may change without notice in the future.>
Once version 2 of the META file spec is more widely supported, this may default
to 2.
=cut

has version => (
is => 'ro',
isa => 'Num',
default => '1.4',
);

sub gather_files {
my ($self, $arg) = @_;

Expand Down Expand Up @@ -72,7 +53,7 @@ sub gather_files {
}

my $converter = CPAN::Meta::Converter->new($distmeta);
my $output = $converter->convert(version => $self->version);
my $output = $converter->convert(version => '1.4');
$output->{x_serialization_backend} = sprintf '%s version %s',
'YAML::Tiny', YAML::Tiny->VERSION;

Expand Down
8 changes: 1 addition & 7 deletions t/plugins/autoprereqs.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ sub build_meta {
my $tzil = shift;

$tzil->build;

YAML::Tiny->new->read($tzil->tempdir->child('build/META.yml'))->[0];
$tzil->distmeta;
}

my $tzil = Builder->from_config(
Expand Down Expand Up @@ -64,7 +63,6 @@ $tzil = Builder->from_config(
qw(GatherDir ExecDir),
[ AutoPrereqs => { skip => '^DZPA::Skip',
configure_finder => ':IncModules' } ],
[ MetaYAML => { version => 2 } ],
),
'source/inc/DZPA.pm' => "use DZPA::NotInDist;\n use DZPA::Configure;\n",
},
Expand Down Expand Up @@ -101,7 +99,6 @@ $tzil = Builder->from_config(
qw(GatherDir ExecDir),
[ AutoPrereqs => { skip => '^DZPA::Skip',
configure_finder => ':IncModules' } ],
[ MetaYAML => { version => 2 } ],
),
'source/inc/DZPA.pm' => "use DZPA::NotInDist;\n use DZPA::Configure;\n",
'source/t/basic.t' => "use Test::Foo;\n",
Expand Down Expand Up @@ -138,7 +135,6 @@ $tzil = Builder->from_config(
qw(GatherDir ExecDir),
[ AutoPrereqs => { skip => '^DZPA::Skip',
configure_finder => ':IncModules' } ],
[ MetaYAML => { version => 2 } ],
),
'source/inc/DZPA.pm' => "use DZPA::NotInDist;\n use DZPA::Configure;\n",
'source/t/basic.t' => "use Test::Foo;\n",
Expand Down Expand Up @@ -182,7 +178,6 @@ $tzil = Builder->from_config(
'source/dist.ini' => simple_ini(
qw(GatherDir ExecDir),
[ AutoPrereqs => { scanner => 'Perl5', extra_scanner => 'Aliased' } ],
[ MetaYAML => { version => 2 } ],
),
'source/lib/DZPA/Aliased.pm' => "use aliased 'Long::Class::Name';\n",
},
Expand Down Expand Up @@ -221,7 +216,6 @@ $tzil = Builder->from_config(
qw(GatherDir ExecDir),
[ AutoPrereqs => { skip => '^DZPA::Skip',
type => 'suggests' } ],
[ MetaYAML => { version => 2 } ],
),
'source/t/basic.t' => "use Test::Foo;\n",
},
Expand Down
28 changes: 14 additions & 14 deletions t/plugins/distmeta.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use YAML::Tiny;
[ Prereqs => BuildRequires => { 'Test::Foo' => '2.34' } ],
[ Prereqs => ConfigureRequires => { 'Build::Foo' => '0.12' } ],
'MetaJSON',
[ MetaYAML => { version => 2 } ],
'MetaConfig',
),
},
Expand All @@ -41,13 +40,19 @@ use YAML::Tiny;
$meta{json} = JSON::MaybeXS->new(utf8 => 0)->decode($json);
$meta{json}{x_serialization_backend} = 'ignore';

my $yaml = $tzil->slurp_file('build/META.yml');
$meta{yaml} = YAML::Tiny->new->read_string($yaml)->[0];
$meta{yaml}{x_serialization_backend} = 'ignore';
$meta{original} = $tzil->distmeta;
$meta{original}{x_serialization_backend} = 'ignore';

is_deeply($meta{json}, $meta{yaml}, "META.json is_deeply META.yml");
cmp_deeply(
$meta{json},
{
%{ $meta{original} },
generated_by => $meta{original}{generated_by} . ', CPAN::Meta::Converter version ' . CPAN::Meta::Converter->VERSION,
},
"META.json data is identical to original distmeta",
);

for my $type (qw(json yaml)) {
for my $type (qw(json original)) {
my $meta = $meta{$type};

my %want = (
Expand Down Expand Up @@ -94,7 +99,6 @@ use YAML::Tiny;
[ Prereqs => RuntimeRecommends => { 'Foo::Bar::Opt' => '1.234' } ],
[ Prereqs => BuildRequires => { 'Test::Foo' => '2.34' } ],
[ Prereqs => ConfigureRequires => { 'Build::Foo' => '0.12' } ],
[ MetaJSON => { version => 1.4 } ],
'MetaYAML',
'MetaConfig',
),
Expand All @@ -108,17 +112,13 @@ use YAML::Tiny;

my %meta;

my $json = $tzil->slurp_file('build/META.json');
$meta{json} = JSON::MaybeXS->new(utf8 => 0)->decode($json);
$meta{json}{x_serialization_backend} = 'ignore';

my $yaml = $tzil->slurp_file('build/META.yml');
$meta{yaml} = YAML::Tiny->new->read_string($yaml)->[0];
$meta{yaml}{x_serialization_backend} = 'ignore';

is_deeply($meta{json}, $meta{yaml}, "META.json is_deeply META.yml");
#cmp_deeply($meta{json}, $meta{yaml}, "META.json data is identical to META.yml");

for my $type (qw(json yaml)) {
for my $type (qw(yaml)) {
my $meta = $meta{$type};

my %want = (
Expand Down Expand Up @@ -167,7 +167,7 @@ use YAML::Tiny;
$meta{yaml}{x_serialization_backend} = 'ignore';

for my $type (qw(json yaml)) {
is_deeply(
cmp_deeply(
$meta{$type}{author},
[
'Olivier Mengué <[email protected]>',
Expand Down

0 comments on commit 09462bc

Please sign in to comment.