Dist/Zilla/Plugin/Author/HAYOBAAN/NextVersion.pm

filter: Statementstmt 46.8% 22 / 47 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 2 totaltotal 32.1% 27 / 84 CC 12 SCAR 41.5
CC
12
Cov
31%
provide_version
110.0
before_release
12.0
BEGIN
1.0
CRAP 63.4
« Dist/Zilla/PluginBundle/Author/HAYOBAAN.pm ↑ Summary Pod/Weaver/Section/Author/HAYOBAAN/Bugs.pm »
1 package Dist::Zilla::Plugin::Author::HAYOBAAN::NextVersion;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: Adapted version of the Git::NextVersion plugin to allow influencing version bumping.
6 1 our $VERSION = '0.016'; # VERSION
7  
8 #pod =head1 DESCRIPTION
9 #pod
10 #pod Provides the next version number, just as
11 #pod L<Git::NextVersion|Dist::Zilla::Plugin::Git::NextVersion> would do,
12 #pod including specifying the version using the C<V> environment variable.
13 #pod
14 #pod Unlike L<Git::NextVersion|Dist::Zilla::Plugin::Git::NextVersion>, you are, however, able to influence I<if> and I<how> the version is bumped:
15 #pod
16 #pod =begin :list
17 #pod
18 #pod =*
19 #pod
20 #pod By setting the attribute L</include_minor_version> to I<true> you specify that the version string should include a minor version (i.e., end in C<_I<xxx>>).
21 #pod
22 #pod =*
23 #pod
24 #pod Likewise, setting L</remove_minor_version> to I<true>, will remove any existing minor version.
25 #pod
26 #pod =*
27 #pod
28 #pod Finally, setting the attribute L</keep_version> to a I<true> value will keep the version as is (ignoring above settings).
29 #pod
30 #pod =end :list
31 #pod
32 #pod Specifying a specific version using the C<V> environment variable,
33 #pod overrides all of these settings.
34 #pod
35 #pod =head1 USAGE
36 #pod
37 #pod Add the following to your F<dist.ini>:
38 #pod
39 #pod [Author::HAYOBAAN::NextVersion]
40 #pod include_minor_version = 0
41 #pod remove_minor_version = 0
42 #pod keep_version = 0
43 #pod
44 #pod =head1 SEE ALSO
45 #pod
46 #pod =for :list
47 #pod * The original L<Git::NextVersion|Dist::Zilla::Plugin::Git::NextVersion> plugin.
48 #pod
49 #pod =cut
50  
51 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶use namespace::autoclean 0.09;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use Dist::Zilla 5.014; # default_jobs
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 extends 'Dist::Zilla::Plugin::Git::NextVersion';
55  
56 #pod =attr include_minor_version
57 #pod
58 #pod Specifies that a minor version should be included in the version
59 #pod string. This will add C<_001> to the current version if the current
60 #pod version string did not already end in C<_I<xxx>>.
61 #pod
62 #pod Default: I<false>
63 #pod
64 #pod =cut
65  
66 1 has include_minor_version => (
67 is => 'ro',
68 isa => 'Bool',
69 lazy => 1,
70 default => 0,
71 );
72  
73 #pod =attr remove_minor_version
74 #pod
75 #pod Specifies that an existing minor version should be removed from the existing version
76 #pod string. This will remove any C<_I<xxx>> from the end of the current version string.
77 #pod
78 #pod Note: overrides L</include_minor_version>.
79 #pod
80 #pod Default: I<false>
81 #pod
82 #pod =cut
83  
84 1 has remove_minor_version => (
85 is => 'ro',
86 isa => 'Bool',
87 lazy => 1,
88 default => 0,
89 );
90  
91 #pod =attr keep_version
92 #pod
93 #pod Specifies that the version should be kept the same.
94 #pod
95 #pod Default: I<false>
96 #pod
97 #pod =cut
98  
99 1 has keep_version => (
100 is => 'ro',
101 isa => 'Bool',
102 lazy => 1,
103 default => 0,
104 );
105  
106 # Own version of the provide_version function
107 0 ▶sub provide_version {
Subroutine provide_version: not called CC=10 SCAR=47.0
Pod undocumented
108 0 my ($self) = @_;
109  
110 0 my $keep_version = $self->keep_version;
111 0 my $remove_minor_version = $self->remove_minor_version;
112 0 ▶ my $include_minor_version = $self->include_minor_version && !$remove_minor_version;
Condition0%0/3
$self->include_minor_version && !$remove_minor_version
!ll&&!rl&&r
000
MC/DC0%0/2
$self->include_minor_version && !$remove_minor_version
$self->include_minor_version !$remove_minor_version
Truth table0%0/3
A && not(B)
A= $self->include_minor_versionB= !$remove_minor_version
ABresult
0X0
100
111
113 0 my $last_ver = $self->_last_version;
114 0 my $new_ver = $last_ver;
115  
116 0 ▶ if (exists $ENV{V}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $ENV{'V'}) { } 0 0 0
elsif (not defined $last_ver) { } 0 0 0
elsif (not $keep_version) { } 0 0 0
117 # Override with value of V from enviroment
118 0 $new_ver = $ENV{V};
119 } elsif (!defined $last_ver) {
120 # Initialise if no version set
121 0 $new_ver = $self->first_version;
122 } elsif (!$keep_version) {
123 0 ▶ $new_ver .= '_000' if $include_minor_version && $last_ver !~ /_\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $include_minor_version and not $last_ver =~ /_\d+$/ 0 0 0
Condition0%0/3
$include_minor_version and not $last_ver =~ /_\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$include_minor_version and not $last_ver =~ /_\d+$/
$include_minor_version not $last_ver =~ /_\d+$/
Truth table0%0/3
A and not(B)
A= $include_minor_versionB= not $last_ver =~ /_\d+$/
ABresult
0X0
100
111
124 0 ▶ $new_ver =~ s/_\d+$// if $remove_minor_version;
Branch: 1 branch
BranchTrueFalseTotal
if $remove_minor_version 0 0 0
125  
126 0 require Version::Next;
127 0 $new_ver = Version::Next::next_version($new_ver);
128 }
129  
130 # Inform about what was done
131 0 ▶ if (!defined $last_ver) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $last_ver) { } 0 0 0
elsif ($last_ver eq $new_ver) { } 0 0 0
132 0 $self->log("Initialising version to $new_ver");
133 } elsif ($last_ver eq $new_ver) {
134 0 $self->log("Keeping version at $new_ver");
135 } else {
136 0 $self->log("Updating version from $last_ver to $new_ver");
137 }
138  
139 0 return "$new_ver";
140 }
141  
142 # Own version of the provide_version function, allows for duplicate
143 # version when not version bumping
144 0 ▶sub before_release {
Subroutine before_release: not called CC=3 SCAR=24.8
Pod undocumented
145 0 my $self = shift;
146  
147 # No duplicate version check when not bumping
148 0 ▶ unless ($self->keep_version) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->keep_version) 0 0 0
149 # Make sure we're not duplicating a version
150 0 my $version = version->parse( $self->zilla->version );
151  
152 $self->log_fatal("version $version has already been tagged")
153 0 ▶ if grep { $_ == $version } @{ $self->_all_versions };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == $version;} @{$self->_all_versions;} 0 0 0
154 }
155  
156 0 return;
157 }
158  
159 1 __PACKAGE__->meta->make_immutable;
160 1 1;
161  
162 __END__
« Dist/Zilla/PluginBundle/Author/HAYOBAAN.pm ↑ Summary Pod/Weaver/Section/Author/HAYOBAAN/Bugs.pm »