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

filter: Statementstmt 100% 51 / 51 Branchbran 65.0% 13 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 91.2% 73 / 80 CC 13 SCAR 16.3
CC
13
Cov
90%
has_version
7.5
after_build
6.0
__ANON__
2.1
CRAP 5.1
↑ Summary
1 package Dist::Zilla::Plugin::CheckChangeLog;
2 2 $Dist::Zilla::Plugin::CheckChangeLog::VERSION = '0.05';
3 # ABSTRACT: Dist::Zilla with Changes check
4  
5 2 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 with 'Dist::Zilla::Role::AfterBuild';
9  
10 2 has filename => (
11 is => 'ro',
12 isa => 'Str'
13 );
14  
15 4 ▶sub after_build {
Subroutine after_build: called CC=6 SCAR=17.9
Pod documented
16 4 my ($self, $args) = @_;
17  
18 4 my $root = $args->{build_root};
19 4 my $filename = $self->{filename};
20 4 my @change_files;
21  
22 4 ▶ if ($filename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename) { } 2 2 4
23 2 chomp($filename);
24 2 ▶ die "[CheckChangeLog] $! $filename\n" unless -e $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $filename 0 2 2
25 2 push @change_files, Dist::Zilla::File::OnDisk->new({name => $filename});
26 } else {
27 # Search for Changes or ChangeLog on build root
28 2 my @files = $self->_find_change_files($root);
29 2 ▶ die "[CheckChangeLog] No changelog file found.\n" unless scalar @files;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @files 0 2 2
30 2 push @change_files, @files;
31 }
32  
33 4 for my $file (@change_files) {
34 4 ▶ if ($self->has_version($file->content, $self->zilla->version)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_version($file->content, $self->zilla->version)) 2 2 4
35 2 $self->log("[CheckChangeLog] OK with " . $file->name);
36 2 return;
37 }
38 }
39  
40 2 my $msg = "[CheckChangeLog] No Change Log in ";
41 2 $msg .= join(', ', map { $_->name } @change_files) . "\n";
42 2 $self->log($msg);
43 2 $msg = "[CheckChangeLog] Update your Changes file with an entry for ";
44 2 $msg .= $self->zilla->version . "\n";
45 2 die $msg;
46 }
47  
48 4 ▶sub has_version {
Subroutine has_version: called CC=7 SCAR=20.2
Pod documented
49 4 my ($self, $content, $version) = @_;
50  
51 4 for my $line (split(/\n/, $content)) {
52  
53 # no blank lines
54 3 ▶ next unless $line =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/ 0 3 3
55  
56 # skip things that look like bullets
57 3 ▶ next if $line =~ /^\s+/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s+/ 0 3 3
58 3 ▶ next if $line =~ /^\*/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\*/ 0 3 3
59 3 ▶ next if $line =~ /^\-/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\-/ 0 3 3
60  
61 # seen it?
62 3 ▶ return 1 if $line =~ /\Q$version\E/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\Q$version\E/ 2 1 3
63 }
64 2 return 0;
65 }
66  
67 2 ▶sub _find_change_files {
Subroutine _find_change_files: called CC=1 SCAR=0.0
68 2 my ($self, $root) = @_;
69 2 my $files = $self->zilla->files;
70 2 my $change_file_re = qr/Change(?:s|Log)?/i;
71 2 ▶ my $filter = sub { -e "$root/$_->{name}" && $_->{name} =~ $change_file_re };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
-e qq[$root/$_->{"name"}] and $_->{"name"} =~ /$change_file_re/ 8 0 8
72 2 grep { $filter->($_) } @{$files};
73 }
74  
75 2 __PACKAGE__->meta->make_immutable;
76 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 2 1;
79  
80 __END__
↑ Summary