| 1 | # ---------------------------------------------------------------------- copyright and license --- | ||||||||||||||
| 2 | # | ||||||||||||||
| 3 | # file: lib/Dist/Zilla/Plugin/Author/VDB/Version/Bump.pm | ||||||||||||||
| 4 | # | ||||||||||||||
| 5 | # Copyright © 2015 Van de Bugger | ||||||||||||||
| 6 | # | ||||||||||||||
| 7 | # This file is part of perl-Dist-Zilla-PluginBundle-Author-VDB. | ||||||||||||||
| 8 | # | ||||||||||||||
| 9 | # perl-Dist-Zilla-PluginBundle-Author-VDB is free software: you can redistribute it and/or modify | ||||||||||||||
| 10 | # it under the terms of the GNU General Public License as published by the Free Software | ||||||||||||||
| 11 | # Foundation, either version 3 of the License, or (at your option) any later version. | ||||||||||||||
| 12 | # | ||||||||||||||
| 13 | # perl-Dist-Zilla-PluginBundle-Author-VDB is distributed in the hope that it will be useful, but | ||||||||||||||
| 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||||||
| 15 | # PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||||||||||||
| 16 | # | ||||||||||||||
| 17 | # You should have received a copy of the GNU General Public License along with | ||||||||||||||
| 18 | # perl-Dist-Zilla-PluginBundle-Author-VDB. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||
| 19 | # | ||||||||||||||
| 20 | # ---------------------------------------------------------------------- copyright and license --- | ||||||||||||||
| 21 | |||||||||||||||
| 22 | #pod =for test_synopsis BEGIN { die "SKIP: not a Perl code"; } | ||||||||||||||
| 23 | #pod | ||||||||||||||
| 24 | #pod =head1 SYNOPSIS | ||||||||||||||
| 25 | #pod | ||||||||||||||
| 26 | #pod F<dist.in> file: | ||||||||||||||
| 27 | #pod | ||||||||||||||
| 28 | #pod ; version = v0.3.1 ; *Should **not** be used.* | ||||||||||||||
| 29 | #pod ... | ||||||||||||||
| 30 | #pod [Author::VDB::Version::Read] | ||||||||||||||
| 31 | #pod file = VERSION | ||||||||||||||
| 32 | #pod ... | ||||||||||||||
| 33 | #pod [Author::VDB::Version::Bump] | ||||||||||||||
| 34 | #pod file = VERSION | ||||||||||||||
| 35 | #pod | ||||||||||||||
| 36 | #pod F<VERSION> file: | ||||||||||||||
| 37 | #pod | ||||||||||||||
| 38 | #pod v0.3.1 | ||||||||||||||
| 39 | #pod | ||||||||||||||
| 40 | #pod =head1 DESCRIPTION | ||||||||||||||
| 41 | #pod | ||||||||||||||
| 42 | #pod This plugin does C<AfterRelease> role. It bumps version in the specified file by incrementing alpha | ||||||||||||||
| 43 | #pod component. For example, version C<v0.7.1> is bumped to C<v0.7.1_01>, then to C<v0.7.1_02>, etc. | ||||||||||||||
| 44 | #pod | ||||||||||||||
| 45 | #pod =cut | ||||||||||||||
| 46 | |||||||||||||||
| 47 | # -------------------------------------------------------------------------------------------------- | ||||||||||||||
| 48 | |||||||||||||||
| 49 | package Dist::Zilla::Plugin::Author::VDB::Version::Bump; | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 2 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 52 | 2 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 53 | 2 | ▶ | use version 0.77; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 54 | |||||||||||||||
| 55 | # ABSTRACT: Bump version after release | ||||||||||||||
| 56 | 2 | our $VERSION = 'v0.11.3.1'; # TRIAL VERSION | |||||||||||||
| 57 | |||||||||||||||
| 58 | 2 | with 'Dist::Zilla::Role::AfterRelease'; | |||||||||||||
| 59 | 2 | with 'Dist::Zilla::Role::ErrorLogger' => { -version => 'v0.9.0' }; | |||||||||||||
| 60 | # ^ We need `ErrorLogger` to throw an exception, not plain string. | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 2 | ▶ | use Path::Tiny; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 63 | 2 | ▶ | use Try::Tiny; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 64 | 2 | ▶ | use Version::Dotted::Semantic; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 65 | |||||||||||||||
| 66 | # -------------------------------------------------------------------------------------------------- | ||||||||||||||
| 67 | |||||||||||||||
| 68 | #pod =option file | ||||||||||||||
| 69 | #pod | ||||||||||||||
| 70 | #pod Name of file to bump version in. Default value is C<VERSION>. Specifying an empty file disables | ||||||||||||||
| 71 | #pod the plugin. | ||||||||||||||
| 72 | #pod | ||||||||||||||
| 73 | #pod =cut | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 2 | has 'file' => ( | |||||||||||||
| 76 | isa => 'Str', | ||||||||||||||
| 77 | is => 'ro', | ||||||||||||||
| 78 | lazy => 1, | ||||||||||||||
| 79 | default => 'VERSION', | ||||||||||||||
| 80 | ); | ||||||||||||||
| 81 | |||||||||||||||
| 82 | has _file => ( | ||||||||||||||
| 83 | isa => 'Path::Tiny', | ||||||||||||||
| 84 | is => 'ro', | ||||||||||||||
| 85 | init_arg => undef, | ||||||||||||||
| 86 | lazy => 1, | ||||||||||||||
| 87 | 4 | ▶ | default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 88 | 4 | my ( $self ) = @_; | |||||||||||||
| 89 | 4 | my $path = path( $self->file ); | |||||||||||||
| 90 | 4 | ▶ | if ( $path->is_absolute ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | 1 | $self->abort( [ "Bad version file '%s': absolute path is not allowed", $self->file ] ); | |||||||||||||
| 92 | }; | ||||||||||||||
| 93 | 3 | return $path->absolute( $self->zilla->root ); | |||||||||||||
| 94 | }, | ||||||||||||||
| 95 | 2 | ); | |||||||||||||
| 96 | |||||||||||||||
| 97 | # -------------------------------------------------------------------------------------------------- | ||||||||||||||
| 98 | |||||||||||||||
| 99 | #pod =for Pod::Coverage after_release | ||||||||||||||
| 100 | #pod | ||||||||||||||
| 101 | #pod =cut | ||||||||||||||
| 102 | |||||||||||||||
| 103 | 6 | ▶ | sub after_release { | ||||||||||||
|
Subroutine
after_release: called CC=4 SCAR=14.8
Pod
undocumented
| |||||||||||||||
| 104 | 6 | my ( $self ) = @_; | |||||||||||||
| 105 | 6 | ▶ | if ( $self->file ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 106 | 6 | my $version = $self->zilla->version; | |||||||||||||
| 107 | 6 | ▶ | if ( not version::is_strict( $version ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 108 | 1 | $self->abort( [ "Invalid version string '%s'", $version ] ); | |||||||||||||
| 109 | }; | ||||||||||||||
| 110 | 5 | ▶ | if ( $version !~ m{ ^ v \d+ (?: \. \d+ )* $ }x ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 111 | 1 | $self->abort( [ "Not a dotted version string '%s'", $version ] ); | |||||||||||||
| 112 | }; | ||||||||||||||
| 113 | 4 | ▶ | try { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 114 | 4 | $version = Version::Dotted::Semantic->new( $version ); | |||||||||||||
| 115 | 4 | $version->bump( 'trial' ); | |||||||||||||
| 116 | 4 | $self->_file->append( { truncate => 1 }, "$version\n" ); | |||||||||||||
| 117 | # `append` is not atomic but keeps file mode intact. | ||||||||||||||
| 118 | 1 | ▶ | } catch { | ||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=19.4
| |||||||||||||||
| 119 | 1 | my $ex = $_; | |||||||||||||
| 120 | 1 | ▶ | my $class = blessed( $ex ) || ''; | ||||||||||||
|
Condition50%1/2
builtin::blessed($ex) || ''
MC/DC0%0/1
builtin::blessed($ex) || ''
builtin::blessed($ex)
Truth table50%1/2
A
A= builtin::blessed($ex)
| |||||||||||||||
| 121 | 1 | ▶ | if ( 0 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 122 | } elsif ( $class eq 'Dist::Zilla::Role::ErrorLogger::Exception::Abort' ) { | ||||||||||||||
| 123 | # All the messages are aready logged, just rethrow the exception. | ||||||||||||||
| 124 | 1 | die $ex; ## no critic ( RequireCarping ) | |||||||||||||
| 125 | } elsif ( blessed( $ex ) eq 'Try::Tiny::Error' ) { | ||||||||||||||
| 126 | 0 | chomp( my $em = "$ex" ); | |||||||||||||
| 127 | 0 | $self->log_debug( $em ); | |||||||||||||
| 128 | 0 | $self->abort( [ "Can't write version file '%s': %s", $self->file, $ex->{ err } ] ); | |||||||||||||
| 129 | } else { | ||||||||||||||
| 130 | 0 | $self->abort( $ex ); | |||||||||||||
| 131 | }; | ||||||||||||||
| 132 | 4 | }; | |||||||||||||
| 133 | 3 | $self->log_debug( [ 'next release version will be %s', "$version" ] ); | |||||||||||||
| 134 | } else { | ||||||||||||||
| 135 | 0 | $self->log_debug( 'no version file specified' ); | |||||||||||||
| 136 | }; | ||||||||||||||
| 137 | 3 | return; | |||||||||||||
| 138 | }; | ||||||||||||||
| 139 | |||||||||||||||
| 140 | # -------------------------------------------------------------------------------------------------- | ||||||||||||||
| 141 | |||||||||||||||
| 142 | 2 | __PACKAGE__->meta->make_immutable(); | |||||||||||||
| 143 | |||||||||||||||
| 144 | 2 | 1; | |||||||||||||
| 145 | |||||||||||||||
| 146 | #pod =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 147 | #pod | ||||||||||||||
| 148 | #pod Copyright (C) 2015 Van de Bugger | ||||||||||||||
| 149 | #pod | ||||||||||||||
| 150 | #pod License GPLv3+: The GNU General Public License version 3 or later | ||||||||||||||
| 151 | #pod <http://www.gnu.org/licenses/gpl-3.0.txt>. | ||||||||||||||
| 152 | #pod | ||||||||||||||
| 153 | #pod This is free software: you are free to change and redistribute it. There is | ||||||||||||||
| 154 | #pod NO WARRANTY, to the extent permitted by law. | ||||||||||||||
| 155 | #pod | ||||||||||||||
| 156 | #pod | ||||||||||||||
| 157 | #pod =cut | ||||||||||||||
| 158 | |||||||||||||||
| 159 | # end of file # | ||||||||||||||
| 160 | |||||||||||||||
| 161 | __END__ | ||||||||||||||