Plugin/Author/VDB/Version/Bump.pm

filter: Statementstmt 89.3% 42 / 47 Branchbran 50.0% 4 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 1 totaltotal 82.6% 57 / 69 CC 6 SCAR 10.6
CC
6
Cov
82%
__ANON__
7.0
after_release
2.3
__ANON__
2.0
CRAP 2.9
« Plugin/Author/VDB/Hg/Commit.pm ↑ Summary Plugin/Author/VDB/Hg/Tag/Check.pm »
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'; # 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 Perl::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 2 ▶use Try::Tiny;
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 5 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
88 5 my ( $self ) = @_;
89 5 my $path = path( $self->file );
90 5 ▶ if ( $path->is_absolute ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->is_absolute) 1 4 5
91 1 $self->abort( [ "Bad version file '%s': absolute path is not allowed", $self->file ] );
92 };
93 4 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 5 ▶sub after_release {
Subroutine after_release: called CC=2 SCAR=8.1
Pod undocumented
104 5 my ( $self ) = @_;
105 5 ▶ if ( $self->file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->file) { } 5 0 5
106 5 my $version = Perl::Version->new( $self->zilla->version );
107 5 $version->inc_alpha();
108 5 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
109 5 $self->_file->append( { truncate => 1 }, "$version\n" );
110 # `append` is not atomic but keeps file mode intact.
111 1 ▶ } catch {
Subroutine __ANON__: called CC=4 SCAR=19.4
112 1 my $ex = $_;
113 1 ▶ my $class = blessed( $ex ) || '';
Condition50%1/2
builtin::blessed($ex) || ''
l!l
10
MC/DC0%0/1
builtin::blessed($ex) || ''
builtin::blessed($ex)
Truth table50%1/2
A
A= builtin::blessed($ex)
Aresult
11
00
114 1 ▶ if ( 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (do { $class eq 'Dist::Zilla::Role::ErrorLogger::Exception::Abort' }) { } 1 0 1
elsif (builtin::blessed($ex) eq 'Try::Tiny::Error') { } 0 0 0
115 } elsif ( $class eq 'Dist::Zilla::Role::ErrorLogger::Exception::Abort' ) {
116 # All the messages are aready logged, just rethrow the exception.
117 1 die $ex; ## no critic ( RequireCarping )
118 } elsif ( blessed( $ex ) eq 'Try::Tiny::Error' ) {
119 0 chomp( my $em = "$ex" );
120 0 $self->log_debug( $em );
121 0 $self->abort( [ "Can't write version file '%s': %s", $self->file, $ex->{ err } ] );
122 } else {
123 0 $self->abort( $ex );
124 };
125 5 };
126 4 $self->log_debug( [ 'next release version will be %s', "$version" ] );
127 } else {
128 0 $self->log_debug( 'no version file specified' );
129 };
130 4 return;
131 };
132  
133 # --------------------------------------------------------------------------------------------------
134  
135 2 __PACKAGE__->meta->make_immutable();
136  
137 2 1;
138  
139 #pod =head1 COPYRIGHT AND LICENSE
140 #pod
141 #pod Copyright (C) 2015 Van de Bugger
142 #pod
143 #pod License GPLv3+: The GNU General Public License version 3 or later
144 #pod <http://www.gnu.org/licenses/gpl-3.0.txt>.
145 #pod
146 #pod This is free software: you are free to change and redistribute it. There is
147 #pod NO WARRANTY, to the extent permitted by law.
148 #pod
149 #pod
150 #pod =cut
151  
152 # end of file #
153  
154 __END__
« Plugin/Author/VDB/Hg/Commit.pm ↑ Summary Plugin/Author/VDB/Hg/Tag/Check.pm »