/
RWSTAUNER.pm
453 lines (378 loc) · 11.8 KB
/
RWSTAUNER.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# vim: set ts=2 sts=2 sw=2 expandtab smarttab:
use strict;
use warnings;
package Dist::Zilla::PluginBundle::Author::RWSTAUNER;
# ABSTRACT: RWSTAUNER's Dist::Zilla config
use Moose;
use List::Util qw(first); # core
with qw(
Dist::Zilla::Role::PluginBundle::Easy
Dist::Zilla::Role::PluginBundle::Config::Slicer
Dist::Zilla::Role::PluginBundle::PluginRemover
);
# Dist::Zilla::Role::DynamicConfig is not necessary: payload is already dynamic
# don't require it in case it won't install somewhere
my $spelling_tests = eval 'require Dist::Zilla::Plugin::Test::PodSpelling';
# available builders
my %builders = (
eumm => 'MakeMaker',
mb => 'ModuleBuild',
);
# cannot use $self->name for class methods
sub _bundle_name {
my $class = @_ ? ref $_[0] || $_[0] : __PACKAGE__;
join('', '@', ($class =~ /^.+::PluginBundle::(.+)$/));
}
# TODO: consider an option for using ReportPhase
sub _default_attributes {
use Moose::Util::TypeConstraints 1.01;
return {
auto_prereqs => [Bool => 1],
fake_release => [Bool => $ENV{DZIL_FAKERELEASE}],
# cpanm will choose the best place to install
install_command => [Str => 'cpanm -v -i .'],
is_task => [Bool => 0],
placeholder_comments => [Bool => 0],
releaser => [Str => 'UploadToCPAN'],
skip_plugins => [Str => ''],
weaver_config => [Str => $_[0]->_bundle_name],
use_git_bundle => [Bool => 1],
max_target_perl => [Str => '5.008'],
builder => [enum( [ both => keys %builders ] ) => 'eumm'],
};
}
sub _generate_attribute {
my ($self, $key) = @_;
has $key => (
is => 'ro',
isa => $self->_default_attributes->{$key}[0],
lazy => 1,
default => sub {
# if it exists in the payload
exists $_[0]->payload->{$key}
# use it
? $_[0]->payload->{$key}
# else get it from the defaults (for subclasses)
: $_[0]->_default_attributes->{$key}[1];
}
);
}
{
# generate attributes
__PACKAGE__->_generate_attribute($_)
for keys %{ __PACKAGE__->_default_attributes };
}
around BUILDARGS => sub {
my ($orig, $class, @args) = @_;
my $attr = $class->$orig(@args);
# removed attributes
my %deprecated = (
disable_tests => '-remove',
skip_prereqs => 'AutoPrereqs.skip',
);
while( my ($old, $new) = each %deprecated ){
if( exists $attr->{payload}{ $old } ){
die "$class no longer supports '$old'.\n Please use '$new' instead.\n";
}
}
return $attr;
};
# main
after configure => sub {
my ($self) = @_;
# TODO: accept this from ENV
my $skip = $self->skip_plugins;
$skip &&= qr/$skip/;
my $dynamic = $self->payload;
# sneak this config in behind @TestingMania's back
$dynamic->{'Test::Compile.fake_home'} = 1
unless first { /Test::Compile\W+fake_home/ } keys %$dynamic;
my $plugins = $self->plugins;
my $i = -1;
while( ++$i < @$plugins ){
my $spec = $plugins->[$i] or next;
# NOTE: $conf retains its reference (modifications alter $spec)
my ($name, $class, $conf) = @$spec;
# ignore the prefix (@Bundle/Name => Name) (DZP::Name => Name)
my ($alias) = ($name =~ m#([^/]+)$#);
my ($moniker) = ($class =~ m#^(?:Dist::Zilla::Plugin(?:Bundle)?::)?(.+)$#);
# exclude any plugins that match 'skip_plugins'
if( $skip ){
# match on full name or plugin class (regexp should use \b not \A)
if( $name =~ $skip || $class =~ $skip ){
splice(@$plugins, $i, 1);
redo;
}
}
}
if ( $ENV{DZIL_BUNDLE_DEBUG} ) {
eval {
require YAML::Tiny; # dzil requires this
$self->log( YAML::Tiny::Dump( $self->plugins ) );
};
warn $@ if $@;
}
};
sub configure {
my ($self) = @_;
$self->log_fatal("you must not specify both weaver_config and is_task")
if $self->is_task and $self->weaver_config ne $self->_bundle_name;
$self->add_plugins(
# provide version
#'Git::DescribeVersion',
'Git::NextVersion',
# gather and prune
$self->_generate_manifest_skip,
qw(
GatherDir
PruneCruft
ManifestSkip
),
# Devel::Cover db does not need to be packaged with distribution
[ PruneFiles => 'PruneDevelCoverDatabase' => { match => '^(cover_db/.+)' } ],
# Code::Stat report
[ PruneFiles => 'PruneCodeStatCollection' => { match => '^codestat\.out' } ],
# generated tags file... useful for development but noisy to commit
[ PruneFiles => 'PruneTags' => { match => '^tags$' } ],
# munge files
[
Authority => {
':version' => '1.005', # accepts any non-whitespace + locate_comment
do_munging => 1,
do_metadata => 1,
locate_comment => $self->placeholder_comments,
}
],
[
NextRelease => {
# w3cdtf
time_zone => 'UTC',
format => q[%-9V %{yyyy-MM-dd'T'HH:mm:ss'Z'}d],
}
],
'Git::Describe',
($self->placeholder_comments ? 'OurPkgVersion' : 'PkgVersion'),
[
Prepender => {
':version' => '1.112280', # 'skip' attribute
# don't prepend to tests
skip => '^x?t/.+',
}
],
( $self->is_task
? 'TaskWeaver'
# TODO: detect weaver.ini and skip 'config_plugin'?
: [ 'PodWeaver' => { config_plugin => $self->weaver_config } ]
),
# generated distribution files
qw(
License
Readme
),
[
# generate README.pod in repo root for github
ReadmeAnyFromPod => {
':version' => '0.120120',
type => 'pod',
location => 'root',
}
],
# metadata
'Bugtracker',
# won't find git if not in repository root (!-e ".git")
[ Repository => { ':version' => '0.16' } ], # deprecates github_http
# overrides [Repository] if repository is on github
[ GithubMeta => { ':version' => '0.10' } ],
[ ContributorsFromGit => { ':version' => '0.005' } ],
);
$self->add_plugins('AutoPrereqs')
if $self->auto_prereqs;
$self->add_plugins(
# [ 'MetaData::BuiltWith' => { show_uname => 1 } ], # currently DZ::Util::EmulatePhase causes problems
[
MetaNoIndex => {
':version' => 1.101130,
# could use grep { -d $_ } but that will miss any generated files
directory => [qw(corpus examples inc share t xt)],
namespace => [qw(Local t::lib)],
'package' => [qw(DB)],
}
],
[ # AFTER MetaNoIndex
'MetaProvides::Package' => {
':version' => '1.14000001',
meta_noindex => 1
}
],
[ MinimumPerl => { ':version' => '1.003' } ],
qw(
MetaConfig
MetaYAML
MetaJSON
),
# I prefer to be explicit about required versions when loading, but this is a handy example:
# [
# Prereqs => 'TestMoreWithSubtests' => {
# -phase => 'test',
# -type => 'requires',
# 'Test::More' => '0.96'
# }
# ],
# build system
qw(
ExecDir
ShareDir
),
);
{
my @builders = $self->builder eq 'both'
? (values %builders, 'DualBuilders')
: ($builders{ $self->builder });
$self->log("Including builders: @builders\n");
$self->add_plugins(@builders);
}
$self->add_plugins(
# generated t/ tests
[ 'Test::ReportPrereqs' => { ':version' => '0.004' } ], # include/exclude
[ 'Test::ChangesHasContent' => { ':version' => '0.006' } ], # version-TRIAL
# generated xt/ tests
# Test::Pod::Spelling::CommonMistakes ?
#Test::Pod::No404s # removed since it's rarely useful
);
if ( $spelling_tests ) {
$self->add_plugins('Test::PodSpelling');
}
else {
$self->log("Test::PodSpelling Plugin failed to load. Pleese dunt mayke ani misteaks.\n");
}
# NOTE: A newer TestingMania might duplicate plugins if new tests are added
$self->add_bundle('@TestingMania' => {
':version' => '0.019', # max_target_petl
max_target_perl => $self->max_target_perl,
});
$self->add_plugins(
# manifest: must come after all generated files
'Manifest',
# before release
qw(
CheckExtraTests
),
[ CheckChangesHasContent => { ':version' => '0.006' } ], # version-TRIAL
qw(
CheckMetaResources
CheckPrereqsIndexed
TestRelease
),
);
# defaults: { tag_format => '%v', push_to => [ qw(origin) ] }
$self->add_bundle('@Git' => {
':version' => '2.004', # improved changelog parsing
allow_dirty => [qw(Changes README.pod)],
commit_msg => 'v%v%t%n%n%c'
})
if $self->use_git_bundle;
$self->add_plugins(
qw(
ConfirmRelease
),
);
# release
my $releaser = $self->fake_release ? 'FakeRelease' : $self->releaser;
# ignore releaser if it's set to empty string
$self->add_plugins($releaser)
if $releaser;
$self->add_plugins(
[ InstallRelease => { ':version' => '0.006', install_command => $self->install_command } ]
)
if $self->install_command;
}
# As of Dist::Zilla 4.102345 pluginbundles don't have log and log_fatal methods
foreach my $method ( qw(log log_fatal) ){
unless( __PACKAGE__->can($method) ){
no strict 'refs'; ## no critic (NoStrict)
*$method = $method =~ /fatal/
? sub { die($_[1]) }
: sub { warn("[${\$_[0]->_bundle_name}] $_[1]") };
}
}
sub _generate_manifest_skip {
# include a default MANIFEST.SKIP for the tests and/or historical reasons
return [
GenerateFile => 'GenerateManifestSkip' => {
filename => 'MANIFEST.SKIP',
is_template => 1,
content => <<'EOF_MANIFEST_SKIP',
\B\.git\b
\B\.gitignore$
^[\._]build
^blib/
^(Build|Makefile)$
\bpm_to_blib$
^MYMETA\.
EOF_MANIFEST_SKIP
}
];
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
=for Pod::Coverage configure
log log_fatal
=head1 SYNOPSIS
# dist.ini
[@Author::RWSTAUNER]
=head1 DESCRIPTION
This is an Author
L<Dist::Zilla::PluginBundle|Dist::Zilla::Role::PluginBundle::Easy>
that I use for building my distributions.
=head1 CONFIGURATION
Possible options and their default values:
auto_prereqs = 1 ; enable AutoPrereqs
builder = eumm ; or 'mb' or 'both'
fake_release = 0 ; if true will use FakeRelease instead of 'releaser'
install_command = cpanm -v -i . (passed to InstallRelease)
is_task = 0 ; set to true to use TaskWeaver instead of PodWeaver
placeholder_comments = 0 ; use '# VERSION' and '# AUTHORITY' comments
releaser = UploadToCPAN
skip_plugins = ; default empty; a regexp of plugin names to exclude
weaver_config = @Author::RWSTAUNER
The C<fake_release> option also respects C<$ENV{DZIL_FAKERELEASE}>.
B<NOTE>:
This bundle consumes L<Dist::Zilla::Role::PluginBundle::Config::Slicer>
so you can also specify attributes for any of the bundled plugins.
The option should be the plugin name and the attribute separated by a dot:
[@Author::RWSTAUNER]
AutoPrereqs.skip = Bad::Module
B<Note> that this is different than
[@Author::RWSTAUNER]
[AutoPrereqs]
skip = Bad::Module
which will load the plugin a second time.
The first example actually alters the plugin configuration
as it is included by the Bundle.
See L<Config::MVP::Slicer/CONFIGURATION SYNTAX> for more information.
If your situation is more complicated you can use the C<-remove> attribute
(courtesy of L<Dist::Zilla::Role::PluginBundle::PluginRemover>)
to have the Bundle ignore that plugin
and then you can add it yourself:
[MetaNoIndex]
directory = one-dir
directory = another-dir
[@Author::RWSTAUNER]
-remove = MetaNoIndex
C<-remove> can be specified multiple times.
Alternatively you can use the C<skip_plugins> attribute (only once)
which is a regular expression that matches plugin name or package.
[@Author::RWSTAUNER]
skip_plugins = MetaNoIndex|SomethingElse
=head1 ROUGHLY EQUIVALENT
This bundle is roughly equivalent to the following (generated) F<dist.ini>:
=bundle_ini_string
=head1 SEE ALSO
=for :list
* L<Dist::Zilla>
* L<Dist::Zilla::Role::PluginBundle::Easy>
* L<Dist::Zilla::Role::PluginBundle::Config::Slicer>
* L<Dist::Zilla::Role::PluginBundle::PluginRemover>
* L<Pod::Weaver>
=cut