| 1 | 2 | ▶ | use 5.10.0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Dist::Zilla::Plugin::NextRelease::Grouped; | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | # ABSTRACT: Simplify usage of a grouped changelog | ||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.0200'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use MooseX::AttributeShortcuts; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 2 | ▶ | use Types::Standard qw/Str ArrayRef Bool/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 2 | ▶ | use Path::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 2 | ▶ | use List::Util qw/none/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 2 | ▶ | use CPAN::Changes; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 2 | ▶ | use CPAN::Changes::Release; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 2 | ▶ | use Safe::Isa qw/$_call_if_object/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 2 | ▶ | use String::Formatter stringf => { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.7
| |||||||||||||||||||||
| 22 | -as => 'header_formatter', | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | input_processor => 'require_single_input', | ||||||||||||||||||||
| 25 | string_replacer => 'method_replace', | ||||||||||||||||||||
| 26 | codes => { | ||||||||||||||||||||
| 27 | 5 | ▶ | v => sub { shift->zilla->version }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 5 | ▶ | d => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | 5 | require DateTime; | |||||||||||||||||||
| 30 | 5 | DateTime->now->set_time_zone(shift->time_zone)->format_cldr(shift); | |||||||||||||||||||
| 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 | 0 | ▶ | E => sub { shift->user_info('email') }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 35 | 0 | ▶ | U => sub { shift->user_info('name') }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 36 | 4 | ▶ | T => sub { shift->zilla->is_trial ? (shift || '-TRIAL') : '' }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
Branch: 1 branch
Condition50%1/2
shift() or "-TRIAL"
MC/DC0%0/1
shift() or "-TRIAL"
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 37 | 0 | ▶ | V => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 38 | 0 | my $zilla = (shift)->zilla; | |||||||||||||||||||
| 39 | 0 | ▶ | return $zilla->version . ($zilla->is_trial ? (shift || '-TRIAL') : ''); | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
shift() or "-TRIAL"
MC/DC0%0/1
shift() or "-TRIAL"
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 40 | }, | ||||||||||||||||||||
| 41 | 1 | ▶ | P => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 42 | 1 | my $self = shift; | |||||||||||||||||||
| 43 | 1 | my($releaser) = grep { $_->can('cpanid') } @{ $self->zilla->plugins_with('-Releaser') }; | |||||||||||||||||||
| 44 | 1 | ▶ | $self->log_fatal(q{releaser doesn't provide cpanid, but %P used}) unless $releaser; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 1 | return $releaser->cpanid; | |||||||||||||||||||
| 47 | }, | ||||||||||||||||||||
| 48 | }, | ||||||||||||||||||||
| 49 | 2 | }; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 2 | with qw/ | |||||||||||||||||||
| 52 | Dist::Zilla::Role::Plugin | ||||||||||||||||||||
| 53 | Dist::Zilla::Role::FileMunger | ||||||||||||||||||||
| 54 | Dist::Zilla::Role::AfterRelease | ||||||||||||||||||||
| 55 | /; | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 2 | has filename => ( | |||||||||||||||||||
| 58 | is => 'ro', | ||||||||||||||||||||
| 59 | isa => Str, | ||||||||||||||||||||
| 60 | default => 'Changes', | ||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||
| 62 | 2 | has time_zone => ( | |||||||||||||||||||
| 63 | is => 'ro', | ||||||||||||||||||||
| 64 | isa => Str, | ||||||||||||||||||||
| 65 | default => 'local', | ||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||
| 67 | 2 | has user_stash => ( | |||||||||||||||||||
| 68 | is => 'ro', | ||||||||||||||||||||
| 69 | isa => Str, | ||||||||||||||||||||
| 70 | default => '%User', | ||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||
| 72 | 2 | has format_version => ( | |||||||||||||||||||
| 73 | is => 'ro', | ||||||||||||||||||||
| 74 | isa => Str, | ||||||||||||||||||||
| 75 | default => '%v', | ||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||
| 77 | 2 | has format_date => ( | |||||||||||||||||||
| 78 | is => 'ro', | ||||||||||||||||||||
| 79 | isa => Str, | ||||||||||||||||||||
| 80 | default => '%{yyyy-MM-dd HH:mm:ss VVVV}d', | ||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||
| 82 | 2 | has format_note => ( | |||||||||||||||||||
| 83 | is => 'ro', | ||||||||||||||||||||
| 84 | isa => Str, | ||||||||||||||||||||
| 85 | default => '%{ (TRIAL RELEASE)}T', | ||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||
| 87 | has groups => ( | ||||||||||||||||||||
| 88 | is => 'ro', | ||||||||||||||||||||
| 89 | 5 | ▶ | isa => (ArrayRef[Str])->plus_coercions(Str, sub { [split m{\s*,\s*}, $_] }), | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 90 | traits => ['Array'], | ||||||||||||||||||||
| 91 | coerce => 1, | ||||||||||||||||||||
| 92 | 0 | ▶ | default => sub { ['API Changes', 'Bug Fixes', 'Enhancements', 'Documentation'] }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 93 | 2 | handles => { | |||||||||||||||||||
| 94 | all_groups => 'elements', | ||||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||
| 97 | 2 | has auto_order => ( | |||||||||||||||||||
| 98 | is => 'ro', | ||||||||||||||||||||
| 99 | isa => Bool, | ||||||||||||||||||||
| 100 | default => 1, | ||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 2 | has _changes_after_munging => ( | |||||||||||||||||||
| 104 | is => 'rw', | ||||||||||||||||||||
| 105 | isa => Str, | ||||||||||||||||||||
| 106 | init_arg => undef, | ||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | ▶ | sub user_info { | ||||||||||||||||||
|
Subroutine
user_info: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||
| 112 | 0 | my $field = shift; | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 0 | state $stash = $self->zilla->stash_named($self->user_stash); | |||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 0 | my $value = $stash->$_call_if_object($field); | |||||||||||||||||||
| 117 | 0 | ▶ | if(!defined $value) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 118 | 0 | $self->log_fatal(['You must enter your %s in the [%s] section of ~/.dzil/config.ini', $field, $self->user_stash]); | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | 0 | return $value; | |||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 5 | ▶ | sub munge_files { | ||||||||||||||||||
|
Subroutine
munge_files: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 124 | 5 | my $self = shift; | |||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 5 | my($file) = grep { $_->name eq $self->filename } @{ $self->zilla->files }; | |||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 5 | my $changes = CPAN::Changes->load_string($file->content, next_token => $self->_next_token); | |||||||||||||||||||
| 129 | 5 | my $next = ($changes->releases)[-1]; | |||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 5 | ▶ | return if !defined $next; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 5 | $next->version(header_formatter($self->format_version, $self)); | |||||||||||||||||||
| 134 | 5 | $next->date(header_formatter($self->format_date, $self)); | |||||||||||||||||||
| 135 | 5 | $next->note(header_formatter($self->format_note, $self)); | |||||||||||||||||||
| 136 | 5 | $next->delete_empty_groups; | |||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 5 | $self->log_debug(['Cleaning up %s in memory', $file->name]); | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 1 | ▶ | my $sort_groups = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 141 | 1 | ▶ | my @custom_groups = grep { my $group = $_; none { $group eq $_ } $self->all_groups } @_; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 142 | 1 | my @sorted = ((sort { $a cmp $b } @custom_groups), $self->all_groups); | |||||||||||||||||||
| 143 | 1 | return @sorted; | |||||||||||||||||||
| 144 | 5 | }; | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 5 | ▶ | my $content = $self->auto_order ? $changes->serialize : $changes->serialize(group_sort => $sort_groups); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | # hack to remove empty groups | ||||||||||||||||||||
| 149 | 5 | ▶ | if(!$self->auto_order) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | # followed by another group | ||||||||||||||||||||
| 152 | 3 | $content =~ s{ | |||||||||||||||||||
| 153 | (?<= [\n\r] ) | ||||||||||||||||||||
| 154 | [\s\t]+ \[ [^\]]+ \] [\s\t]* | ||||||||||||||||||||
| 155 | [\n\r]+ | ||||||||||||||||||||
| 156 | (?= [\s\t]+ \[ [^\]]+ \] ) | ||||||||||||||||||||
| 157 | }{\n}xmsg; | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | # followed by a release | ||||||||||||||||||||
| 160 | 3 | $content =~ s{ | |||||||||||||||||||
| 161 | (?<=[\n\r]) | ||||||||||||||||||||
| 162 | [\s\t]+ \[ [^\]]+ \] [\s\t]* | ||||||||||||||||||||
| 163 | [\n\r]+ | ||||||||||||||||||||
| 164 | (?=[v\d]) | ||||||||||||||||||||
| 165 | }{\n}xmsg; | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | # followed by end-of-file | ||||||||||||||||||||
| 168 | 3 | $content =~ s{ | |||||||||||||||||||
| 169 | (?<= [\n\r]) | ||||||||||||||||||||
| 170 | [\s\t]+ \[ [^\]]+ \] [\s\t]* | ||||||||||||||||||||
| 171 | [\n\r]* | ||||||||||||||||||||
| 172 | \z | ||||||||||||||||||||
| 173 | }{\n}xmsg; | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | # just one final \n | ||||||||||||||||||||
| 176 | 3 | $content =~ s{\n+\z}{\n}ms; | |||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | # cleanup whitespace | ||||||||||||||||||||
| 179 | 3 | $content =~ s{\r}{}g; | |||||||||||||||||||
| 180 | 3 | $content =~ s{\n{3,}}{\n\n}g; | |||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | # ensure that a release header (any line starting with \d or 'v') isn't followed by an empty line. | ||||||||||||||||||||
| 183 | 3 | $content =~ s{(\n [v\d] [^\n]+) \n{2,} (?=[\s\t]) }{$1\n}msgx; | |||||||||||||||||||
| 184 | } | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | 5 | $file->content($content); | |||||||||||||||||||
| 187 | 5 | $self->_changes_after_munging($content); | |||||||||||||||||||
| 188 | } | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | 5 | ▶ | sub after_release { | ||||||||||||||||||
|
Subroutine
after_release: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 191 | 5 | my $self = shift; | |||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | 5 | my $changes = CPAN::Changes->load_string($self->_changes_after_munging, next_token => $self->_next_token); | |||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | 5 | my $next = CPAN::Changes::Release->new(version => '{{$NEXT}}'); | |||||||||||||||||||
| 196 | 5 | $next->add_group($self->all_groups); | |||||||||||||||||||
| 197 | 5 | $changes->add_release($next); | |||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | 5 | path($self->filename)->spew({ binmode => $self->binmode }, $changes->serialize); | |||||||||||||||||||
| 200 | } | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | 10 | ▶ | sub _next_token { qr/\{\{\$NEXT\}\}/ } | ||||||||||||||||||
|
Subroutine
_next_token: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | 5 | ▶ | sub binmode { | ||||||||||||||||||
|
Subroutine
binmode: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 205 | 5 | my $self = shift; | |||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | 5 | my($file) = grep { $_->name eq $self->filename } @{ $self->zilla->files }; | |||||||||||||||||||
| 208 | 0 | ▶ | $self->log_fatal("failed to find @{[ $self->filename ]} in the distribution") if !$file; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | 5 | return sprintf ':raw:encoding(%s)', $file->encoding; | |||||||||||||||||||
| 211 | } | ||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 214 | |||||||||||||||||||||
| 215 | 2 | 1; | |||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | __END__ | ||||||||||||||||||||