blib/lib/Dist/Zilla/Plugin/NextRelease.pm

filter: Statementstmt 97.4% 76 / 78 Branchbran 66.6% 8 / 12 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 91.3% 21 / 23 Podpod 0.0% 0 / 3 totaltotal 88.1% 112 / 127 CC 10 SCAR 6.3
CC
10
Cov
92%
__ANON__
3.6
_user_info
3.0
__ANON__
3.0
CRAP 1.9
« blib/lib/Dist/Zilla/MVP/Assembler.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/FakeRelease.pm »
1 package Dist::Zilla::Plugin::NextRelease 6.040;
2 # ABSTRACT: update the next release number in your changelog
3  
4 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 with (
6 'Dist::Zilla::Role::FileMunger',
7 'Dist::Zilla::Role::TextTemplate',
8 'Dist::Zilla::Role::AfterRelease',
9 );
10  
11 5 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 ▶use Dist::Zilla::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use String::Formatter 0.100680 stringf => {
Subroutine BEGIN: called CC=1 SCAR=0.1
19 -as => '_format_version',
20  
21 input_processor => 'require_single_input',
22 string_replacer => 'method_replace',
23 codes => {
24 15 ▶ v => sub { $_[0]->zilla->version },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 9 ▶ d => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
26 9 require DateTime;
27 9 DateTime->VERSION('0.44'); # CLDR fixes
28  
29 9 DateTime->from_epoch(epoch => $^T, time_zone => $_[0]->time_zone)
30 ->format_cldr($_[1]),
31 },
32 0 ▶ t => sub { "\t" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 ▶ n => sub { "\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 2 ▶ E => sub { $_[0]->_user_info('email') },
Subroutine __ANON__: called CC=1 SCAR=0.0
35 3 ▶ U => sub { $_[0]->_user_info('name') },
Subroutine __ANON__: called CC=1 SCAR=0.0
36 10 ▶ T => sub { $_[0]->zilla->is_trial
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->zilla->is_trial ? : 2 8 10
Condition100%2/2
$_[1] // "-TRIAL"
l!l
11
MC/DC100%1/1
$_[1] // "-TRIAL"
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
37 ? ($_[1] // '-TRIAL') : '' },
38 1 ▶ V => sub { $_[0]->zilla->version
Subroutine __ANON__: called CC=3 SCAR=12.7
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->zilla->is_trial ? : 1 0 1
Condition50%1/2
$_[1] // "-TRIAL"
l!l
01
MC/DC0%0/1
$_[1] // "-TRIAL"
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
39 . ($_[0]->zilla->is_trial
40 ? ($_[1] // '-TRIAL') : '') },
41 1 ▶ P => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
42 1 ▶ my $releaser = first { $_->can('cpanid') } @{ $_[0]->zilla->plugins_with('-Releaser') };
Subroutine __ANON__: called CC=1 SCAR=0.0
43 1 ▶ $_[0]->log_fatal('releaser doesn\'t provide cpanid, but %P used') unless $releaser;
Branch: 1 branch
BranchTrueFalseTotal
unless $releaser 0 1 1
44 1 $releaser->cpanid;
45 },
46 },
47 5 };
48  
49 5 our $DEFAULT_TIME_ZONE = 'local';
50 5 has time_zone => (
51 is => 'ro',
52 isa => 'Str', # should be more validated later -- apocal
53 default => $DEFAULT_TIME_ZONE,
54 );
55  
56 5 has format => (
57 is => 'ro',
58 isa => 'Str', # should be more validated Later -- rjbs, 2008-06-05
59 default => '%-9v %{yyyy-MM-dd HH:mm:ssZZZZZ VVVV}d%{ (TRIAL RELEASE)}T',
60 );
61  
62 5 has filename => (
63 is => 'ro',
64 isa => 'Str',
65 default => 'Changes',
66 );
67  
68 has update_filename => (
69 is => 'ro',
70 isa => 'Str',
71 lazy => 1,
72 1 ▶ default => sub { $_[0]->filename },
Subroutine __ANON__: called CC=1 SCAR=0.0
73 5 );
74  
75 5 has user_stash => (
76 is => 'ro',
77 isa => 'Str',
78 default => '%User'
79 );
80  
81 has _user_stash_obj => (
82 is => 'ro',
83 isa => maybe_type( class_type('Dist::Zilla::Stash::User') ),
84 lazy => 1,
85 init_arg => undef,
86 3 ▶ default => sub { $_[0]->zilla->stash_named( $_[0]->user_stash ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
87 5 );
88  
89 5 ▶sub _user_info {
Subroutine _user_info: called CC=3 SCAR=11.0
90 5 my ($self, $field) = @_;
91  
92 5 my $stash = $self->_user_stash_obj;
93  
94 5 ▶ $self->log_fatal([
Branch: 1 branch
BranchTrueFalseTotal
unless $stash and defined(my $value = $stash->$field) 1 4 5
Condition66%2/3
$stash and defined(my $value = $stash->$field)
!ll&&!rl&&r
104
MC/DC50%1/2
$stash and defined(my $value = $stash->$field)
$stash defined(my $value = $stash->$field)
Truth table66%2/3
A and B
A= $stashB= defined(my $value = $stash->$field)
ABresult
0X0
100
111
95 "You must enter your %s in the [%s] section in ~/.dzil/config.ini",
96 $field, $self->user_stash
97 ]) unless $stash and defined(my $value = $stash->$field);
98  
99 4 return $value;
100 }
101  
102 16 ▶sub section_header {
Subroutine section_header: called CC=1 SCAR=0.0
Pod undocumented
103 16 my ($self) = @_;
104  
105 16 return _format_version($self->format, $self);
106 }
107  
108 5 has _original_changes_content => (
109 is => 'rw',
110 isa => 'Str',
111 init_arg => undef,
112 );
113  
114 15 ▶sub munge_files {
Subroutine munge_files: called CC=2 SCAR=6.9
Pod undocumented
115 15 my ($self) = @_;
116  
117 15 my ($file) = grep { $_->name eq $self->filename } @{ $self->zilla->files };
118 15 ▶ $self->log_fatal([ 'failed to find %s in the distribution', $self->filename ]) if not $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 15 15
119  
120 # save original unmunged content, for replacing back in the repo later
121 15 my $content = $self->_original_changes_content($file->content);
122  
123 15 $content = $self->fill_in_string(
124 $content,
125 {
126 dist => \($self->zilla),
127 version => \($self->zilla->version),
128 NEXT => \($self->section_header),
129 },
130 );
131  
132 14 $self->log_debug([ 'updating contents of %s in memory', $file->name ]);
133 14 $file->content($content);
134 }
135  
136 # new release is part of distribution history, let's record that.
137 1 ▶sub after_release {
Subroutine after_release: called CC=2 SCAR=6.9
Pod undocumented
138 1 my ($self) = @_;
139 1 my $filename = $self->filename;
140 1 my ($gathered_file) = grep { $_->name eq $filename } @{ $self->zilla->files };
141 1 ▶ $self->log_fatal("failed to find $filename in the distribution") if not $gathered_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $gathered_file 0 1 1
142 1 my $iolayer = sprintf(":raw:encoding(%s)", $gathered_file->encoding);
143  
144 # read original changelog
145 1 my $content = $self->_original_changes_content;
146  
147 # add the version and date to file content
148 1 my $delim = $self->delim;
149 1 my $header = $self->section_header;
150 1 $content =~ s{ (\Q$delim->[0]\E \s*) \$NEXT (\s* \Q$delim->[1]\E) }
151 {$1\$NEXT$2\n\n$header}xs;
152  
153 1 my $update_fn = $self->update_filename;
154 1 $self->log_debug([ 'updating contents of %s on disk', $update_fn ]);
155  
156 # and finally rewrite the changelog on disk
157 1 path($update_fn)->spew({binmode => $iolayer}, $content);
158 }
159  
160 5 __PACKAGE__->meta->make_immutable;
161 5 1;
162  
163 #pod =head1 SYNOPSIS
164 #pod
165 #pod In your F<dist.ini>:
166 #pod
167 #pod [NextRelease]
168 #pod
169 #pod In your F<Changes> file:
170 #pod
171 #pod {{$NEXT}}
172 #pod
173 #pod
174 #pod =head1 DESCRIPTION
175 #pod
176 #pod Tired of having to update your F<Changes> file by hand with the new
177 #pod version and release date / time each time you release your distribution?
178 #pod Well, this plugin is for you.
179 #pod
180 #pod Add this plugin to your F<dist.ini>, and the following to your
181 #pod F<Changes> file:
182 #pod
183 #pod {{$NEXT}}
184 #pod
185 #pod The C<NextRelease> plugin will then do 2 things:
186 #pod
187 #pod =over 4
188 #pod
189 #pod =item * At build time, this special marker will be replaced with the
190 #pod version and the build date, to form a standard changelog header. This
191 #pod will be done to the in-memory file - the original F<Changes> file won't
192 #pod be updated.
193 #pod
194 #pod =item * After release (when running C<dzil release>), since the version
195 #pod and build date are now part of your dist's history, the real F<Changes>
196 #pod file (not the in-memory one) will be updated with this piece of
197 #pod information.
198 #pod
199 #pod =back
200 #pod
201 #pod The module accepts the following options in its F<dist.ini> section:
202 #pod
203 #pod =begin :list
204 #pod
205 #pod = filename
206 #pod the name of your changelog file; defaults to F<Changes>
207 #pod
208 #pod = update_filename
209 #pod the file to which to write an updated changelog to; defaults to the C<filename>
210 #pod
211 #pod = format
212 #pod sprintf-like string used to compute the next value of C<{{$NEXT}}>;
213 #pod defaults to C<%-9v %{yyyy-MM-dd HH:mm:ssZZZZZ VVVV}d%{ (TRIAL RELEASE)}T>
214 #pod
215 #pod = time_zone
216 #pod the timezone to use when generating the date; defaults to I<local>
217 #pod
218 #pod = user_stash
219 #pod the name of the stash where the user's name and email address can be found;
220 #pod defaults to C<%User>
221 #pod
222 #pod =end :list
223 #pod
224 #pod The module allows the following sprintf-like format codes in the C<format>:
225 #pod
226 #pod =begin :list
227 #pod
228 #pod = C<%v>
229 #pod The distribution version
230 #pod
231 #pod = C<%{-TRIAL}T>
232 #pod Expands to -TRIAL (or any other supplied string) if this
233 #pod is a trial release, or the empty string if not. A bare C<%T> means
234 #pod C<%{-TRIAL}T>.
235 #pod
236 #pod = C<%{-TRIAL}V>
237 #pod Equivalent to C<%v%{-TRIAL}T>, to allow for the application of modifiers such
238 #pod as space padding to the entire version string produced.
239 #pod
240 #pod = C<%{CLDR format}d>
241 #pod The date of the release. You can use any CLDR format supported by
242 #pod L<DateTime>. You must specify the format; there is no default.
243 #pod
244 #pod = C<%U>
245 #pod The name of the user making this release (from C<user_stash>).
246 #pod
247 #pod = C<%E>
248 #pod The email address of the user making this release (from C<user_stash>).
249 #pod
250 #pod = C<%P>
251 #pod The CPAN (PAUSE) id of the user making this release (from -Releaser plugins;
252 #pod see L<[UploadToCPAN]|Dist::Zilla::Plugin::UploadToCPAN/username>).
253 #pod
254 #pod = C<%n>
255 #pod A newline
256 #pod
257 #pod = C<%t>
258 #pod A tab
259 #pod
260 #pod =end :list
261 #pod
262 #pod =head1 SEE ALSO
263 #pod
264 #pod Core Dist::Zilla plugins:
265 #pod L<AutoVersion|Dist::Zilla::Plugin::AutoVersion>,
266 #pod L<PkgVersion|Dist::Zilla::Plugin::PkgVersion>,
267 #pod L<PodVersion|Dist::Zilla::Plugin::PodVersion>.
268 #pod
269 #pod Dist::Zilla roles:
270 #pod L<AfterRelease|Dist::Zilla::Plugin::AfterRelease>,
271 #pod L<FileMunger|Dist::Zilla::Role::FileMunger>,
272 #pod L<TextTemplate|Dist::Zilla::Role::TextTemplate>.
273  
274 __END__
« blib/lib/Dist/Zilla/MVP/Assembler.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/FakeRelease.pm »