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

filter: Statementstmt 97.8% 46 / 47 Branchbran 83.3% 5 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 1 totaltotal 95.6% 66 / 69 CC 5 SCAR 6.2
CC
5
Cov
96%
before_release
3.0
_get_changes
3.0
BEGIN
1.0
CRAP 1.9
« blib/lib/Dist/Zilla/Plugin/Test/ChangesHasContent.pm ↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Dist::Zilla::Plugin::CheckChangesHasContent;
4 # ABSTRACT: Ensure Changes has content before releasing
5 1 our $VERSION = '0.011';
6  
7 # Dependencies
8 1 ▶use Dist::Zilla 6 (); # XXX really the next release after this date
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use autodie 2.00;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Moose 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use namespace::autoclean 0.28;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # extends, roles, attributes, etc.
15  
16 1 with 'Dist::Zilla::Role::BeforeRelease';
17  
18 1 has changelog => (
19 is => 'ro',
20 isa => 'Str',
21 default => 'Changes'
22 );
23  
24 1 has trial_token => (
25 is => 'ro',
26 isa => 'Str',
27 default => '-TRIAL'
28 );
29  
30 # methods
31  
32 5 ▶sub before_release {
Subroutine before_release: called CC=3 SCAR=11.0
Pod undocumented
33 5 my $self = shift;
34 5 my $changes_filename = $self->changelog;
35 5 my $newver = $self->zilla->version;
36  
37 5 $self->log("Checking Changes");
38  
39 5 ▶ my $changes_file = first { $_->name eq $changes_filename } @{ $self->zilla->files };
Subroutine __ANON__: called CC=1 SCAR=0.0
40  
41 5 ▶ if ( ! $changes_file ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $changes_file) { } 0 5 5
elsif ($self->_get_changes($changes_file)) { } 3 2 5
42 0 $self->log_fatal("No $changes_filename file found");
43 }
44 elsif ( $self->_get_changes($changes_file) ) {
45 3 $self->log("$changes_filename OK");
46 }
47 else {
48 2 $self->log_fatal("$changes_filename has no content for $newver");
49 }
50  
51 3 return;
52 }
53  
54 5 ▶sub _get_changes {
Subroutine _get_changes: called CC=3 SCAR=11.0
55 5 my ($self, $changelog) = @_;
56  
57 # parse changelog to find commit message
58 5 my $newver = $self->zilla->version;
59 5 my $trial_token = $self->trial_token;
60 my @content =
61 5 grep { /^$newver(?:$trial_token)?(?:\s+|$)/ ... /^\S/ } # from newver to un-indented
62 split /\n/, $changelog->content;
63 5 shift @content; # drop the version line
64 # drop unindented last line and trailing blank lines
65 5 ▶ pop @content while ( @content && $content[-1] =~ /^(?:\S|\s*$)/ );
Branch: 1 branch
BranchTrueFalseTotal
@content and $content[-1] =~ /^(?:\S|\s*$)/ and do { pop @content } 9 5 14
Condition100%3/3
@content and $content[-1] =~ /^(?:\S|\s*$)/
!ll&&!rl&&r
239
MC/DC100%2/2
@content and $content[-1] =~ /^(?:\S|\s*$)/
@content $content[-1] =~ /^(?:\S|\s*$)/
Truth table100%3/3
A and B
A= @contentB= $content[-1] =~ /^(?:\S|\s*$)/
ABresult
0X0
100
111
66  
67 # return number of non-blank lines
68 5 return scalar @content;
69 } # end _get_changes
70  
71 1 __PACKAGE__->meta->make_immutable;
72  
73 1 1;
74  
75 __END__
« blib/lib/Dist/Zilla/Plugin/Test/ChangesHasContent.pm ↑ Summary