lib/ASPEER/MakeMaker/Markdown/Pod/MM.pm

filter: Statementstmt 29.0% 25 / 86 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 100% 3 / 3 Podpod 100% 3 / 3 totaltotal 17.9% 31 / 173 CC 32 SCAR 56.9
CC
32
Cov
16%
readme
462.0
doc
30.6
manifest_add
6.0
CRAP 295.6
↑ Summary blib/lib/ASPEER/MakeMaker/Markdown/Pod/Constant.pm »
1 #
2 # This file is part of ASPEER::MakeMaker::Markdown::Pod.
3 #
4 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 # Full license text is available at:
10 #
11 # <http://dev.perl.org/licenses/>
12 #
13 package ASPEER::MakeMaker::Markdown::Pod::MM;
14  
15  
16 # Compiler Pragma
17 #
18 use strict qw(vars);
19 use vars qw($VERSION @ISA $IMPORTED);
20 use warnings;
21 no warnings qw(uninitialized);
22 sub BEGIN {local $^W=0}
23  
24  
25 # Base packages and shared utility functions
26 #
27 use ASPEER::MakeMaker::MM ();
28 use ASPEER::MakeMaker::MM::Util;
29 use ASPEER::MakeMaker::Markdown::Pod::MM::Constant ();
30 @ISA=qw(ASPEER::MakeMaker::MM);
31  
32  
33 # External Packages
34 #
35 use Digest::MD5 qw(md5_hex);
36  
37  
38 # Version information in a formate suitable for CPAN etc. Must be
39 # all on one line
40 #
41 $VERSION='1.013';
42  
43  
44 # All done, init finished
45 #
46 1;
47  
48  
49 #======================================================================================================================
50  
51 # Makefile targets from here down
52 #
53 sub doc {
54  
55  
56 # Convert DocBook articles under doc to sibling Markdown files
57 #
58 6 ▶ my ($self, $param_hr)=(shift(), arg(@_));
Subroutine doc: called CC=11 SCAR=34.2
Pod documented
59 6 msg($self);
60 6 ▶ if (-d 'doc') {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "doc") 0 0 0
61 6 require Docbook::Convert::Pandoc;
62 6 my $docbook_or=Docbook::Convert::Pandoc->new();
63 6 my $changed_fn_ar=$docbook_or->convert_articles('doc');
64 6 msg('docbook: %s: updated', $_) foreach @{$changed_fn_ar};
65 }
66  
67  
68 # Convert MD files to POD
69 #
70 6 my $exe_files_ar=$param_hr->{'EXE_FILES_AR'};
71 6 my %exe_files=map {$_ => 1} @{$exe_files_ar};
72 6 require Markdown::Pod::Embed;
73  
74  
75 # Get manifest - only convert files in manifest
76 #
77 6 require ExtUtils::Manifest;
78 6 my $manifest_hr=ExtUtils::Manifest::maniread();
79  
80  
81 # Hash to hold files we generate so not processed twice
82 #
83 6 my %ignore_fn;
84  
85  
86 # Look for all Markdown files ignoring ones we created ourselves
87 #
88 6 ▶ my @manifest_md_fn=sort grep {/\.md$/ && !m{^t/}} keys %{$manifest_hr};
Condition0%0/3
/\.md$/ && !m[^t/]
!ll&&!rl&&r
000
MC/DC0%0/2
/\.md$/ && !m[^t/]
/\.md$/ !m[^t/]
Truth table0%0/3
A && not(B)
A= /\.md$/B= !m[^t/]
ABresult
0X0
100
111
89 6 @manifest_md_fn=grep {!$ignore_fn{$_}} @manifest_md_fn;
90  
91  
92 # Iterate
93 #
94 6 foreach my $fn (@manifest_md_fn) {
95  
96 # Get target file name. If foo.pm.md, bar.pl.md and foo.pm or bar.pl exists, then
97 # convert Markdown to POD and install into target file.
98 #
99  
100 #
101 6 (my $target_fn=$fn)=~s/\.md$//;
102  
103 6 ▶ if ($target_fn=~/\.pm$/ || $target_fn=~/\.pl$/ || $exe_files{$target_fn}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_fn =~ /\.pm$/ or $target_fn =~ /\.pl$/ or $exe_files{$target_fn}) { } 0 0 0
Condition0%0/6
$target_fn =~ /\.pm$/ or $target_fn =~ /\.pl$/ or $exe_files{$target_fn}
l!l&&r!l&&!r
000
$target_fn =~ /\.pm$/ or $target_fn =~ /\.pl$/
l!l&&r!l&&!r
000
MC/DC0%0/3
$target_fn =~ /\.pm$/ or $target_fn =~ /\.pl$/ or $exe_files{$target_fn}
$target_fn =~ /\.pm$/ $target_fn =~ /\.pl$/ $exe_files{$target_fn}
Truth table0%0/4
A or B or C
A= $target_fn =~ /\.pm$/B= $target_fn =~ /\.pl$/C= $exe_files{$target_fn}
ABCresult
1XX1
01X1
0011
0000
104 6 ▶ unless (-f $target_fn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $target_fn) 0 0 0
105 0 verbose("markpod: %s -> %s: skipped, missing target", $fn, $target_fn);
106 0 next;
107 }
108 0 msg("markpod: %s -> %s: starting merge", $fn, $target_fn);
109 0 my $markpod_or=Markdown::Pod::Embed->new();
110 0 my $pod_changed=$markpod_or->markpod_process_and_update($target_fn);
111 0 ▶ if (!defined $pod_changed) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $pod_changed) { } 0 0 0
elsif ($pod_changed) { } 0 0 0
112 0 msg("markpod: %s -> %s: finished, skipped", $fn, $target_fn);
113 }
114 elsif ($pod_changed) {
115 0 msg("markpod: %s -> %s: finished, updated pod", $fn, $target_fn);
116 }
117 else {
118 0 msg("markpod: %s -> %s: finished, no changes", $fn, $target_fn);
119 }
120 }
121 else {
122 0 verbose("markpod: %s -> %s: skipped, unsupported target", $fn, $target_fn);
123  
124 }
125  
126 }
127  
128  
129 # Done
130 #
131 0 return undef;
132  
133 }
134  
135  
136 sub readme {
137  
138  
139 # Build README files from README.md or VERSION_FROM markdown
140 #
141 0 ▶ my ($self, $param_hr)=(shift(), arg(@_));
Subroutine readme: called CC=21 SCAR=61.4
Pod documented
142 0 require Markdown::Pod::Embed;
143  
144  
145 # Get manifest for any file additions we make
146 #
147 0 require ExtUtils::Manifest;
148 0 my $manifest_hr=ExtUtils::Manifest::maniread();
149 0 my @manifest_add;
150 0 my $version_from_fn=$param_hr->{'VERSION_FROM'};
151 0 my $readme_md_fn='README.md';
152 0 my $readme_fn='README';
153 0 my $markpod_or=Markdown::Pod::Embed->new();
154 0 my $md;
155 my $source_fn;
156  
157  
158 # Use an existing Markdown README when one is available
159 #
160 0 ▶ if (-f $readme_md_fn) {
Branch: 3 branches
BranchTrueFalseTotal
if (-f $readme_md_fn) { } 0 0 0
elsif (-e $readme_md_fn or -l $readme_md_fn) { } 0 0 0
elsif (-e $readme_fn or -l $readme_fn) { } 0 0 0
161 0 $source_fn=$readme_md_fn;
162 0 $md=slurp($readme_md_fn);
163 }
164 ▶ elsif (-e $readme_md_fn || -l $readme_md_fn) {
Condition0%0/3
-e $readme_md_fn or -l $readme_md_fn
l!l&&r!l&&!r
000
MC/DC0%0/2
-e $readme_md_fn or -l $readme_md_fn
-e $readme_md_fn -l $readme_md_fn
Truth table0%0/3
A or B
A= -e $readme_md_fnB= -l $readme_md_fn
ABresult
1X1
011
000
165 0 return err("$readme_md_fn exists and is not a regular file");
166 }
167 ▶ elsif (-e $readme_fn || -l $readme_fn) {
Condition0%0/3
-e $readme_fn or -l $readme_fn
l!l&&r!l&&!r
000
MC/DC0%0/2
-e $readme_fn or -l $readme_fn
-e $readme_fn -l $readme_fn
Truth table0%0/3
A or B
A= -e $readme_fnB= -l $readme_fn
ABresult
1X1
011
000
168 0 verbose('markpod: %s exists without %s, leaving both unchanged', $readme_fn, $readme_md_fn);
169 0 return undef;
170 }
171 else {
172 0 ▶ unless (defined $version_from_fn && length $version_from_fn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $version_from_fn and length $version_from_fn) 0 0 0
Condition0%0/3
defined $version_from_fn and length $version_from_fn
!ll&&!rl&&r
000
MC/DC0%0/2
defined $version_from_fn and length $version_from_fn
defined $version_from_fn length $version_from_fn
Truth table0%0/3
A and B
A= defined $version_from_fnB= length $version_from_fn
ABresult
0X0
100
111
173 0 verbose('markpod: no VERSION_FROM file, no README files created');
174 0 return undef;
175 }
176 0 $md=$markpod_or->markpod_markdown_source($version_from_fn);
177 0 ▶ unless (defined $md && length $md) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $md and length $md) 0 0 0
Condition0%0/3
defined $md and length $md
!ll&&!rl&&r
000
MC/DC0%0/2
defined $md and length $md
defined $md length $md
Truth table0%0/3
A and B
A= defined $mdB= length $md
ABresult
0X0
100
111
178 0 msg('markpod: %s -> %s: skipped, no markdown source', $version_from_fn, $readme_fn);
179 0 return undef;
180 }
181 0 my $readme_md=$md;
182 0 ▶ $readme_md.=$/ unless $readme_md=~/\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $readme_md =~ /\n\z/ 0 0 0
183 0 ▶ blurp($readme_md_fn, $readme_md) ||
Branch: 1 branch
BranchTrueFalseTotal
blurp($readme_md_fn, $readme_md) or return err() 0 0 0
184 return err();
185 0 ▶ push @manifest_add, $readme_md_fn unless exists $manifest_hr->{$readme_md_fn};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $manifest_hr->{$readme_md_fn} 0 0 0
186 0 $source_fn=$readme_md_fn;
187 }
188 0 msg('markpod: %s -> %s: starting render', $source_fn, $readme_fn);
189  
190  
191 # No markdown means nothing to render
192 #
193 0 ▶ unless (defined $md && length $md) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $md and length $md) 0 0 0
Condition0%0/3
defined $md and length $md
!ll&&!rl&&r
000
MC/DC0%0/2
defined $md and length $md
defined $md length $md
Truth table0%0/3
A and B
A= defined $mdB= length $md
ABresult
0X0
100
111
194 0 msg('markpod: %s -> %s: finished, skipped empty markdown source', $source_fn, $readme_fn);
195 0 ▶ manifest_add(\@manifest_add) if @manifest_add;
Branch: 1 branch
BranchTrueFalseTotal
if @manifest_add 0 0 0
196 0 return undef;
197 }
198  
199  
200 # Convert markdown to text
201 #
202 0 my $text=$markpod_or->markpod_markdown_text($md);
203  
204  
205 # Update README only when changed
206 #
207 0 ▶ my $existing_readme=-f $readme_fn ? slurp($readme_fn) : '';
Branch: 1 branch
BranchTrueFalseTotal
-f $readme_fn ? : 0 0 0
208 0 ▶ if (md5_hex($existing_readme) ne md5_hex($text)) {
Branch: 1 branch
BranchTrueFalseTotal
if (md5_hex($existing_readme) ne md5_hex($text)) { } 0 0 0
209 0 ▶ $markpod_or->outfile($text, $readme_fn) ||
Branch: 1 branch
BranchTrueFalseTotal
$markpod_or->outfile($text, $readme_fn) or return err() 0 0 0
210 return err();
211 0 msg('markpod: %s -> %s: finished, updated', $source_fn, $readme_fn);
212 }
213 else {
214 0 msg('markpod: %s -> %s: finished, no changes', $source_fn, $readme_fn);
215 }
216  
217 0 ▶ push @manifest_add, $readme_fn unless exists $manifest_hr->{$readme_fn};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $manifest_hr->{$readme_fn} 0 0 0
218 0 ▶ manifest_add(\@manifest_add) if @manifest_add;
Branch: 1 branch
BranchTrueFalseTotal
if @manifest_add 0 0 0
219  
220 }
221  
222  
223 sub manifest_add {
224  
225 0 ▶ my ($file_ar)=@_;
Subroutine manifest_add: called CC=2 SCAR=17.9
Pod documented
226 0 ▶ return undef unless @{$file_ar};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$file_ar;} 0 0 0
227 0 require ExtUtils::Manifest;
228 0 my %add=map { $_ => '' } @{$file_ar};
229 0 ExtUtils::Manifest::maniadd(\%add);
230 0 return 1;
231  
232 }
233  
234  
235 1;
236  
237  
238 __END__
↑ Summary blib/lib/ASPEER/MakeMaker/Markdown/Pod/Constant.pm »