Pod/Weaver/Section/RecentChanges.pm

filter: Statementstmt 95.0% 77 / 81 Branchbran 76.4% 26 / 34 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 1 totaltotal 83.5% 122 / 146 CC 21 SCAR 25.5
CC
21
Cov
85%
weave_section
23.0
_release_to_pod
3.0
BEGIN
1.0
CRAP 12.8
↑ Summary Pod/Weaver/Section/InstallationInstructions.pm »
1 package Pod::Weaver::Section::RecentChanges;
2  
3 # ABSTRACT: generate POD with the recent changes
4  
5 10 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 with 'Pod::Weaver::Role::Section';
9  
10 10 ▶use CPAN::Changes::Parser 0.500002;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use List::Util qw( first );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use MooseX::MungeHas;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use Pod::Elemental::Element::Nested;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use Pod::Elemental::Element::Pod5::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 ▶use Pod::Elemental::Element::Pod5::Ordinary;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 ▶use Pod::Elemental::Element::Pod5::Region;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶use Types::Common qw( Bool NonEmptySimpleStr SimpleStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 10 ▶use experimental qw( lexical_subs signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 10 our $VERSION = 'v0.6.0';
24  
25  
26 10 has header => (
27 is => 'rw',
28 isa => NonEmptySimpleStr,
29 default => 'RECENT CHANGES',
30 );
31  
32  
33 10 has changelog => (
34 is => 'rw',
35 isa => SimpleStr,
36 default => 'Changes',
37 );
38  
39  
40 10 has version => (
41 is => 'rw',
42 isa => SimpleStr,
43 default => '',
44 );
45  
46  
47 10 has region => (
48 is => 'rw',
49 isa => SimpleStr,
50 default => '',
51 );
52  
53  
54 10 has all_modules => (
55 is => 'rw',
56 isa => Bool,
57 default => 0,
58 );
59  
60 10 ▶sub weave_section( $self, $document, $input ) {
Subroutine weave_section: called CC=19 SCAR=31.3
Pod undocumented
61  
62 10 my $zilla = $input->{zilla};
63  
64 10 ▶ unless ($zilla) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($zilla) 0 10 10
65 0 $self->log_fatal("missing zilla argument");
66 0 return;
67 }
68  
69 10 ▶ if ( $zilla && !$self->all_modules ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zilla and not $self->all_modules) 10 0 10
Condition33%1/3
$zilla and not $self->all_modules
!ll&&!rl&&r
0010
MC/DC0%0/2
$zilla and not $self->all_modules
$zilla not $self->all_modules
Truth table33%1/3
A and not(B)
A= $zillaB= not $self->all_modules
ABresult
0X0
100
111
70 10 ▶ return if $zilla->main_module->name ne $input->{filename};
Branch: 1 branch
BranchTrueFalseTotal
if $zilla->main_module->name ne $input->{"filename"} 0 10 10
71 }
72  
73 10 ▶ if ( my $stash = $zilla ? $zilla->stash_named('%PodWeaver') : undef ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $stash = $zilla ? $zilla->stash_named("%PodWeaver") : undef) 1 9 10
$zilla ? : 10 0 10
74 1 $stash->merge_stashed_config($self);
75 }
76  
77 10 ▶ if ( my $next = first { $_->isa("Dist::Zilla::Plugin::NextRelease") } $zilla->plugins->@* ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = &first(sub { $_->isa("Dist::Zilla::Plugin::NextRelease"); } , @{$zilla->plugins})) 7 3 10
78 7 my $filename = $next->update_filename;
79 7 ▶ if ( $self->changelog eq "" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->changelog eq '') { } 1 6 7
elsif ($self->changelog ne $filename) { } 0 6 6
80 1 $self->changelog($filename);
81 }
82 elsif ( $self->changelog ne $filename ) {
83 0 $self->log_fatal("changelog is different file ${filename} used by NextRelease");
84 }
85 }
86  
87 10 ▶ if ( $self->changelog eq "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->changelog eq "") 0 10 10
88 0 $self->changelog("Changes");
89 }
90  
91 10 ▶ my $file = first { $_->name eq $self->changelog } $zilla->files->@* or return;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
my $file = &first(sub { $_->name eq $self->changelog; } , @{$zilla->files}) or return 7 3 10
92  
93 7 ▶ my $version = $self->version || ( $input->{version} // $zilla->version );
Condition33%2/6
$self->version || ($input->{'version'} // $zilla->version)
l!l&&r!l&&!r
070
$input->{"version"} // $zilla->version
l!l&&r!l&&!r
700
MC/DC0%0/3
$self->version || ($input->{'version'} // $zilla->version)
$self->version $input->{"version"} $zilla->version
Truth table25%1/4
A || B // C
A= $self->versionB= $input->{"version"}C= $zilla->version
ABCresult
1XX1
01X1
0011
0000
94  
95 7 my $re = quotemeta($version);
96 7 my $parser = CPAN::Changes::Parser->new( version_like => qr/$re/ );
97  
98 7 my $changelog = $parser->parse_string( $file->content );
99  
100 # Ignore if there is only one release, e.g. "Initial release"
101 7 ▶ return if $changelog->releases <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $changelog->releases <= 1 1 6 7
102  
103 27 ▶ state sub _release_to_pod($entry) {
Subroutine _release_to_pod: called CC=3 SCAR=11.0
104  
105 27 my $pod = [];
106 27 ▶ push $pod->@*,
Branch: 1 branch
BranchTrueFalseTotal
if $entry->can("text") 21 6 27
107 (
108 Pod::Elemental::Element::Pod5::Command->new(
109 {
110 command => 'item',
111 content => '*'
112 }
113 ),
114 Pod::Elemental::Element::Pod5::Ordinary->new( { content => $entry->text } )
115 ) if $entry->can("text");
116  
117 27 ▶ if ( my @entries = $entry->entries->@* ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@entries) = @{$entry->entries}) 15 12 27
118  
119 push $pod->@*,
120 (
121 Pod::Elemental::Element::Pod5::Command->new(
122 {
123 command => 'over',
124 content => '4',
125 }
126 ),
127 15 ( map { __SUB__->($_) } @entries ),
128 Pod::Elemental::Element::Pod5::Command->new(
129 {
130 command => 'back',
131 content => '',
132 }
133 )
134 );
135 }
136  
137 27 return $pod->@*;
138  
139 }
140  
141 6 ▶ my $release = $changelog->find_release($version) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $release = $changelog->find_release($version) or return 6 0 6
142  
143 6 ▶ my @entries = _release_to_pod($release) or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@entries) = _release_to_pod($release) or return 5 1 6
144  
145 5 my $text = "Changes for version " . $version;
146 5 ▶ if ( my $date = $release->date ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $date = $release->date) 5 0 5
147 5 $text .= sprintf( ' (%s)', substr( $date, 0, 10 ) );
148 }
149  
150 5 my $res = Pod::Elemental::Element::Nested->new(
151 {
152 type => 'command',
153 command => 'head1',
154 content => $self->header,
155 children => [
156 Pod::Elemental::Element::Pod5::Ordinary->new( { content => $text } ),
157 @entries,
158 Pod::Elemental::Element::Pod5::Ordinary->new(
159 { content => sprintf( 'See the F<%s> file for more details.', $self->changelog ) }
160 )
161 ],
162 }
163 );
164  
165 5 ▶ if ( my $name = $self->region ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $self->region) { } 1 4 5
166  
167 1 push $document->children->@*,
168 Pod::Elemental::Element::Pod5::Region->new(
169 {
170 format_name => $name =~ s/^://r,
171 is_pod => 1,
172 content => '',
173 children => [$res],
174 }
175 );
176  
177 }
178 else {
179 4 push $document->children->@*, $res;
180 }
181  
182 }
183  
184 10 __PACKAGE__->meta->make_immutable;
185  
186 __END__
↑ Summary Pod/Weaver/Section/InstallationInstructions.pm »