From 24eac4cd2eb8a83853bf5d5e936bdceac8629d53 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Wed, 18 May 2016 13:57:01 -0700 Subject: [PATCH] add [MetaJSON] to [@Basic] --- Changes | 2 ++ lib/Dist/Zilla/Plugin/MetaJSON.pm | 8 +++++++ lib/Dist/Zilla/PluginBundle/Basic.pm | 2 ++ t/plugins/metajson.t | 36 ++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 t/plugins/metajson.t diff --git a/Changes b/Changes index 19aab512e..18b4f52b6 100644 --- a/Changes +++ b/Changes @@ -24,6 +24,8 @@ Revision history for {{$dist->name}} release test (thanks, Karen Etheridge) - all builds now result in a .build/latest symlink (thanks again, Karen) + - [MetaJSON] is now in [@Basic], with special handling to handle the + possibility that the plugin is loaded twice 6.012 2018-04-21 10:20:21+02:00 Europe/Oslo - revert addition of Archive::Tar::Wrapper as a mandatory prereq (in diff --git a/lib/Dist/Zilla/Plugin/MetaJSON.pm b/lib/Dist/Zilla/Plugin/MetaJSON.pm index 78739acd9..b3300af7c 100644 --- a/lib/Dist/Zilla/Plugin/MetaJSON.pm +++ b/lib/Dist/Zilla/Plugin/MetaJSON.pm @@ -8,6 +8,7 @@ use Moose::Util::TypeConstraints; use Dist::Zilla::Dialect; +use List::Util 'first'; use namespace::autoclean; =head1 DESCRIPTION @@ -54,6 +55,13 @@ has version => ( sub gather_files ($self) { my $zilla = $self->zilla; + # gracefully handle there being more than one of us (e.g. one via [@Basic]) + if ((first { $_->isa(__PACKAGE__) } $self->zilla->plugins->@*) != $self) { + $self->log('doing nothing: another [MetaJSON] already ran'); + $self->log('To remove this warning, remove [MetaJSON] from your dist.ini, **and** add ":version = 7.000" underneath [@Basic]'); + return; + } + require JSON::MaybeXS; require Dist::Zilla::File::FromCode; require CPAN::Meta::Converter; diff --git a/lib/Dist/Zilla/PluginBundle/Basic.pm b/lib/Dist/Zilla/PluginBundle/Basic.pm index b72655f31..b94f18733 100644 --- a/lib/Dist/Zilla/PluginBundle/Basic.pm +++ b/lib/Dist/Zilla/PluginBundle/Basic.pm @@ -14,6 +14,7 @@ sub configure ($self) { PruneCruft ManifestSkip MetaYAML + MetaJSON License Readme ExtraTests @@ -45,6 +46,7 @@ It includes the following plugins with their default configuration: * L * L * L +* L * L * L * L diff --git a/t/plugins/metajson.t b/t/plugins/metajson.t new file mode 100644 index 000000000..f7352c22a --- /dev/null +++ b/t/plugins/metajson.t @@ -0,0 +1,36 @@ +use strict; +use warnings; + +use Test::More 0.88; +use Test::DZil; +use Test::Fatal; +use Path::Tiny; + +{ + my $tzil = Builder->from_config( + { dist_root => 'does-not-exist' }, + { + add_files => { + 'source/dist.ini' => simple_ini( + '@Basic', + 'MetaJSON', + ), + }, + }, + ); + + $tzil->chrome->logger->set_debug(1); + is( + exception { $tzil->build }, + undef, + 'build proceeds normally', + ); + + my $build_dir = path($tzil->tempdir)->child('build'); + ok(-e $build_dir->child('META.json'), 'META.json was created successfully'); + + diag 'got log messages: ', explain $tzil->log_messages + if not Test::Builder->new->is_passing; +} + +done_testing;