File Coverage

blib/lib/Dist/Zilla/PluginBundle/Author/WATERKIP.pm
Criterion Covered Total %
statement 15 42 35.7
branch 0 14 0.0
condition 0 6 0.0
subroutine 5 10 50.0
pod 4 4 100.0
total 24 76 31.5


line stmt bran cond sub pod time code
1             use Moose;
2 1     1   96886  
  1         383397  
  1         6  
3             # ABSTRACT: An plugin bundle for all distributions by WATERKIP
4             # KEYWORDS: author bundle distribution tool
5              
6             use Data::Dumper;
7 1     1   6755 use List::Util qw(uniq any first);
  1         6857  
  1         64  
8 1     1   7 use Moose::Util::TypeConstraints qw(enum subtype where);
  1         2  
  1         61  
9 1     1   7 use namespace::autoclean;
  1         2  
  1         10  
10 1     1   946  
  1         6441  
  1         3  
11             our $VERSION = '3.1';
12              
13             with
14             'Dist::Zilla::Role::PluginBundle::Easy',
15             'Dist::Zilla::Role::PluginBundle::Airplane',
16             'Dist::Zilla::Role::PluginBundle::PluginRemover' =>
17             { -version => '0.103' },
18             'Dist::Zilla::Role::PluginBundle::Config::Slicer';
19              
20             has server => (
21             is => 'ro',
22             isa => enum([qw(github bitbucket gitlab none)]),
23             init_arg => undef,
24             lazy => 1,
25             default => sub { $_[0]->payload->{server} // 'gitlab' },
26             );
27              
28             has license => (
29             is => 'ro',
30             isa => 'Str',
31             init_arg => undef,
32             lazy => 1,
33             default => sub { $_[0]->payload->{license} // 'LICENSE' },
34             );
35              
36             has exclude_files => (
37             isa => 'ArrayRef[Str]',
38             init_arg => undef,
39             lazy => 1,
40             default => sub { $_[0]->payload->{exclude_files} // [] },
41             traits => ['Array'],
42             handles => { exclude_files => 'elements' },
43             );
44              
45             around exclude_files => sub {
46             my $orig = shift;
47             my $self = shift;
48             sort(uniq(
49             $self->$orig(@_),
50             qw(Dockerfile .gitlab-ci.yml docker-compose.yml docker-compose.override.yml .dockerignore dev-bin/cpanm)
51             ));
52             };
53              
54             has copy_file_from_build => (
55             isa => 'ArrayRef[Str]',
56             init_arg => undef,
57             lazy => 1,
58             default => sub { $_[0]->payload->{copy_file_from_build} // [] },
59             traits => ['Array'],
60             handles => { copy_files_from_build => 'elements' },
61             );
62              
63             around copy_files_from_build => sub {
64             my $orig = shift;
65             my $self = shift;
66             sort(uniq(
67             $self->$orig(@_),
68             qw(Makefile.PL cpanfile Build.PL README README.md CONTRIBUTORS),
69             $self->license
70             ));
71             };
72              
73             has copy_file_from_release => (
74             isa => 'ArrayRef[Str]',
75             init_arg => undef,
76             lazy => 1,
77             default => sub { $_[0]->payload->{copy_file_from_release} // [] },
78             traits => ['Array'],
79             handles => { copy_files_from_release => 'elements' },
80             );
81              
82              
83             around copy_files_from_release => sub {
84             my $orig = shift;
85             my $self = shift;
86             sort(uniq(
87             $self->$orig(@_),
88             qw(CONTRIBUTING ppport.h INSTALL)
89             ));
90             };
91              
92             has debug => (
93             is => 'ro',
94             isa => 'Bool',
95             init_arg => undef,
96             lazy => 1,
97             default =>
98             sub { $ENV{DZIL_AUTHOR_DEBUG} // $_[0]->payload->{debug} // 0 },
99             );
100              
101             has upload_to => (
102             is => 'ro',
103             isa => enum([qw(cpan pause stratopan local)]),
104             init_arg => undef,
105             lazy => 1,
106             default => sub { $_[0]->payload->{upload_to} // 'cpan' },
107             );
108              
109             has authority => (
110             is => 'ro',
111             isa => 'Str',
112             init_arg => undef,
113             lazy => 1,
114             default => sub {
115             my $self = shift;
116             $self->payload->{authority} // 'cpan:WATERKIP';
117             },
118             );
119              
120             has fake_release => (
121             is => 'ro',
122             isa => 'Bool',
123             init_arg => undef,
124             lazy => 1,
125             default =>
126             sub { $ENV{FAKE_RELEASE} // $_[0]->payload->{fake_release} // 0 },
127             );
128              
129             has changes_version_columns => (
130             is => 'ro',
131             isa => subtype('Int', where { $_ > 0 && $_ < 20 }),
132             init_arg => undef,
133             lazy => 1,
134             default => sub { $_[0]->payload->{changes_version_columns} // 10 },
135             );
136              
137             my $msg = shift;
138             warn(sprintf("[\@Author::WATERKIP] %s\n", $msg));
139             }
140 0     0      
141 0           my $self = shift;
142             grep { -e }
143             sort(uniq('README.pod', 'Changes', $self->copy_files_from_release, $self->copy_files_from_build));
144             }
145 0     0 1    
146 0           return [qw(
  0            
147             PromptIfStale
148             Test::Pod::LinkCheck
149             Test::Pod::No404s
150             Git::Remote::Check
151 0     0 1   CheckPrereqsIndexed
152             CheckIssues
153             UploadToCPAN
154             UploadToStratopan
155             Git::Push
156             )];
157             };
158              
159             my %removed;
160              
161             my $self = shift;
162             if ($self->fake_release) {
163             _warn_me("Fake release has been set");
164             return 'FakeRelease';
165             }
166             if ($self->upload_to eq 'stratopan') {
167 0     0 1   _warn_me("Stratopan release has been set");
168 0 0         my $prefix = 'stratopan';
169 0           return [
170 0           'UploadToStratopan' => {
171             repo => $self->payload->{"$prefix.repo"},
172 0 0         stack => $self->payload->{"$prefix.stack"},
173 0           recurse => $self->payload->{"$prefix.recurse"},
174 0           }
175             ],
176             ;
177             }
178             return 'UploadToCPAN';
179 0           }
180              
181             my $self = shift;
182              
183             if ($self->debug) {
184 0           _warn_me(Dumper { payload => $self->payload, });
185             }
186              
187             if (!-d '.git' and -f 'META.json' and !exists $removed{'Git::GatherDir'})
188 0     0 1   {
189             _warn_me(
190 0 0         '.git is missing and META.json is present -- this looks like a CPAN download rather than a git repository. You should probably run '
191 0           . (
192             -f 'Build.PL'
193             ? 'perl Build.PL; ./Build'
194 0 0 0       : 'perl Makefile.PL; make'
      0        
195             )
196 0 0         . ' instead of using dzil commands!',
197             );
198             }
199              
200             my @plugins = (
201              
202             [
203             'Git::GatherDir' => {
204             do {
205             my @filenames = uniq(
206             grep { -e } $self->copy_files_from_release,
207             $self->copy_files_from_build,
208             $self->exclude_files,
209             );
210             @filenames ? (exclude_filename => \@filenames) : ();
211 0 0         },
212             },
213 0           ],
  0            
214              
215             [
216             'PromptIfStale' => 'stale modules, build' =>
217 0 0         { phase => 'build', module => [$self->meta->name] }
218             ],
219             [
220             'PromptIfStale' => 'stale modules, release' => {
221             phase => 'release',
222             check_all_plugins => 1,
223             check_all_prereqs => 1
224             }
225             ],
226              
227             qw(PruneCruft ManifestSkip MetaYAML MetaJSON),
228              
229             ['License' => { filename => $self->license }],
230              
231             ['ReadmeFromPod' => { type => 'markdown', readme => 'README.md' }],
232              
233             qw(ExecDir ShareDir MakeMaker Manifest
234             TestRelease PodWeaver),
235              
236             ['Git::Contributors' => { order_by => 'commits' }],
237             ['ContributorsFile' => { filename => 'CONTRIBUTORS' }],
238              
239             ['AutoPrereqs' => { skip => [qw(^perl$ utf8 warnings strict overload feature autodie base)] }],
240             ['Prereqs::AuthorDeps' => { ':version' => '0.006' }],
241             [
242             'MinimumPerl' => {
243             ':version' => '1.006',
244             configure_finder => ':NoFiles'
245             }
246             ],
247             ['MetaProvides::Package'],
248              
249             [
250             'Encoding' => [
251             encoding => 'bytes',
252             match => '\.ico$',
253             match => '\.docx?$',
254             match => '\.zip$',
255             match => '\.ztb$', # Mintlab specific, just a zip file
256             match => '\.pdf$',
257             match => '\.odt$',
258             match => '\.msg$',
259             match => '\.gz$',
260             ]
261             ],
262              
263             ['CPANFile'],
264              
265             [
266             'CopyFilesFromBuild::Filtered' =>
267             { copy => [$self->copy_files_from_build] }
268             ],
269              
270             [ 'Git::Check' => 'initial check' => { allow_dirty => [ $self->airplane ? 'dist.ini' : '' ] } ],
271              
272             qw(Git::CheckFor::MergeConflicts),
273             ['Git::Remote::Check' => { branch => 'master', remote_branch => 'master' } ],
274             ['Git::CheckFor::CorrectBranch' =>
275             { release_branch => 'master' }
276             ],
277              
278             qw(CheckPrereqsIndexed),
279              
280             ['Repository'],
281             ['ConfirmRelease'],
282              
283             # This plugin seems cool, but also unmaintained with downstream
284             # deps which are also unmaintained. ABORT
285             #[ 'PrereqsClean'],
286              
287             $self->release_option,
288              
289             [
290             'CopyFilesFromRelease' =>
291             { filename => [$self->copy_files_from_release] }
292             ],
293             );
294              
295             # Disable test::perl::critic as it messes with the version rewrite
296             # that happens during a build
297             # Also disable portability files as foo.conf.dist is not allowed :(
298             $self->add_bundle(
299             '@TestingMania' => {
300             disable => [
301             qw(
302             Test::Perl::Critic
303             Test::Portability::Files
304             Test::Portability
305 0           )
306             ]
307             }
308             );
309              
310             # plugins to do with calculating, munging, incrementing versions
311             $self->add_bundle(
312             '@Git::VersionManager' => {
313             'RewriteVersion::Transitional.global' => 1,
314             'RewriteVersion::Transitional.fallback_version_provider' =>
315             'Git::NextVersion',
316             'RewriteVersion::Transitional.version_regexp' =>
317             '^v([\d._]+)(-TRIAL)?$',
318 0            
319             # for first Git::Commit
320             commit_files_after_release => [$self->commit_files_after_release],
321              
322             # because of [Git::Check], only files copied from the release would
323             # be added -- there is nothing else hanging around in the current
324             # directory
325             'release snapshot.add_files_in' => ['.'],
326             'release snapshot.commit_msg' => '%N-%v%t%n%n%c',
327              
328             'Git::Tag.tag_message' => 'v%v%t',
329              
330             'BumpVersionAfterRelease::Transitional.global' => 1,
331              
332             'NextRelease.:version' => '5.033',
333             'NextRelease.time_zone' => 'UTC',
334             'NextRelease.format' => '%-'
335             . ($self->changes_version_columns - 2)
336             . 'v %{yyyy-MM-dd HH:mm:ss\'Z\'}d%{ (TRIAL RELEASE)}T',
337             }
338             );
339             $self->add_plugins(@plugins);
340              
341             }
342              
343              
344             __PACKAGE__->meta->make_immutable;
345              
346 0            
347             =pod
348              
349             =encoding UTF-8
350              
351             =head1 NAME
352              
353             Dist::Zilla::PluginBundle::Author::WATERKIP - An plugin bundle for all distributions by WATERKIP
354              
355             =head1 VERSION
356              
357             version 3.1
358              
359             =head1 SYNOPSIS
360              
361             In your F<dist.ini>:
362              
363             [@Author::WATERKIP]
364              
365             =head1 DESCRIPTION
366              
367             This is a L<Dist::Zilla> plugin bundle. It is somewhat equal to the
368             following F<dist.ini>:
369              
370             [Git::GatherDir]
371             exclude_filename = .dockerignore
372             exclude_filename = .gitlab-ci.yml
373             exclude_filename = Dockerfile
374             exclude_filename = docker-compose.override.yml
375             exclude_filename = docker-compose.yml
376              
377             [PromptIfStale 'stale modules, build']
378             phase = build
379             module = ... ; lookup syntax
380              
381             [PruneCruft]
382             [ManifestSkip]
383             [MetaYAML]
384             [MetaJSON]
385              
386             [License]
387             filename = LICENSE
388              
389             [ReadmeFromPod]
390             type = markdown
391             readme = README.md
392              
393             [ExecDir]
394             [ShareDir]
395             [MakeMaker]
396             [Manifest]
397             [TestRelease]
398             [PodWeaver]
399              
400             [Git::Contributors]
401             order_by = commits
402              
403             [ContributesFile]
404             filename = CONTRIBUTORS
405              
406             [AutoPrereqs]
407             skip = ^perl$, utf8, warnings, strict, overload
408              
409             [Prereqs::AuthorDeps]
410             [MinimumPerl]
411             configure_finder = :NoFiles
412              
413             [MetaProvides::Package]
414              
415             [Encoding]
416             encoding = bytes
417             match = \.ico$
418             match = \.docx?$
419             match = \.zip$
420             match = \.ztb$ ; Mintlab specific
421             match = \.pdf$
422             match = \.odt$
423              
424             [CPANFile]
425              
426             [CopyFilesFromBuild::Filtered]
427             copy = cpanfile, Makefile.pl, CONTRIBUTORS, LICENSE, README.md
428              
429             [Git::Check 'initial check']
430             allow_dirty = dist.ini; only if airplane mode is set
431              
432             [Git::CheckFor::MergeConflicts]
433             [Git::Remote::Check]
434             branch = master
435             remote_branch = master
436              
437             [Git::CheckFor::CorrectBranch]
438             release_branch = master
439              
440             [CheckPrereqsIndexed]
441              
442             [Repository]
443             [ConfirmRelease]
444              
445             [CopyFilesFromRelease]
446             filename = cpanfile, Makefile.pl, CONTRIBUTORS, LICENSE, README.md
447              
448             [@TestingMania]
449             disable = Test::Perl::Critic
450             disable = Test::Portability::Files
451             disable = Test::Portability
452              
453             [@Git::VersionManager]
454             RewriteVersion::Transitional.global = 1
455             RewriteVersion::Transitional.fallback_version_provider = Git::NextVersion
456             RewriteVersion::Transitional.version_regexp = ^v([\d._]+)(-TRIAL)?$
457              
458             commit_files_after_release = Changes LICENSE README.md
459              
460             release snapshot.add_files_in = .
461             release snapshot.commit_msg = %N-%v%t%n%n%c
462              
463             Git::Tag.tag_message = v%v%t
464              
465             BumpVersionAfterRelease::Transitional.global = 1
466              
467             NextRelease.time_zone = UTC
468             NextRelease.format = %-8v %{yyyy-MM-dd HH:mm:ss\'Z\'}d%{ (TRIAL RELEASE)}T'
469              
470             =head1 METHODS
471              
472             =head2 configure
473              
474             Configure the author plugin
475              
476             =head2 commit_files_after_release
477              
478             Commit files after a release
479              
480             =head2 release_option
481              
482             Define the release options. Choose between:
483              
484             C<cpan> or C<stratopan>. When fake release is used, this overrides these two options
485              
486             =head2 build_network_plugins
487              
488             Builder for network plugins
489              
490             =head1 SEE ALSO
491              
492             I took inspiration from L<Dist::Zilla::PluginBundle::Author::ETHER>
493              
494             =head1 AUTHOR
495              
496             Wesley Schwengle <waterkip@cpan.org>
497              
498             =head1 COPYRIGHT AND LICENSE
499              
500             This software is copyright (c) 2017 by Wesley Schwengle.
501              
502             This is free software; you can redistribute it and/or modify it under
503             the same terms as the Perl 5 programming language system itself.
504              
505             =cut