| 1 | ## no critic | ||||||||||
| 2 | package Dist::Zilla::Plugin::CheckVersionIncrement; | ||||||||||
| 3 | { | ||||||||||
| 4 | 1 | $Dist::Zilla::Plugin::CheckVersionIncrement::VERSION = '0.121750'; | |||||||||
| 5 | } | ||||||||||
| 6 | ## use critic | ||||||||||
| 7 | # ABSTRACT: Prevent a release unless the version number is incremented | ||||||||||
| 8 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | with 'Dist::Zilla::Role::BeforeRelease'; | |||||||||
| 11 | 1 | ▶ | use Encode qw(encode_utf8); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use version (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use JSON::PP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | # Lots of this is cargo-culted from DZP::CheckPrereqsIndexed | ||||||||||
| 18 | 0 | ▶ | sub before_release { | ||||||||
|
Subroutine
before_release: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||
| 19 | 0 | my ($self) = @_; | |||||||||
| 20 | |||||||||||
| 21 | 0 | my $pkg = $self->zilla->name; | |||||||||
| 22 | 0 | $pkg =~ s/-/::/g; | |||||||||
| 23 | ### $pkg | ||||||||||
| 24 | |||||||||||
| 25 | 0 | my $pkg_version = version->parse($self->zilla->version); | |||||||||
| 26 | 0 | my $indexed_version; | |||||||||
| 27 | |||||||||||
| 28 | 0 | my $ua = LWP::UserAgent->new(keep_alive => 1); | |||||||||
| 29 | 0 | $ua->env_proxy; | |||||||||
| 30 | 0 | my $res = $ua->get("http://cpanidx.org/cpanidx/json/mod/$pkg"); | |||||||||
| 31 | 0 | ▶ | if ($res->is_success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | my $yaml_octets = encode_utf8($res->decoded_content); | |||||||||
| 33 | 0 | my $payload = JSON::PP->new->decode($yaml_octets); | |||||||||
| 34 | 0 | ▶ | if (@$payload) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | $indexed_version = version->parse($payload->[0]{mod_vers}); | |||||||||
| 36 | } | ||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | if ($indexed_version) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | ▶ | return if $indexed_version < $pkg_version; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | |||||||||||
| 42 | 0 | my $indexed_description; | |||||||||
| 43 | 0 | ▶ | if ($indexed_version == $pkg_version) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | $indexed_description = "the same version ($indexed_version)"; | |||||||||
| 45 | } | ||||||||||
| 46 | else { | ||||||||||
| 47 | 0 | $indexed_description = "a higher version ($indexed_version)"; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | return if $self->zilla->chrome->prompt_yn( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | "You are releasing version $pkg_version but $indexed_description is already indexed on CPAN. Release anyway?", | ||||||||||
| 52 | { default => 0 } | ||||||||||
| 53 | ); | ||||||||||
| 54 | 0 | $self->log_fatal("aborting release of version $pkg_version because $indexed_description is already indexed on CPAN"); | |||||||||
| 55 | } | ||||||||||
| 56 | else { | ||||||||||
| 57 | 0 | $self->log("Dist not indexed on CPAN. Skipping check for incremented version."); | |||||||||
| 58 | } | ||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 1 | 1; # Magic true value required at end of module | |||||||||
| 62 | |||||||||||
| 63 | |||||||||||
| 64 | =pod | ||||||||||
| 65 | |||||||||||
| 66 | =head1 NAME | ||||||||||
| 67 | |||||||||||
| 68 | Dist::Zilla::Plugin::CheckVersionIncrement - Prevent a release unless the version number is incremented | ||||||||||
| 69 | |||||||||||
| 70 | =head1 VERSION | ||||||||||
| 71 | |||||||||||
| 72 | version 0.121750 | ||||||||||
| 73 | |||||||||||
| 74 | =head1 SYNOPSIS | ||||||||||
| 75 | |||||||||||
| 76 | In your F<dist.ini> | ||||||||||
| 77 | |||||||||||
| 78 | [CheckVersionIncrement] | ||||||||||
| 79 | |||||||||||
| 80 | =head1 DESCRIPTION | ||||||||||
| 81 | |||||||||||
| 82 | This plugin prevents your from releasing a distribution unless it has | ||||||||||
| 83 | a version number I<greater> than the latest version already indexed on | ||||||||||
| 84 | CPAN. | ||||||||||
| 85 | |||||||||||
| 86 | Note that this plugin doesn't check whether your release method | ||||||||||
| 87 | actually involves the CPAN or not. So if you don't use the | ||||||||||
| 88 | UploadToCPAN plugin for releases, then you probably shouldn't use this | ||||||||||
| 89 | one either. | ||||||||||
| 90 | |||||||||||
| 91 | =head1 METHODS | ||||||||||
| 92 | |||||||||||
| 93 | =head2 before_release | ||||||||||
| 94 | |||||||||||
| 95 | This method checks the version of the dist to be released against the | ||||||||||
| 96 | latest version already indexed on CPAN. If the version to be released | ||||||||||
| 97 | is not greater than the indexed version, it prompts the user to | ||||||||||
| 98 | confirm the release. | ||||||||||
| 99 | |||||||||||
| 100 | This method does nothing if the dist is not indexed at all. | ||||||||||
| 101 | |||||||||||
| 102 | =head1 BUGS AND LIMITATIONS | ||||||||||
| 103 | |||||||||||
| 104 | Please report any bugs or feature requests to | ||||||||||
| 105 | C<rct+perlbug@thompsonclan.org>. | ||||||||||
| 106 | |||||||||||
| 107 | =head1 SEE ALSO | ||||||||||
| 108 | |||||||||||
| 109 | =over 4 | ||||||||||
| 110 | |||||||||||
| 111 | =item * | ||||||||||
| 112 | |||||||||||
| 113 | L<Dist::Zilla::Plugin::CheckPrereqsIndexed> - Used as the example for getting the indexed version of a dist | ||||||||||
| 114 | |||||||||||
| 115 | =back | ||||||||||
| 116 | |||||||||||
| 117 | =head1 INSTALLATION | ||||||||||
| 118 | |||||||||||
| 119 | See perlmodinstall for information and options on installing Perl modules. | ||||||||||
| 120 | |||||||||||
| 121 | =head1 AUTHOR | ||||||||||
| 122 | |||||||||||
| 123 | Ryan C. Thompson <rct@thompsonclan.org> | ||||||||||
| 124 | |||||||||||
| 125 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 126 | |||||||||||
| 127 | This software is copyright (c) 2012 by Ryan C. Thompson. | ||||||||||
| 128 | |||||||||||
| 129 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 130 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 131 | |||||||||||
| 132 | =head1 DISCLAIMER OF WARRANTY | ||||||||||
| 133 | |||||||||||
| 134 | BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | ||||||||||
| 135 | FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT | ||||||||||
| 136 | WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER | ||||||||||
| 137 | PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, | ||||||||||
| 138 | EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE | ||||||||||
| 139 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||||||||||
| 140 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE | ||||||||||
| 141 | SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME | ||||||||||
| 142 | THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. | ||||||||||
| 143 | |||||||||||
| 144 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||||||||||
| 145 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | ||||||||||
| 146 | REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE | ||||||||||
| 147 | TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR | ||||||||||
| 148 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE | ||||||||||
| 149 | SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING | ||||||||||
| 150 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A | ||||||||||
| 151 | FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF | ||||||||||
| 152 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH | ||||||||||
| 153 | DAMAGES. | ||||||||||
| 154 | |||||||||||
| 155 | =cut | ||||||||||
| 156 | |||||||||||
| 157 | |||||||||||
| 158 | __END__ | ||||||||||