File Coverage

blib/lib/Dist/Zilla/PluginBundle/Author/RTHOMPSON.pm
Criterion Covered Total %
statement 54 58 93.1
branch 23 34 67.6
condition 6 11 54.5
subroutine 8 8 100.0
pod 0 1 0.0
total 91 112 81.2


line stmt bran cond sub pod time code
1 1     1   424 use strict;
  1         1  
  1         23  
2 1     1   3 use warnings;
  1         1  
  1         20  
3 1     1   3 use feature 'switch';
  1         1  
  1         63  
4 1     1   470 use utf8;
  1         8  
  1         5  
5              
6             package Dist::Zilla::PluginBundle::Author::RTHOMPSON;
7             # ABSTRACT: RTHOMPSON's Dist::Zilla Configuration
8             $Dist::Zilla::PluginBundle::Author::RTHOMPSON::VERSION = '0.161990';
9 1     1   44 use Moose;
  1         2  
  1         6  
10 1     1   4700 use Carp;
  1         1  
  1         699  
11             with 'Dist::Zilla::Role::PluginBundle::Easy';
12             with 'Dist::Zilla::Role::PluginBundle::Config::Slicer';
13             with 'Dist::Zilla::Role::PluginBundle::PluginRemover';
14              
15             sub mvp_multivalue_args { qw( copy_file move_file allow_dirty ) }
16              
17             # Returns true for strings of 'true', 'yes', or positive numbers,
18             # false otherwise.
19             sub _parse_bool {
20 12   50 12   48 $_ ||= '';
21 12 100       80 return 1 if $_[0] =~ m{^(true|yes|1)$}xsmi;
22 2 50       14 return if $_[0] =~ m{^(false|no|0)$}xsmi;
23 0         0 die "Invalid boolean value $_[0]. Valid values are true/yes/1 or false/no/0";
24             }
25              
26             sub configure {
27 6     6 0 35295 my $self = shift;
28              
29 6         77 my $defaults = {
30             # AutoVersion by default
31             version => 'auto',
32             # Assume that the module is experimental unless told
33             # otherwise.
34             version_major => 0,
35             # Assume that synopsis is perl code and should compile
36             # cleanly.
37             synopsis_is_perl_code => 1,
38             # Realease to CPAN for real
39             release => 'real',
40             # Archive releases
41             archive => 1,
42             archive_directory => 'releases',
43             # version control system = git
44             vcs => 'git',
45             git_remote => 'origin',
46             git_branch => 'master',
47             allow_dirty => [ 'dist.ini', 'README.pod', 'Changes' ],
48             };
49 6         25 my %args = (%$defaults, %{$self->payload});
  6         206  
50              
51             # Add appropriate version plugin, if any
52 6 100       110 if (lc($args{version}) eq 'auto') {
    100          
53             $self->add_plugins(
54 3         20 [ 'AutoVersion' => { major => $args{version_major} } ]
55             );
56             }
57 12         30 elsif (grep { lc($args{version}) eq $_ } (qw(disable none false), q())) {
58 2         5 delete $args{version};
59             }
60             else {
61             $self->add_plugins(
62 1         7 [ 'StaticVersion' => { version => $args{version} } ]
63             );
64             }
65              
66             # Copy/move files from build dir. The "copy_file" and "move_file"
67             # arguments get passed to CopyFilesFromBuild as "copy" and "move"
68             # respectively.
69 6         434 my %cffb_opt_hash = ();
70 6         15 for my $opt ("copy", "move") {
71 12 100 66     45 if ($args{"${opt}_file"} and @{$args{"${opt}_file"}}) {
  2         10  
72 2         5 $cffb_opt_hash{$opt} = $args{"${opt}_file"};
73             }
74             }
75 6 100       24 if (keys %cffb_opt_hash) {
76 1         25 $self->add_plugins([ 'CopyFilesFromBuild' => \%cffb_opt_hash ]);
77             }
78              
79             # Decide whether to test SYNOPSIS for syntax.
80 6 100       93 if (_parse_bool($args{synopsis_is_perl_code})) {
81 5         21 $self->add_plugins('Test::Synopsis');
82             }
83              
84             # Choose release plugin
85 6         468 for ($args{release}) {
86 6 50       34 if (lc eq 'real') {
    50          
    0          
    0          
87 0         0 $self->add_plugins('UploadToCPAN')
88             }
89             elsif (lc eq 'fake') {
90 6         14 $self->add_plugins('FakeRelease')
91             }
92             elsif (lc eq 'none') {
93             # No release plugin
94             }
95             elsif ($_) {
96 0         0 $self->add_plugins("$_")
97             }
98             else {
99             # Empty string is the same as 'none'
100             }
101             }
102              
103             # Choose whether and where to archive releases
104 6 100       494 if (_parse_bool($args{archive})) {
105             $self->add_plugins(
106             ['ArchiveRelease' => {
107             directory => $args{archive_directory},
108 5         28 } ]
109             );
110             }
111              
112             # All the invariant plugins
113             $self->add_plugins(
114             # @Basic
115 6         482 'GatherDir',
116             'PruneCruft',
117             'ManifestSkip',
118             'MetaYAML',
119             'MetaJSON',
120             'License',
121             'ExecDir',
122             'ShareDir',
123             'MakeMaker',
124             'Manifest',
125              
126             # Add provides section to META.yml
127             'MetaProvides::Package',
128              
129             # Don't include the corpus directory, it's just for files that
130             # tests will run on
131             [ 'MetaNoIndex' => { dir => 'corpus' } ],
132              
133             # Mods
134             'PkgVersion',
135             # TODO: Only add PodWeaver if weaver.ini exists
136             'PodWeaver',
137              
138             # Generated Docs
139             'InstallGuide',
140             ['ReadmeAnyFromPod', 'ReadmeTextInBuild'],
141             # This one gets copied out of the build dir by default, and
142             # does not become part of the dist.
143             ['ReadmeAnyFromPod', 'ReadmePodInRoot ' => {
144             phase => 'release',
145             }],
146              
147             # Tests
148             'Test::Perl::Critic',
149             'PodCoverageTests',
150             'PodSyntaxTests',
151             'HasVersionTests',
152             'Test::Portability',
153             'Test::UnusedVars',
154             ['Test::Compile' => {
155             # The test files don't seem to compile in the context of
156             # this test. But it's ok, because if they really have
157             # problems, they'll fail to compile when they run.
158             skip => 'Test$',
159             }],
160             'Test::Kwalitee',
161             'ExtraTests',
162              
163             # Prerequisite checks
164             'ReportVersions',
165             'MinimumPerl',
166             'AutoPrereqs',
167              
168             # Release checks
169             'CheckChangesHasContent',
170             'CheckPrereqsIndexed',
171             'CheckVersionIncrement',
172              
173             # Release
174             'NextRelease',
175             'TestRelease',
176             );
177              
178             # Choose version control. This must be after 'NextRelease' so that
179             # the Changes file is updated before committing.
180 6         3285 for ($args{vcs}) {
181 6 50       33 if (lc eq 'none') {
    50          
182             # No-op
183             }
184             elsif (lc eq 'git') {
185             $self->add_plugins(
186             ['Git::Check' => {
187             allow_dirty => $args{allow_dirty},
188             } ],
189             [ 'Git::Commit' => {
190             allow_dirty => $args{allow_dirty},
191 6         35 } ],
192             'Git::Tag',
193             # This can't hurt. It's a no-op if github is not involved.
194             'GithubMeta',
195             );
196 6 50       778 if ($args{git_remote}) {
197 6 50 66     23 if (! $args{no_check_remote} && $args{git_branch}) {
198             $self->add_plugins(
199             ['Git::Remote::Check' => {
200             remote_name => $args{git_remote},
201             branch => $args{git_branch},
202             remote_branch => $args{git_remote_branch} || $args{git_branch},
203 5   33     43 } ],
204             );
205             }
206 6 100       418 if (! $args{no_push}) {
207             $self->add_plugins(
208             ['Git::Push' => {
209             push_to => $args{git_remote},
210 5         21 } ],
211             );
212             }
213             }
214             }
215             else {
216 0         0 croak "Unknown vcs: $_\nTry setting vcs = 'none' and setting it up yourself.";
217             }
218             }
219              
220             # This is added last so that the user is only asked for
221             # confimation if *all* other pre-release checkpoints have been
222             # passed.
223             $self->add_plugins(
224 6         404 'ConfirmRelease',
225             );
226             }
227              
228             1; # Magic true value required at end of module
229              
230             __END__
231              
232             =pod
233              
234             =head1 NAME
235              
236             Dist::Zilla::PluginBundle::Author::RTHOMPSON - RTHOMPSON's Dist::Zilla Configuration
237              
238             =head1 VERSION
239              
240             version 0.161990
241              
242             =head1 SYNOPSIS
243              
244             In dist.ini:
245              
246             [@Author::RTHOMPSON]
247              
248             =head1 DESCRIPTION
249              
250             This plugin bundle, in its default configuration, is equivalent to:
251              
252             [AutoVersion]
253             major = 0
254             [GatherDir]
255             [PruneCruft]
256             [ManifestSkip]
257             [MetaYAML]
258             [MetaJSON]
259             [MetaNoIndex]
260             dir = corpus
261             [License]
262             [ExecDir]
263             [ShareDir]
264             [MakeMaker]
265             [Manifest]
266             [MetaProvides::Package]
267             [PkgVersion]
268             [PodWeaver]
269             [InstallGuide]
270             [ReadmeAnyFromPod / ReadmeTextInBuild ]
271             [ReadmeAnyFromPod / ReadmePodInRoot ]
272             phase = release
273             [Test::Perl::Critic]
274             [PodCoverageTests]
275             [PodSyntaxTests]
276             [HasVersionTests]
277             [Test::Portability]
278             [Test::UnusedVars]
279             [Test::Compile]
280             skip = Test$
281             [Test::Kwalitee]
282             [ExtraTests]
283             [ReportVersions]
284             [MinimumPerl]
285             [AutoPrereqs]
286             [CheckChangesHasContent]
287             [CheckPrereqsIndexed]
288             [CheckVersionIncrement]
289             [NextRelease]
290             [TestRelease]
291             [ConfirmRelease]
292             [UploadToCPAN]
293             [ArchiveRelease]
294             directory = releases
295             [Git::Check]
296             allow_dirty = dist.ini
297             allow_dirty = README.pod
298             allow_dirty = Changes
299             [Git::Commit]
300             allow_dirty = dist.ini
301             allow_dirty = README.pod
302             allow_dirty = Changes
303             [Git::Tag]
304             [Git::Push]
305             push_to = origin
306             [Git::Remote::Check]
307             remote_name = origin
308             branch = master
309             remote_branch = master
310             [GithubMeta]
311              
312             There are several options that can change the default configuation,
313             though.
314              
315             =head1 OPTIONS
316              
317             =head2 -remove
318              
319             This option can be used to remove specific plugins from the bundle. It
320             can be used multiple times.
321              
322             Obviously, the default is not to remove any plugins.
323              
324             Example:
325              
326             ; Remove these two plugins from the bundle
327             -remove = Test::Perl::Critic
328             -remove = GithubMeta
329              
330             =head2 version, version_major
331              
332             This option is used to specify the version of the module. The default
333             is 'auto', which uses the AutoVersion plugin to choose a version
334             number. You can also set the version number manually, or choose
335             'disable' to prevent this bundle from supplying a version.
336              
337             Examples:
338              
339             ; Use AutoVersion (default)
340             version = auto
341             version_major = 0
342             ; Use manual versioning
343             version = 1.14.04
344             ; Provide no version, so that another plugin can handle it.
345             version = disable
346              
347             =head2 copy_file, move_file
348              
349             If you want to copy or move files out of the build dir and into the
350             distribution dir, use these two options to specify those files. Both
351             of these options can be specified multiple times.
352              
353             The most common reason to use this would be to put automatically
354             generated files under version control. For example, Github likes to
355             see a README file in your distribution, but if your README file is
356             auto-generated during the build, you need to copy each newly-generated
357             README file out of its build directory in order for Github to see it.
358              
359             If you want to include an auto-generated file in your distribution but
360             you I<don't> want to include it in the build, use C<move_file> instead
361             of C<copy_file>.
362              
363             By default, both of these options are unset.
364              
365             Example:
366              
367             copy_file = README
368             move_file = README.pod
369             copy_file = README.txt
370              
371             =head2 synopsis_is_perl_code
372              
373             If this is set to true (the default), then the SynopsisTests plugin
374             will be enabled. This plugin checks the perl syntax of the SYNOPSIS
375             sections of your modules. Obviously, if your SYNOPSIS section is not
376             perl code (case in point: this module), you should set this to false.
377              
378             Example:
379              
380             synopsis_is_perl_code = false
381              
382             =head2 release
383              
384             This option chooses the type of release to do. The default is 'real,'
385             which means "really upload the release to CPAN" (i.e. load the
386             C<UploadToCPAN> plugin). You can set it to 'fake,' in which case the
387             C<FakeRelease> plugin will be loaded, which simulates the release
388             process without actually doing anything. You can also set it to 'none'
389             if you do not want this module to load any release plugin, in which
390             case your F<dist.ini> file should load a release plugin directly. Any
391             other value for this option will be interpreted as a release plugin
392             name to be loaded.
393              
394             Examples:
395              
396             ; Release to CPAN for real (default)
397             release = real
398             ; For testing, you can do fake releases
399             release = fake
400             ; Or you can choose no release plugin
401             release = none
402             ; Or you can specify a specific release plugin.
403             release = OtherReleasePlugin
404              
405             =head2 archive, archive_directory
406              
407             If set to true, the C<archive> option copies each released version of
408             the module to an archive directory, using the C<ArchiveRelease>
409             plugin. This is the default. The name of the archive directory is
410             specified using C<archive_directory>, which is F<releases> by default.
411              
412             Examples:
413              
414             ; archive each release to the "releases" directory
415             archive = true
416             archive_directory = releases
417             ; Or don't archive
418             archive = false
419              
420             =head2 vcs
421              
422             This option specifies which version control system is being used for
423             the distribution. Integration for that version control system is
424             enabled. The default is 'git', and currently the only other option is
425             'none', which does not load any version control plugins.
426              
427             =head2 git_remote
428              
429             This option specifies the primary Git remote for the repository. The
430             default is 'origin'. To disable all Git remote operations, set this to
431             an empty string.
432              
433             =head2 git_branch, git_remote_branch
434              
435             This option specifies the branch that is to be checked against its
436             remote. The default is 'master'. The second option,
437             C<git_remote_branch>, is only needed if the remote branch has a
438             different name. It will default to being the same as C<git_branch>.
439              
440             =head2 no_check_remote
441              
442             By default, the Git branch C<git_branch> will be checked against the
443             remote branch C<git_remote_branch> at the remote specified by
444             C<git_remote> using the C<Git::Remote::Check> plugin. If the remote
445             branch is ahead of the local branch, the release process will be
446             aborted. This option disables the check, allowing a release to happen
447             even if the check would fail. This option has no effect if either
448             C<git_remote> or C<git_branch> is set to an empty string.
449              
450             =head2 no_push
451              
452             By default, the Git repo will be pushed to the remote specified by
453             C<git_remote> after every release, to ensure that the remote
454             repository contains the latest release. To disable pushing after a
455             release, set this option. This option has no effect if git_remote is
456             set to an empty string.
457              
458             =head2 allow_dirty
459              
460             This corresponds to the option of the same name in the Git::Check and
461             Git::Commit plugins. Briefly, files listed in C<allow_dirty> are
462             allowed to have changes that are not yet committed to git, and during
463             the release process, they will be checked in (committed).
464              
465             The default is F<dist.ini>, F<Changes>, and F<README.pod>. If you
466             override the default, you must include these files manually if you
467             want them.
468              
469             This option only has an effect if C<vcs> is 'git'.
470              
471             =head2 PLUGIN-SPECIFIC OPTIONS
472              
473             This bundle consumes the
474             C<Dist::Zilla::Role::PluginBundle::Config::Slicer> role, which means
475             that you can specify any option to any plugin in the bundle directly
476             by prefixing it with the plugin's name. This allows you to configure
477             any options not covered by the above. For example, if you want to
478             select "scripts" as the directory for the ExecDir plugin, you would
479             specify the option as C<ExecDir.dir = "scripts">.
480              
481             =for Pod::Coverage configure mvp_multivalue_args
482              
483             =head1 BUGS AND LIMITATIONS
484              
485             This module should be more configurable. Suggestions welcome.
486              
487             Please report any bugs or feature requests to
488             C<rct+perlbug@thompsonclan.org>.
489              
490             =head1 INSTALLATION
491              
492             See perlmodinstall for information and options on installing Perl modules.
493              
494             =head1 AUTHOR
495              
496             Ryan C. Thompson <rct@thompsonclan.org>
497              
498             =head1 COPYRIGHT AND LICENSE
499              
500             This software is copyright (c) 2010 by Ryan C. Thompson.
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             =head1 DISCLAIMER OF WARRANTY
506              
507             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
508             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
509             WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
510             PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
511             EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
512             IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
513             PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
514             SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME
515             THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
516              
517             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
518             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
519             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
520             TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
521             CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
522             SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
523             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
524             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
525             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
526             DAMAGES.
527              
528             =cut