Dist/Zilla/PluginBundle/Author/MAXHQ.pm untested

filter: Statementstmt 0.0% 0 / 142 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 203 CC 13 SCAR 24.3
CC
13
Cov
0%
register_prereqs
30.0
configure
20.0
add_plugins_if_wanted
12.0
CRAP 11.3
1 use strict;
2 package Dist::Zilla::PluginBundle::Author::MAXHQ;
3 # ABSTRACT: MAXHQ's default Dist::Zilla configuration
4 $Dist::Zilla::PluginBundle::Author::MAXHQ::VERSION = '3.3.3';
5 #pod =encoding UTF-8
6 #pod
7 #pod =head1 SYNOPSIS
8 #pod
9 #pod Put following into your C<My-Module/dist.ini>:
10 #pod
11 #pod [@Author::MAXHQ]
12 #pod GatherDir.exclude_match = ^[^\/\.]+\.txt$
13 #pod PodWeaver.replacer = replace_with_nothing
14 #pod ReadmeAnyFromPod = no
15 #pod
16 #pod =head2 DESCRIPTION
17 #pod
18 #pod The bundles' behaviour can be altered by the following options:
19 #pod
20 #pod =for :list
21 #pod * C<GatherDir.exclude_match> - a regex specifying which files or directories to
22 #pod ignore (they are not processed and thus not added to the distribution tarball).
23 #pod This option can be specified several times for different regexes.
24 #pod * C<PodWeaver.replacer> - Which replacer to use for POD sections.
25 #pod See L<Pod::Elemental::PerlMunger>.
26 #pod Currently possible values: "replace_with_nothing",
27 #pod "replace_with_comment" (default), "replace_with_blank"
28 #pod
29 #pod =head1 OVERVIEW
30 #pod
31 #pod Currently this plugin bundle is equivalent to:
32 #pod
33 #pod #
34 #pod # Include files tracked by Git with some exceptions
35 #pod #
36 #pod [Git::GatherDir]
37 #pod exclude_match = ^cpanfile$
38 #pod exclude_match = ^cpanfile.snapshot$
39 #pod exclude_match = \A[^\/]+\.ini\Z
40 #pod exclude_match = \A[^\/]+\.tar\.gz\Z
41 #pod exclude_match = ^\.build\b
42 #pod exclude_match = ^\.git\b
43 #pod exclude_match = ^\.svn\b
44 #pod exclude_match = ^extlib\b
45 #pod exclude_match = ^local\b
46 #pod exclude_match = ^CVS\b
47 #pod include_dotfiles = 1
48 #pod
49 #pod [PruneCruft]
50 #pod [ExecDir]
51 #pod dir = bin
52 #pod
53 #pod [ShareDir]
54 #pod dir = share/dist/My-Module
55 #pod
56 #pod #
57 #pod # Conversion and replacements
58 #pod #
59 #pod [Authority]
60 #pod
61 #pod [PkgVersion]
62 #pod die_on_existing_version = 1
63 #pod die_on_line_insertion = 1
64 #pod
65 #pod [NextRelease]
66 #pod format = '%-9v %{yyyy-MM-dd}d'
67 #pod
68 #pod [PreviousVersion::Changelog]
69 #pod [NextVersion::Semantic]
70 #pod major = *NEW FEATURES, *API CHANGES
71 #pod minor = +ENHANCEMENTS
72 #pod revision = REVISION, BUG FIXES, DOCUMENTATION
73 #pod numify_version = 1
74 #pod format = %d.%03d%03d
75 #pod
76 #pod [PodWeaver]
77 #pod config_plugin = @Author::MAXHQ
78 #pod replacer = replace_with_comment
79 #pod
80 #pod #
81 #pod # Prerequisites
82 #pod #
83 #pod [Prereqs::FromCPANfile]
84 #pod [Prereqs::AuthorDeps]
85 #pod [AutoPrereqs]
86 #pod
87 #pod [Prereqs / MAXHQ]
88 #pod -phase = runtime
89 #pod -relationship = requires
90 #pod Pod::Elemental::Transformer::List = 0.102000
91 #pod
92 #pod [Prereqs / MAXHQ-DEV]
93 #pod -phase = devlop
94 #pod -relationship = requires
95 #pod Pod::Coverage::TrustPod = 0.100003
96 #pod
97 #pod [RemovePrereqs]
98 #pod remove = strict
99 #pod
100 #pod [CheckSelfDependency]
101 #pod
102 #pod #
103 #pod # Auto generation --- meta info
104 #pod #
105 #pod [Authority]
106 #pod do_munging = 0
107 #pod [MetaProvides::Package]
108 #pod [MetaConfig]
109 #pod
110 #pod #
111 #pod # Auto generation --- generate files
112 #pod #
113 #pod [ModuleBuild]
114 #pod [MetaYAML]
115 #pod [MetaJSON]
116 #pod [Manifest]
117 #pod [License]
118 #pod [ReadmeAnyFromPod]
119 #pod [CPANFile]
120 #pod
121 #pod [MetaNoIndex]
122 #pod directory = t
123 #pod directory = xt
124 #pod directory = inc
125 #pod directory = share
126 #pod directory = eg
127 #pod directory = examples
128 #pod
129 #pod #
130 #pod # Auto generation --- tests
131 #pod #
132 #pod [Test::Inline]
133 #pod [RunExtraTests]
134 #pod [Test::Perl::Critic]
135 #pod [PodSyntaxTests]
136 #pod [Test::Pod::Coverage::Configurable]
137 #pod [Test::Pod::No404s]
138 #pod [Test::Pod::LinkCheck]
139 #pod [Test::EOL]
140 #pod [Test::NoTabs]
141 #pod
142 #pod #
143 #pod # Copy files back into project dir
144 #pod #
145 #pod [CopyFilesFromBuild]
146 #pod copy = cpanfile
147 #pod
148 #pod #
149 #pod # Release
150 #pod #
151 #pod [TestRelease]
152 #pod
153 #pod [Git::Check]
154 #pod allow_dirty => cpanfile
155 #pod
156 #pod [Git::Commit]
157 #pod allow_dirty => cpanfile
158 #pod allow_dirty => Changes
159 #pod commit_msg = Release %v%n%n%c
160 #pod
161 #pod [Git::Tag]
162 #pod tag_format = %v
163 #pod ;# make a lightweight tag
164 #pod tag_message =
165 #pod [Git::Push]
166 #pod
167 #pod [ConfirmRelease]
168 #pod
169 #pod =cut
170  
171 use Moose;
172  
173 # choose the easy way of configuring a plugin bundle
174 with 'Dist::Zilla::Role::PluginBundle::Easy';
175  
176  
177  
178 #pod =for Pod::Coverage mvp_multivalue_args
179 #pod
180 #pod =cut
181 #
182 #"If you want a configuration option that takes more than one value, you'll need
183 #to mark it as multivalue arg by having its name returned by
184 #C<mvp_multivalue_args>."
185 #
186 #Queried by L<Dist::Zilla>.
187 #
188 sub mvp_multivalue_args { return qw(GatherDir.exclude_match) }
189  
190 #pod =for Pod::Coverage _warn
191 #pod
192 #pod =cut
193 sub _warn {
194 my $name = __PACKAGE__;
195 $name =~ s/^Dist::Zilla::PluginBundle:://;
196 warn sprintf("[%s] %s\n", $name, join("", @_));
197 }
198  
199 #pod =method add_plugins_if_wanted
200 #pod
201 #pod Adds the given plugins unless there is a configuration option given to the
202 #pod plugin bundle that tells not to use it.
203 #pod
204 #pod E.g. plugin 'PruneCruft' is used unless the following is given:
205 #pod
206 #pod [@Author::MAXHQ]
207 #pod PruneCruft = no
208 #pod
209 #pod =cut
210 sub add_plugins_if_wanted {
211 my ($self, @plugin_specs) = @_;
212  
213 my @plugin_specs_filtered = ();
214 foreach my $this_spec (@plugin_specs) {
215 my $moniker = ref $this_spec ? $this_spec->[0] : $this_spec;
216 # skip plugin if told by user
217 if (grep { $moniker =~ /^\Q$_\E$/ && $self->payload->{$_} =~ /^no$/i } keys %{$self->payload}) {
218 _warn("Skipping plugin $moniker");
219 next;
220 }
221 # otherwise add to list
222 push @plugin_specs_filtered, $this_spec;
223 }
224 $self->add_plugins(@plugin_specs_filtered);
225 }
226  
227 #pod =for Pod::Coverage configure
228 #pod
229 #pod =cut
230 #
231 #Required by role L<Dist::Zilla::Role::PluginBundle::Easy>.
232 #
233 #Configures the plugins of this bundle.
234 #
235 sub configure {
236 my $self = shift;
237  
238 # build this array by merging...
239 my @exclude_matches = (
240 # ...the parameter (or an empty ref)
241 @{ $self->payload->{'GatherDir.exclude_match'} || [] },
242 # ...with the default options (exclude certain files at top level)
243 # note: cpanfile is parsed by [Prereqs::FromCPANfile] and the release version created
244 # note: each subdir is matched separately, i.e. not the whole file path
245 qw(
246 ^cpanfile$
247 ^cpanfile.snapshot$
248 ^(?!(dist|weaver)\.ini)\w+\.ini$
249 ^\w+\.tar\.gz$
250 ^extlib$
251 ^local$
252 ^\.build$
253 ^\.git$
254 ^\.svn$
255 ^CVS$
256 )
257 );
258  
259 my $build_myself = $self->payload->{build_myself};
260  
261 $self->add_plugins_if_wanted(
262 #
263 # Files included
264 #
265 ['Git::GatherDir' => { # skip files on top level
266 exclude_match => [ @exclude_matches ],
267 include_dotfiles => 1, # needed e.g. for ".devdir",
268 }],
269 'PruneCruft', # prune stuff you probably don't want
270  
271 ['ExecDir' => { # install contents of bin/ as executable
272 dir => 'bin',
273 }],
274 'ShareDir::ProjectDistDir', # include all files in /share/dist/My-Dist
275  
276 #
277 # Conversion and replacements
278 #
279 ['PkgVersion' => { # insert version number in first blank line
280 die_on_existing_version => 1,
281 die_on_line_insertion => 1,
282 }],
283 ['NextRelease' => { # replace {{$NEXT}} in "Changes" file with new version and
284 format => '%-9v %{yyyy-MM-dd}d', # date (MUST be included before NextVersion::Semantic)
285 }],
286 'PreviousVersion::Changelog', # fetch previous version from changelog
287 # alternatively run: V=0.00100 dzil release
288 ['NextVersion::Semantic' => { # generate next version based on type of changes
289 major => '*NEW FEATURES, *API CHANGES',
290 minor => '+ENHANCEMENTS',
291 revision => 'REVISION, BUG FIXES, DOCUMENTATION',
292 format => '%d.%3d.%3d',
293 }],
294 # Please note that * and ! are mainly there to enforce correct ordering
295 # as CPAN::Changes::Release (used in NextVersion::Semantic) just sorts
296 # groups alphabetically
297  
298 # weave your Pod together from configuration and Dist::Zilla
299 # (turns "# ABSTRACT" into POD, processes =method and short lists etc.)
300 # To exclude files from PodWeaver see: http://blogs.perl.org/users/polettix/2011/11/distzilla-podweaver-and-bin.html
301 ['PodWeaver' => {
302 config_plugin => '@Author::MAXHQ',
303 replacer =>
304 $self->payload->{'PodWeaver.replacer'}
305 || 'replace_with_comment', # replace original POD with comments to preserve line numbering
306  
307 }],
308  
309 #
310 # Prerequisites
311 #
312 !$build_myself
313 ? 'Prereqs::FromCPANfile' # use prereqs from "cpanfile"
314 : ['Prereqs' => { 'Dist::Zilla::Plugin::Prereqs::FromCPANfile' => 0 }], # add manually because [MAXHQ::BundleDepsDeep] wont see it
315 'AutoPrereqs', # collect prereqs from modules
316 ['RemovePrereqs' => {
317 'remove' => [ qw( strict warnings ) ],
318 }],
319  
320 'CheckSelfDependency', # Make sure no packages of this dist ended up in the prerequisites list
321  
322 #
323 # Auto generation --- meta info
324 #
325 ['Authority' => { # Add authority
326 'do_munging' => 0,
327 }],
328 'MetaProvides::Package', # specify provided packages in META.* instead of letting PAUSE figure them out
329 'MetaConfig', # add Dist::Zilla info to META.*
330  
331 #
332 # Auto generation --- generate files
333 #
334 'ModuleBuildTiny', # add Build.PL that will use Module::Build::Tiny to install the distribution
335 'Manifest', # add Manifest (list of all files)
336 'MetaYAML', # add META.yml (supports CPAN::Meta::Spec v1.4)
337 'MetaJSON', # add META.json (supports CPAN::Meta::Spec v2.0 upwards)
338 'CPANFile', # add "cpanfile"
339 'License', # add LICENSE
340 'ReadmeAnyFromPod', # add README (with dist's name, version, abstract, license)
341 ['MetaNoIndex' => { # prevent CPAN from indexing these files (taken from https://metacpan.org/pod/Dist::Zilla::PluginBundle::Starter)
342 'directory' => [ qw( t xt inc share eg examples ) ],
343 $build_myself # don't index private modules of this bundle
344 ? ( 'package' => [ qw(
345 Dist::Zilla::Plugin::ShareDir::ProjectDistDir
346 Dist::Zilla::Plugin::MAXHQ::BundleDepsDeep
347 ) ] )
348 : (),
349 }],
350  
351 #
352 # Auto generation --- tests
353 #
354 'Test::Inline', # generate .t files from inline test code (POD)
355  
356 # auto-generate various tests
357 'RunExtraTests',
358 'Test::Perl::Critic',
359 'Test::Pod::Coverage::Configurable',
360 'PodSyntaxTests',
361 'Test::Pod::No404s',
362 'Test::Pod::LinkCheck',
363 'Test::EOL',
364 'Test::NoTabs',
365  
366 #
367 # Replacement of files in project dir
368 #
369 [ 'CopyFilesFromBuild' => { # copy cpanfile back into project dir
370 'copy' => 'cpanfile',
371 }],
372  
373 #
374 # Release
375 #
376 'TestRelease', # test before releasing
377  
378 ['Git::Check' => { # check for dirty files etc.
379 'allow_dirty' => 'cpanfile', # ignore cpanfile because we copy it back from release
380 }],
381 ['Git::Commit' => {
382 'allow_dirty' => [
383 'cpanfile', # add cpanfile because we copy it back from release
384 'Changes', # add Changes because it's modified by [NextRelease]
385 ],
386 'commit_msg' => 'Release %v%n%n%c',
387 }],
388 ['Git::Tag' => {
389 'tag_format' => '%v',
390 'tag_message' => '', # make a lightweight tag
391 }],
392 'Git::Push',
393  
394 'ConfirmRelease', # ask for confirmation before releasing
395  
396 # almost at the end to capture all other plugins
397 $build_myself ? 'MAXHQ::BundleDepsDeep' : (),
398 # after [MAXHQ::BundleDepsDeep] so that dependencies are not copied to phase "runtime"
399 'Prereqs::AuthorDeps', # "adds Dist::Zilla and the result of "dzil
400 # authordeps" to the 'develop' phase prerequisite list"
401 );
402 }
403  
404 no Moose;
405 __PACKAGE__->meta->make_immutable;
406  
407 {
408 package Dist::Zilla::Plugin::ShareDir::ProjectDistDir;
409 # ABSTRACT: install "ShareDir" content and make other modules happy
410 $Dist::Zilla::Plugin::ShareDir::ProjectDistDir::VERSION = '3.3.3';
411 # fullfill File::ShareDir::ProjectDistDir strict mode and be compatible with Module::Build::Tiny
412  
413 use Moose;
414 use namespace::autoclean;
415  
416 with 'Dist::Zilla::Role::FileMunger';
417 with 'Dist::Zilla::Role::ShareDir';
418  
419 use File::Spec;
420  
421 # FileMunger plugins are executed before ShareDir plugins, so the ShareDir
422 # code below will see the already moved files.
423  
424 # In contrast to Dist::Zilla::Plugin::ShareDir we use this for the munger
425 has dir => (
426 is => 'ro',
427 isa => 'Str',
428 lazy => 1,
429 default => sub {
430 my ($self) = @_;
431 return File::Spec->catfile('share', 'dist', $self->zilla->name);
432 },
433 );
434  
435 #
436 # ShareDir code
437 #
438 sub find_files { # Required by Dist::Zilla::Role::ShareDir
439 my ($self) = @_;
440 return [
441 grep { index($_->name, "share/") == 0 } @{ $self->zilla->files }
442 ];
443 }
444  
445 sub share_dir_map {
446 my ($self) = @_;
447 my $files = $self->find_files;
448 return unless @$files;
449 return { dist => "share" };
450 }
451  
452 #
453 # FileMunger code
454 #
455 # Moves files from share/dist/My-Dist to share/ to comply with Module::Build::Tiny
456 sub munge_files {
457 my ($self) = @_;
458 for my $file (@{ $self->zilla->files }) {
459 my @dirs = File::Spec->splitdir($file->name);
460 # process files under share/
461 next unless $dirs[0] eq "share";
462 # if the sharedir equals $self->dir (i.e. share/dist/My-Dist per default)
463 if (File::Spec->catdir(@dirs[0..2]) eq $self->dir) {
464  
465 splice(@dirs, 1, 2);
466 $file->name( File::Spec->catdir(@dirs) );
467 }
468 }
469 }
470  
471 __PACKAGE__->meta->make_immutable;
472 }
473  
474 {
475 package Dist::Zilla::Plugin::MAXHQ::BundleDepsDeep;
476 # ABSTRACT: register all needed plugins in a bundle as runtime requirements
477 $Dist::Zilla::Plugin::MAXHQ::BundleDepsDeep::VERSION = '3.3.3';
478 use Moose;
479 use namespace::autoclean;
480  
481 with 'Dist::Zilla::Role::PrereqSource';
482  
483 use Module::Metadata;
484 use Distribution::Metadata;
485  
486 sub register_prereqs {
487 my ($self) = @_;
488  
489 my $req = $self->zilla->prereqs; # class Dist::Zilla::Prereqs
490 my $cpan_req = $req->cpan_meta_prereqs; # class CPAN::Meta::Prereqs
491  
492 #
493 # Add all "develop" phase prerequisites as "runtime" prerequisites
494 # because they might have been injected by plugins (and we assume all
495 # plugins of the pluginbundle will be used later, so the prerequisites
496 # are needed.
497 #
498 $self->log("Copying plugins from phase 'develop' to 'runtime'");
499 my $devreq = $cpan_req->requirements_for('develop', 'requires'); # class CPAN::Meta::Requirements
500 my $devreq_str = $devreq->as_string_hash;
501 $self->zilla->register_prereqs(
502 {
503 phase => 'runtime',
504 type => 'requires',
505 },
506 %$devreq_str,
507 );
508  
509 #
510 # Add all active plugins as runtime requirements
511 # (if not already there with a version number)
512 #
513 $self->log("Registering currently used plugins as 'runtime' requirements");
514  
515 # Try to find list of Dist::Zilla's own packages
516 my $dzil_meta = Distribution::Metadata->new_from_module("Dist::Zilla");
517 my $dzil_pkg = {};
518 if ($dzil_meta->install_json) {
519 $self->log("Excluding packages of Dist::Zilla distribution");
520 $dzil_pkg = $dzil_meta->install_json_hash->{provides};
521 }
522  
523 # list of active plugins with currently installed versions
524 my $plugins = {
525 map {
526 my $mod = $_;
527 $mod = "Dist::Zilla" if $dzil_pkg->{$mod};
528 my $meta = Module::Metadata->new_from_module($mod);
529 $mod => $meta ? $meta->version->stringify : 0
530 }
531 map { ref } # get class name
532 @{$self->zilla->plugins} # RJBS mentions that this attribute might go away!
533 };
534  
535 my $runreq = $cpan_req->requirements_for('runtime', 'requires'); # class CPAN::Meta::Requirements
536 my $runreq_str = $runreq->as_string_hash;
537  
538 # add plugins as runtime requirements unless they're already defined
539 my $plugin_prereqs = {};
540 for my $module (sort keys %$plugins) {
541 my $ver = $runreq_str->{$module};
542 next if $ver; # don't overwrite specs coming from elsewhere
543 $plugin_prereqs->{$module} = $plugins->{$module};
544 }
545 $self->zilla->register_prereqs(
546 {
547 phase => 'runtime',
548 type => 'requires',
549 },
550 %$plugin_prereqs,
551 );
552 }
553  
554 __PACKAGE__->meta->make_immutable;
555 }
556  
557 1;
558  
559 __END__