blib/lib/Dist/Zilla/Plugin/Test/ChangesHasContent.pm

filter: Statementstmt 100% 55 / 55 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 2 totaltotal 84.0% 74 / 88 CC 7 SCAR 9.1
CC
7
Cov
88%
munge_files
5.4
gather_files
3.1
BEGIN
1.0
CRAP 2.5
↑ Summary blib/lib/Dist/Zilla/Plugin/CheckChangesHasContent.pm »
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::Test::ChangesHasContent;
4 # ABSTRACT: Release test to ensure Changes has content
5 1 our $VERSION = '0.011';
6  
7 # Dependencies
8 1 ▶use Dist::Zilla;
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 Sub::Exporter::ForMethods;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Data::Section 0.200002 # encoding and bytes
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 { installer => Sub::Exporter::ForMethods::method_installer },
14 1 '-setup' => { encoding => 'bytes' };
15 1 ▶use Moose::Util::TypeConstraints 'role_type';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use namespace::autoclean 0.09;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # extends, roles, attributes, etc.
20  
21 1 with qw/Dist::Zilla::Role::FileGatherer
22 Dist::Zilla::Role::FileMunger
23 Dist::Zilla::Role::TextTemplate
24 /;
25  
26 1 has changelog => (
27 is => 'ro',
28 isa => 'Str',
29 default => 'Changes'
30 );
31  
32 1 has trial_token => (
33 is => 'ro',
34 isa => 'Str',
35 default => '-TRIAL'
36 );
37  
38 1 has _file => (
39 is => 'rw', isa => role_type('Dist::Zilla::Role::File'),
40 );
41  
42 # methods
43  
44 sub gather_files
45 4 ▶{
Subroutine gather_files: called CC=3 SCAR=11.4
Pod undocumented
46 4 my $self = shift;
47  
48 4 my $data = $self->merged_section_data;
49 4 ▶ return unless $data and %$data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data and %$data 0 4 4
Condition33%1/3
$data and %$data
!ll&&!rl&&r
004
MC/DC0%0/2
$data and %$data
$data %$data
Truth table33%1/3
A and B
A= $dataB= %$data
ABresult
0X0
100
111
50  
51 4 my ($name, $contentref) = %$data;
52  
53 4 require Dist::Zilla::File::InMemory;
54  
55 4 $self->add_file( $self->_file(
56 Dist::Zilla::File::InMemory->new({
57 name => $name,
58 content => $$contentref,
59 }))
60 );
61  
62 4 return;
63 }
64  
65 sub munge_files
66 4 ▶{
Subroutine munge_files: called CC=5 SCAR=16.8
Pod undocumented
67 4 my $self = shift;
68 4 my $file = $self->_file;
69  
70 4 my $changes_filename = $self->changelog;
71 4 ▶ my $changes_file = first { $_->name eq $changes_filename } @{ $self->zilla->files };
Subroutine __ANON__: called CC=1 SCAR=0.0
72 4 ▶ $self->log_fatal([ 'No %s file found', $changes_filename ]) if not $changes_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $changes_file 0 4 4
73 4 ▶ $self->log_fatal([ 'Cannot decode %s from bytes encoding', $changes_filename ])
Branch: 1 branch
BranchTrueFalseTotal
if $changes_filename->can("is_bytes") and $changes_filename->is_bytes 0 4 4
Condition33%1/3
$changes_filename->can("is_bytes") and $changes_filename->is_bytes
!ll&&!rl&&r
400
MC/DC0%0/2
$changes_filename->can("is_bytes") and $changes_filename->is_bytes
$changes_filename->can("is_bytes") $changes_filename->is_bytes
Truth table33%1/3
A and B
A= $changes_filename->can("is_bytes")B= $changes_filename->is_bytes
ABresult
0X0
100
111
74 if $changes_filename->can('is_bytes') and $changes_filename->is_bytes;
75 4 ▶ my $encoding = $changes_file->can('encoding') ? $changes_file->encoding : undef;
Branch: 1 branch
BranchTrueFalseTotal
$changes_file->can('encoding') ? : 4 0 4
76  
77 4 $file->content(
78 $self->fill_in_string(
79 $file->content,
80 {
81 changelog => $self->changelog,
82 trial_token => $self->trial_token,
83 newver => $self->zilla->version,
84 encoding => $encoding,
85 }
86 )
87 );
88  
89 4 return;
90 }
91  
92 1 __PACKAGE__->meta->make_immutable;
93  
94 1 1;
95  
96 # Pod must be before DATA
97  
98 #pod =for Pod::Coverage gather_files munge_files
99 #pod
100 #pod =head1 SYNOPSIS
101 #pod
102 #pod # in dist.ini
103 #pod
104 #pod [Test::ChangesHasContent]
105 #pod
106 #pod =head1 DESCRIPTION
107 #pod
108 #pod This plugin provides C<xt/release/changes_has_content.t>.
109 #pod
110 #pod This test ensures ensures that your Changes file actually has some content
111 #pod since the last release.
112 #pod
113 #pod This can be contrasted to L<Dist::Zilla::Plugin::CheckChangesHasContent>, which
114 #pod performs the check at release time, halting the release process if content is
115 #pod missing. Performing the check as a test makes it possible to check more
116 #pod frequently, and closer to the point of development.
117 #pod
118 #pod The algorithm is very naive. It looks for an unindented line starting with
119 #pod the version to be released. It then looks for any text from that line until
120 #pod the next unindented line (or the end of the file), ignoring whitespace.
121 #pod
122 #pod For example, in the file below, algorithm will find "- blah blah blah":
123 #pod
124 #pod Changes file for Foo-Bar
125 #pod
126 #pod {{$NEXT}}
127 #pod
128 #pod - blah blah blah
129 #pod
130 #pod 0.001 Wed May 12 13:49:13 EDT 2010
131 #pod
132 #pod - the first release
133 #pod
134 #pod If you had nothing but whitespace between C<{{$NEXT}}> and C<0.001>,
135 #pod the release would be halted.
136 #pod
137 #pod If you name your change log something other than "Changes", you can configure
138 #pod the name with the C<changelog> argument:
139 #pod
140 #pod [Test::ChangesHasContent]
141 #pod changelog = ChangeLog
142 #pod
143 #pod =head1 SEE ALSO
144 #pod
145 #pod * L<Dist::Zilla::Plugin::CheckChangesHasContent>
146 #pod * L<Dist::Zilla>
147 #pod
148 #pod =cut
149  
150 =pod
151  
152 =encoding UTF-8
153  
154 =head1 NAME
155  
156 Dist::Zilla::Plugin::Test::ChangesHasContent - Release test to ensure Changes has content
157  
158 =head1 VERSION
159  
160 version 0.011
161  
162 =head1 SYNOPSIS
163  
164 # in dist.ini
165  
166 [Test::ChangesHasContent]
167  
168 =head1 DESCRIPTION
169  
170 This plugin provides C<xt/release/changes_has_content.t>.
171  
172 This test ensures ensures that your Changes file actually has some content
173 since the last release.
174  
175 This can be contrasted to L<Dist::Zilla::Plugin::CheckChangesHasContent>, which
176 performs the check at release time, halting the release process if content is
177 missing. Performing the check as a test makes it possible to check more
178 frequently, and closer to the point of development.
179  
180 The algorithm is very naive. It looks for an unindented line starting with
181 the version to be released. It then looks for any text from that line until
182 the next unindented line (or the end of the file), ignoring whitespace.
183  
184 For example, in the file below, algorithm will find "- blah blah blah":
185  
186 Changes file for Foo-Bar
187  
188 {{$NEXT}}
189  
190 - blah blah blah
191  
192 0.001 Wed May 12 13:49:13 EDT 2010
193  
194 - the first release
195  
196 If you had nothing but whitespace between C<{{$NEXT}}> and C<0.001>,
197 the release would be halted.
198  
199 If you name your change log something other than "Changes", you can configure
200 the name with the C<changelog> argument:
201  
202 [Test::ChangesHasContent]
203 changelog = ChangeLog
204  
205 =for Pod::Coverage gather_files munge_files
206  
207 =head1 SEE ALSO
208  
209 * L<Dist::Zilla::Plugin::CheckChangesHasContent>
210 * L<Dist::Zilla>
211  
212 =head1 AUTHORS
213  
214 =over 4
215  
216 =item *
217  
218 David Golden <dagolden@cpan.org>
219  
220 =item *
221  
222 Karen Etheridge <ether@cpan.org>
223  
224 =back
225  
226 =head1 COPYRIGHT AND LICENSE
227  
228 This software is Copyright (c) 2017 by David Golden.
229  
230 This is free software, licensed under:
231  
232 The Apache License, Version 2.0, January 2004
233  
234 =cut
235  
236 __DATA__
↑ Summary blib/lib/Dist/Zilla/Plugin/CheckChangesHasContent.pm »