lib/Markdown/Publish.pm

filter: Statementstmt 84.8% 432 / 509 Branchbran 70.3% 187 / 266 Conditioncond 67.0% 108 / 161 MC/DCmcdc 46.3% 44 / 95 Subroutinesub 87.7% 50 / 57 Podpod 23.6% 9 / 38 totaltotal 73.7% 830 / 1126 CC 201 SCAR 27.1
CC
201
Cov
78%
markdown_title
57.0
publish_gh
56.0
split
25.3
CRAP 15.0
« blib/lib/Markdown/Publish/VitePress.pm ↑ Summary lib/Markdown/Publish/MkDocs.pm »
1 #
2 # This file is part of Markdown::Publish.
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 Markdown::Publish;
14  
15  
16 # Compiler pragma and package variables
17 #
18 2 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use vars qw($VERSION $AUTHORITY);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 # Core and external packages
24 #
25 2 ▶use Cwd qw(abs_path getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use File::Copy qw(copy);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use IPC::Run3 qw(run3);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use JSON::PP qw(decode_json encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use Markdown::Publish::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36  
37 # Version information
38 #
39 2 $AUTHORITY='cpan:ASPEER';
40 2 $VERSION='1.004';
41  
42  
43 # Supported publication actions
44 #
45 2 my %ACTION=map {$_ => 1} qw(build serve gh gh-push cloudflare);
46  
47  
48 # Short names for the publisher classes supplied by this distribution
49 #
50 2 my %module_alias=(
51 mkdocs => 'Markdown::Publish::MkDocs',
52 vitepress => 'Markdown::Publish::VitePress',
53 docusaurus => 'Markdown::Publish::Docusaurus',
54 starlight => 'Markdown::Publish::Starlight'
55 );
56  
57  
58 # Done
59 #
60 2 1;
61  
62  
63 #======================================================================================================================
64  
65 82 ▶sub new {
Subroutine new: called CC=13 SCAR=25.8
Pod documented
66  
67 82 my ($class, $opt_hr)=@_;
68 82 ▶ $opt_hr={} unless defined($opt_hr);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt_hr 13 69 82
69 82 ▶ die "publication configuration must be a hash reference\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opt_hr eq "HASH" 0 82 82
70 unless ref($opt_hr) eq 'HASH';
71 82 ▶ if ($class eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 20 62 82
72 20 ▶ if (exists($opt_hr->{'config_file'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt_hr->{"config_file"}) 2 18 20
73 die "config_file cannot be combined with inline publication settings\n"
74 2 ▶ unless keys(%{$opt_hr})==1;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$opt_hr;} == 1 1 1 2
75 1 return $class->load_config($opt_hr->{'config_file'});
76 }
77 my $publisher=defined($ENV{'MARKDOWN_PUBLISH_MODULE'}) ?
78 $ENV{'MARKDOWN_PUBLISH_MODULE'} :
79 18 ▶ (exists($opt_hr->{'module'}) ? $opt_hr->{'module'} : $MARKDOWN_PUBLISH_MODULE);
Branch: 2 branches
BranchTrueFalseTotal
defined $ENV{'MARKDOWN_PUBLISH_MODULE'} ? : 4 14 18
exists $opt_hr->{'module'} ? : 12 2 14
80 18 ▶ die "publication module is not defined\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $publisher and length $publisher 0 18 18
Condition33%1/3
defined $publisher and length $publisher
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $publisher and length $publisher
defined $publisher length $publisher
Truth table33%1/3
A and B
A= defined $publisherB= length $publisher
ABresult
0X0
100
111
81 unless defined($publisher) && length($publisher);
82 18 ▶ $publisher=$module_alias{lc($publisher)} || $publisher;
Condition66%2/3
$module_alias{lc $publisher} || $publisher
l!l&&r!l&&!r
7110
MC/DC0%0/2
$module_alias{lc $publisher} || $publisher
$module_alias{lc $publisher} $publisher
Truth table66%2/3
A || B
A= $module_alias{lc $publisher}B= $publisher
ABresult
1X1
011
000
83 18 (my $publisher_fn=$publisher)=~s{::}{/}g;
84 18 my $loaded=eval {
85 18 require "$publisher_fn.pm";
86 16 1;
87 };
88 18 ▶ die "unable to load publication module $publisher: $@"
Branch: 1 branch
BranchTrueFalseTotal
unless $loaded 2 16 18
89 unless $loaded;
90 16 ▶ die "$publisher is not a Markdown::Publish subclass\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $publisher->isa(__PACKAGE__) 1 15 16
91 unless $publisher->isa(__PACKAGE__);
92 15 return $publisher->new($opt_hr);
93 }
94 62 my $self=bless({%{$opt_hr}}, $class);
95 62 return $self;
96  
97 }
98  
99  
100 5 ▶sub load_config {
Subroutine load_config: called CC=6 SCAR=18.3
Pod documented
101  
102  
103 # Read a standalone JSON configuration and accept either the complete
104 # metadata extension or its publish section.
105 #
106 5 my ($class, $config_fn)=@_;
107 5 ▶ open(my $config_fh, '<', $config_fn) ||
Branch: 1 branch
BranchTrueFalseTotal
open my $config_fh, "<", $config_fn or die "unable to read publication configuration ${config_fn}: $!\n" 5 0 5
108 die "unable to read publication configuration $config_fn: $!\n";
109 5 local $/=undef;
110 5 my $json=<$config_fh>;
111 5 ▶ close($config_fh) ||
Branch: 1 branch
BranchTrueFalseTotal
close $config_fh or die "unable to close publication configuration ${config_fn}: $!\n" 5 0 5
112 die "unable to close publication configuration $config_fn: $!\n";
113 5 my $config_hr=decode_json($json);
114 5 ▶ die "publication configuration in $config_fn must be an object\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config_hr eq "HASH" 0 5 5
115 unless ref($config_hr) eq 'HASH';
116  
117 5 ▶ if (ref($config_hr->{'x_documentation'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $config_hr->{"x_documentation"} eq "HASH") 3 2 5
118 3 $config_hr=$config_hr->{'x_documentation'};
119 }
120 5 ▶ if (ref($config_hr->{'publish'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $config_hr->{"publish"} eq "HASH") 5 0 5
121 5 $config_hr=$config_hr->{'publish'};
122 }
123 5 return $class->new($config_hr);
124  
125 }
126  
127  
128 140 ▶sub option {
Subroutine option: called CC=2 SCAR=6.9
Pod undocumented
129  
130 140 my ($self, $name, $default)=@_;
131 140 ▶ return $self->{$name} if exists($self->{$name});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$name} 32 108 140
132 108 return $default;
133  
134 }
135  
136  
137 20 ▶sub configuration_files {
Subroutine configuration_files: called CC=7 SCAR=19.5
Pod undocumented
138  
139 20 my ($self)=@_;
140 20 my $config_fn=$self->option('config', undef);
141 20 my $extend_fn=$self->option('config_extend', undef);
142 20 ▶ my $has_config=defined($config_fn) && length($config_fn);
Condition66%2/3
defined $config_fn && length $config_fn
!ll&&!rl&&r
1505
MC/DC50%1/2
defined $config_fn && length $config_fn
defined $config_fn length $config_fn
Truth table66%2/3
A && B
A= defined $config_fnB= length $config_fn
ABresult
0X0
100
111
143 20 ▶ my $has_extend=defined($extend_fn) && length($extend_fn);
Condition66%2/3
defined $extend_fn && length $extend_fn
!ll&&!rl&&r
1307
MC/DC50%1/2
defined $extend_fn && length $extend_fn
defined $extend_fn length $extend_fn
Truth table66%2/3
A && B
A= defined $extend_fnB= length $extend_fn
ABresult
0X0
100
111
144 20 ▶ die "config and config_extend cannot be combined\n"
Branch: 1 branch
BranchTrueFalseTotal
if $has_config and $has_extend 1 19 20
Condition100%3/3
$has_config and $has_extend
!ll&&!rl&&r
1541
MC/DC100%2/2
$has_config and $has_extend
$has_config $has_extend
Truth table100%3/3
A and B
A= $has_configB= $has_extend
ABresult
0X0
100
111
145 if $has_config && $has_extend;
146 19 ▶ return ($has_config ? $config_fn : undef,
Branch: 2 branches
BranchTrueFalseTotal
$has_config ? : 4 15 19
$has_extend ? : 6 13 19
147 $has_extend ? $extend_fn : undef);
148  
149 }
150  
151  
152 3 ▶sub configuration_context {
Subroutine configuration_context: called CC=3 SCAR=11.1
Pod undocumented
153  
154 3 my ($self, $pages_ar, $navigation_ar)=@_;
155 3 ▶ $pages_ar=[] unless defined($pages_ar);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pages_ar 0 3 3
156 3 ▶ $navigation_ar=[] unless defined($navigation_ar);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $navigation_ar 0 3 3
157 return {
158 name => $self->option('name', 'Documentation'),
159 base => $self->site_base('/'),
160 output => $self->option('output', $MARKDOWN_PUBLISH_OUTPUT_DN),
161 3 pages => [@{$pages_ar}],
162 3 navigation => [map {{%{$_}}} @{$navigation_ar}]
163 };
164  
165 }
166  
167  
168 13 ▶sub site_base {
Subroutine site_base: called CC=10 SCAR=24.9
Pod undocumented
169  
170 13 my ($self, $default)=@_;
171 13 ▶ my $base=exists($self->{'base'}) ? $self->{'base'} : $default;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'base'} ? : 11 2 13
172 13 ▶ return undef unless defined($base);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base 0 13 13
173 13 ▶ die "publication base must start and end with / and contain no empty or dot segments\n"
Branch: 1 branch
BranchTrueFalseTotal
if ref $base or not length $base or not $base =~ m[\A/] or not $base =~ m[/\z] or $base =~ m[//] or $base =~ m[(?:\A|/)\.\.?/] or $base =~ /[\s?#]/ 1 12 13
Condition61%11/18
ref $base or not length $base or not $base =~ m[\A/] or not $base =~ m[/\z] or $base =~ m[//] or $base =~ m[(?:\A|/)\.\.?/] or $base =~ /[\s?#]/
l!l&&r!l&&!r
1012
ref $base or not length $base or not $base =~ m[\A/] or not $base =~ m[/\z] or $base =~ m[//] or $base =~ m[(?:\A|/)\.\.?/]
l!l&&r!l&&!r
1012
ref $base or not length $base or not $base =~ m[\A/] or not $base =~ m[/\z] or $base =~ m[//]
l!l&&r!l&&!r
1012
ref $base or not length $base or not $base =~ m[\A/] or not $base =~ m[/\z]
l!l&&r!l&&!r
1012
ref $base or not length $base or not $base =~ m[\A/]
l!l&&r!l&&!r
0112
ref $base or not length $base
l!l&&r!l&&!r
0013
MC/DC14%1/7
ref $base or not length $base or not $base =~ m[\A/] or not $base =~ m[/\z] or $base =~ m[//] or $base =~ m[(?:\A|/)\.\.?/] or $base =~ /[\s?#]/
ref $base not length $base not $base =~ m[\A/] not $base =~ m[/\z] $base =~ m[//] $base =~ m[(?:\A|/)\.\.?/] $base =~ /[\s?#]/
Truth table25%2/8
A or not(B) or not(C) or not(D) or E or F or G
A= ref $baseB= not length $baseC= not $base =~ m[\A/]D= not $base =~ m[/\z]E= $base =~ m[//]F= $base =~ m[(?:\A|/)\.\.?/]G= $base =~ /[\s?#]/
ABCDEFGresult
1XXXXXX1
01XXXXX1
001XXXX1
0001XXX1
00001XX1
000001X1
00000011
00000000
174 if ref($base) || !length($base) || $base!~m{\A/} || $base!~m{/\z} ||
175 $base=~m{//} || $base=~m{(?:\A|/)\.\.?/} || $base=~m{[\s?#]};
176 12 return $base;
177  
178 }
179  
180  
181 3 ▶sub github_repository_name {
Subroutine github_repository_name: called CC=7 SCAR=20.0
Pod undocumented
182  
183 3 my ($self)=@_;
184 3 my $remote;
185 3 eval {$remote=$self->command('git', 'config', '--get', 'remote.origin.url')};
186 3 ▶ if (defined($remote) && length($remote)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $remote and length $remote) 2 1 3
Condition66%2/3
defined $remote and length $remote
!ll&&!rl&&r
102
MC/DC50%1/2
defined $remote and length $remote
defined $remote length $remote
Truth table66%2/3
A and B
A= defined $remoteB= length $remote
ABresult
0X0
100
111
187 2 $remote=~s/[\r\n]+\z//;
188 2 $remote=~s{[/\\]+\z}{};
189 2 $remote=~s{\.git\z}{}i;
190 2 ▶ if ($remote=~m{([^/\\:]+)\z}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remote =~ m[([^/\\:]+)\z]) 2 0 2
191 2 my $repository=$1;
192 2 ▶ return $repository if $repository=~/\A[A-Za-z0-9._-]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $repository =~ /\A[A-Za-z0-9._-]+\z/ 2 0 2
193 }
194 }
195 1 my $root_dn=$self->command('git', 'rev-parse', '--show-toplevel');
196 1 $root_dn=~s/[\r\n]+\z//;
197 1 my $repository=basename($root_dn);
198 1 ▶ die "unable to determine GitHub repository name\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repository and $repository =~ /\A[A-Za-z0-9._-]+\z/ 0 1 1
Condition33%1/3
defined $repository and $repository =~ /\A[A-Za-z0-9._-]+\z/
!ll&&!rl&&r
001
MC/DC0%0/2
defined $repository and $repository =~ /\A[A-Za-z0-9._-]+\z/
defined $repository $repository =~ /\A[A-Za-z0-9._-]+\z/
Truth table33%1/3
A and B
A= defined $repositoryB= $repository =~ /\A[A-Za-z0-9._-]+\z/
ABresult
0X0
100
111
199 unless defined($repository) && $repository=~/\A[A-Za-z0-9._-]+\z/;
200 1 return $repository;
201  
202 }
203  
204  
205 3 ▶sub github_base {
Subroutine github_base: called CC=2 SCAR=6.9
Pod undocumented
206  
207 3 my ($self)=@_;
208 3 my $repository=$self->github_repository_name();
209 3 ▶ return '/' if $repository=~/\.github\.io\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $repository =~ /\.github\.io\z/i 1 2 3
210 2 return "/$repository/";
211  
212 }
213  
214  
215 4 ▶sub github_site_base {
Subroutine github_site_base: called CC=2 SCAR=6.9
Pod undocumented
216  
217 4 my ($self)=@_;
218 4 ▶ return $self->site_base('/') if exists($self->{'base'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"base"} 1 3 4
219 3 return $self->github_base();
220  
221 }
222  
223  
224 6 ▶sub validate_action {
Subroutine validate_action: called CC=3 SCAR=11.0
Pod undocumented
225  
226 6 my ($self, $action)=@_;
227 die "unknown publication action: $action\n"
228 6 ▶ unless defined($action) && $ACTION{$action};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $action and $ACTION{$action} 1 5 6
Condition66%2/3
defined $action and $ACTION{$action}
!ll&&!rl&&r
015
MC/DC50%1/2
defined $action and $ACTION{$action}
defined $action $ACTION{$action}
Truth table66%2/3
A and B
A= defined $actionB= $ACTION{$action}
ABresult
0X0
100
111
229 5 return 1;
230  
231 }
232  
233  
234 6 ▶sub run {
Subroutine run: called CC=5 SCAR=16.1
Pod documented
235  
236 6 my ($self, $action)=@_;
237 6 $self->validate_action($action);
238 5 ▶ return $self->build() if $action eq 'build';
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "build" 1 4 5
239 4 ▶ return $self->serve() if $action eq 'serve';
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "serve" 1 3 4
240 3 ▶ return $self->publish_gh() if $action eq 'gh';
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "gh" 1 2 3
241 2 ▶ return $self->publish_gh_push() if $action eq 'gh-push';
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "gh-push" 1 1 2
242 1 return $self->publish_cloudflare();
243  
244 }
245  
246  
247 0 ▶sub command {
Subroutine command: not called CC=2 SCAR=17.9
Pod undocumented
248  
249 0 my ($self, @command)=@_;
250 0 my ($output, $error);
251 0 run3(\@command, \undef, \$output, \$error);
252 0 ▶ die "command failed (@command): $error\n" if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 0 0 0
253 0 return $output;
254  
255 }
256  
257  
258 0 ▶sub system_command {
Subroutine system_command: not called CC=2 SCAR=17.9
Pod undocumented
259  
260 0 my ($self, @command)=@_;
261 0 system(@command);
262 0 ▶ die "command failed (@command)\n" if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 0 0 0
263 0 return 1;
264  
265 }
266  
267  
268 0 ▶sub system_in_dir {
Subroutine system_in_dir: not called CC=4 SCAR=30.0
Pod undocumented
269  
270 0 my ($self, $dir, @command)=@_;
271 0 my $cwd=getcwd();
272 0 ▶ chdir($dir) || die "unable to chdir $dir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $dir or die "unable to chdir ${dir}: $!\n" 0 0 0
273 0 my $ok=eval {$self->system_command(@command); 1};
274 0 my $error=$@;
275 0 ▶ chdir($cwd) || die "unable to chdir $cwd: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $cwd or die "unable to chdir ${cwd}: $!\n" 0 0 0
276 0 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
277 0 return 1;
278  
279 }
280  
281  
282 203 ▶sub write_file {
Subroutine write_file: called CC=5 SCAR=17.3
Pod undocumented
283  
284 203 my ($self, $fn, $text)=@_;
285 203 my (undef, $parent_dn)=File::Spec->splitpath($fn);
286 203 ▶ make_path($parent_dn) if length($parent_dn) && !-d $parent_dn;
Branch: 1 branch
BranchTrueFalseTotal
if length $parent_dn and not -d $parent_dn 0 203 203
Condition33%1/3
length $parent_dn and not -d $parent_dn
!ll&&!rl&&r
02030
MC/DC0%0/2
length $parent_dn and not -d $parent_dn
length $parent_dn not -d $parent_dn
Truth table33%1/3
A and not(B)
A= length $parent_dnB= not -d $parent_dn
ABresult
0X0
100
111
287 203 ▶ open(my $output_fh, '>', $fn) || die "unable to write $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $output_fh, ">", $fn or die "unable to write ${fn}: $!\n" 203 0 203
288 203 print {$output_fh} $text;
289 203 ▶ close($output_fh) || die "unable to close $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $output_fh or die "unable to close ${fn}: $!\n" 203 0 203
290 203 return 1;
291  
292 }
293  
294  
295 53 ▶sub copy_tree {
Subroutine copy_tree: called CC=2 SCAR=7.0
Pod undocumented
296  
297 53 my ($self, $source_dn, $target_dn)=@_;
298 53 ▶ return unless -d $source_dn;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $source_dn 46 7 53
299 File::Find::find({
300 no_chdir => 1,
301 102 ▶ wanted => sub {
Subroutine __ANON__: called CC=5 SCAR=16.5
302 102 my $fn=$File::Find::name;
303 102 ▶ return if -l $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -l $fn 0 102 102
304 102 my $relative=File::Spec->abs2rel($fn, $source_dn);
305 102 my $output_fn=File::Spec->catfile($target_dn, $relative);
306 102 ▶ if (-d $fn) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $fn) { } 42 60 102
elsif (-f $fn) { } 60 0 60
307 42 make_path($output_fn);
308 }
309 elsif (-f $fn) {
310 60 ▶ copy($fn, $output_fn) || die "unable to copy $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
copy($fn, $output_fn) or die "unable to copy ${fn}: $!\n" 60 0 60
311 }
312 }
313 7 }, $source_dn);
314 7 return 1;
315  
316 }
317  
318  
319 22 ▶sub source_directories {
Subroutine source_directories: called CC=5 SCAR=19.7
Pod documented
320  
321  
322 # An explicit source list is exact. Without one, doc is the publication
323 # boundary whenever it exists; module sidecars are only a fallback.
324 #
325 22 my ($self)=@_;
326 22 ▶ if (exists($self->{'sources'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"sources"}) 16 6 22
327 die "publication sources must be an array reference\n"
328 16 ▶ unless ref($self->{'sources'}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"sources"} eq "ARRAY" 0 16 16
329 16 return [@{$self->{'sources'}}];
330 }
331 6 ▶ return ['doc'] if -d 'doc';
Branch: 1 branch
BranchTrueFalseTotal
if -d "doc" 6 0 6
332 0 my @source_dn=grep {-d $_} qw(lib bin);
333 0 ▶ warn "doc directory not found; publishing module and executable sidecars\n"
Branch: 1 branch
BranchTrueFalseTotal
if @source_dn 0 0 0
334 if @source_dn;
335 0 return \@source_dn;
336  
337 }
338  
339  
340 77 ▶sub target_filename {
Subroutine target_filename: called CC=3 SCAR=11.0
Pod undocumented
341  
342 77 my ($self, $source_dn, $fn)=@_;
343 77 my $relative=File::Spec->abs2rel($fn, $source_dn);
344 77 ▶ if ($source_dn eq 'lib') {
Branch: 1 branch
BranchTrueFalseTotal
if ($source_dn eq "lib") 1 76 77
345 1 $relative=~s/\.pm\.md$/.md/;
346 1 $relative=~s{[/\\]}{_}g;
347 1 return File::Spec->catfile('modules', $relative);
348 }
349 76 ▶ if ($source_dn eq 'bin') {
Branch: 1 branch
BranchTrueFalseTotal
if ($source_dn eq "bin") 1 75 76
350 1 return File::Spec->catfile('utilities', $relative);
351 }
352 75 return $relative;
353  
354 }
355  
356  
357 42 ▶sub copy_markdown_tree {
Subroutine copy_markdown_tree: called CC=2 SCAR=7.0
Pod undocumented
358  
359 42 my ($self, $source_dn, $docs_dn)=@_;
360 42 ▶ return unless -d $source_dn;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $source_dn 4 38 42
361 File::Find::find({
362 no_chdir => 1,
363 76 ▶ preprocess => sub {sort @_},
Subroutine __ANON__: called CC=1 SCAR=0.0
364 114 ▶ wanted => sub {
Subroutine __ANON__: called CC=6 SCAR=18.4
365 114 my $fn=$File::Find::name;
366 114 ▶ return if -l $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -l $fn 0 114 114
367 114 ▶ return unless -f $fn && $fn=~/\.md$/;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $fn and $fn =~ /\.md$/ 76 38 114
Condition66%2/3
-f $fn and $fn =~ /\.md$/
!ll&&!rl&&r
76038
MC/DC50%1/2
-f $fn and $fn =~ /\.md$/
-f $fn $fn =~ /\.md$/
Truth table66%2/3
A and B
A= -f $fnB= $fn =~ /\.md$/
ABresult
0X0
100
111
368 38 my $target_fn=File::Spec->catfile($source_dn,
369 File::Spec->abs2rel($fn, $source_dn));
370 38 my $output_fn=File::Spec->catfile($docs_dn, $target_fn);
371 38 ▶ die "publication page already exists: $target_fn\n" if -e $output_fn;
Branch: 1 branch
BranchTrueFalseTotal
if -e $output_fn 0 38 38
372 38 my (undef, $parent_dn)=File::Spec->splitpath($output_fn);
373 38 make_path($parent_dn);
374 38 ▶ copy($fn, $output_fn) || die "unable to copy $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
copy($fn, $output_fn) or die "unable to copy ${fn}: $!\n" 38 0 38
375 }
376 38 }, $source_dn);
377 38 return 1;
378  
379 }
380  
381  
382 19 ▶sub promote_home {
Subroutine promote_home: called CC=5 SCAR=16.2
Pod undocumented
383  
384 # Keep the first page's original path available for authored links.
385 # Only a top-level page can be copied to index without rebasing its links.
386 #
387 19 my ($self, $docs_dn, $pages_ar)=@_;
388 19 ▶ return unless @{$pages_ar};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$pages_ar;} 0 19 19
389 19 my $has_index=grep {$_ eq 'index.md'} @{$pages_ar};
390 19 ▶ return if $has_index || $pages_ar->[0]=~m{[/\\]};
Branch: 1 branch
BranchTrueFalseTotal
if $has_index or $pages_ar->[0] =~ m([/\\]) 1 18 19
Condition66%2/3
$has_index or $pages_ar->[0] =~ m([/\\])
l!l&&r!l&&!r
1018
MC/DC50%1/2
$has_index or $pages_ar->[0] =~ m([/\\])
$has_index $pages_ar->[0] =~ m([/\\])
Truth table66%2/3
A or B
A= $has_indexB= $pages_ar->[0] =~ m([/\\])
ABresult
1X1
011
000
391 18 my $first_fn=File::Spec->catfile($docs_dn, $pages_ar->[0]);
392 18 my $index_fn=File::Spec->catfile($docs_dn, 'index.md');
393 18 ▶ copy($first_fn, $index_fn) || die "unable to copy $first_fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
copy($first_fn, $index_fn) or die "unable to copy ${first_fn}: $!\n" 18 0 18
394 18 $pages_ar->[0]='index.md';
395 18 return 1;
396  
397 }
398  
399  
400 22 ▶sub prepare_docs {
Subroutine prepare_docs: called CC=8 SCAR=20.8
Pod documented
401  
402  
403 # Assemble the configured source roots and mirror lib/bin Markdown when
404 # doc is selected. Nested documents remain linkable but outside generated
405 # navigation.
406 #
407 22 my ($self)=@_;
408 22 my $temporary_dn=abs_path(tempdir(CLEANUP => 1));
409 22 my $docs_dn=File::Spec->catdir($temporary_dn, 'docs');
410 22 make_path($docs_dn);
411 22 my @pages;
412 22 my $source_dn_ar=$self->source_directories();
413  
414 22 foreach my $source_dn (@{$source_dn_ar}) {
415 24 ▶ die "publication source directory not found: $source_dn\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $source_dn 0 24 24
416 unless -d $source_dn;
417 File::Find::find({
418 no_chdir => 1,
419 46 ▶ preprocess => sub {sort @_},
Subroutine __ANON__: called CC=1 SCAR=0.0
420 144 ▶ wanted => sub {
Subroutine __ANON__: called CC=16 SCAR=27.8
421 144 my $fn=$File::Find::name;
422 144 ▶ if (-d $fn && $fn=~m{[/\\](?:build|example|examples|mkdocs|node_modules|site|t)$}) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $fn and $fn =~ m([/\\](?:build|example|examples|mkdocs|node_modules|site|t)$)) 21 123 144
Condition100%3/3
-d $fn and $fn =~ m([/\\](?:build|example|examples|mkdocs|node_modules|site|t)$)
!ll&&!rl&&r
774621
MC/DC100%2/2
-d $fn and $fn =~ m([/\\](?:build|example|examples|mkdocs|node_modules|site|t)$)
-d $fn $fn =~ m([/\\](?:build|example|examples|mkdocs|node_modules|site|t)$)
Truth table100%3/3
A and B
A= -d $fnB= $fn =~ m([/\\](?:build|example|examples|mkdocs|node_modules|site|t)$)
ABresult
0X0
100
111
423 21 $File::Find::prune=1;
424 21 return;
425 }
426 123 ▶ return unless -f $fn && !-l $fn && $fn=~/\.md$/;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $fn and not -l $fn and $fn =~ /\.md$/ 46 77 123
Condition66%4/6
-f $fn and not -l $fn and $fn =~ /\.md$/
!ll&&!rl&&r
46077
-f $fn and not -l $fn
!ll&&!rl&&r
46077
MC/DC33%1/3
-f $fn and not -l $fn and $fn =~ /\.md$/
-f $fn not -l $fn $fn =~ /\.md$/
Truth table50%2/4
A and not(B) and C
A= -f $fnB= not -l $fnC= $fn =~ /\.md$/
ABCresult
0XX0
10X0
1100
1111
427 77 my $target_fn=$self->target_filename($source_dn, $fn);
428 77 my $output_fn=File::Spec->catfile($docs_dn, $target_fn);
429 77 my (undef, $parent_dn)=File::Spec->splitpath($output_fn);
430 77 make_path($parent_dn);
431 77 ▶ my $navigation_page=$source_dn eq 'lib' || $source_dn eq 'bin' ||
Condition100%6/6
$source_dn eq 'lib' || $source_dn eq 'bin' || !($target_fn =~ m([/\\]))
l!l&&r!l&&!r
25520
$source_dn eq "lib" or $source_dn eq "bin"
l!l&&r!l&&!r
1175
MC/DC100%3/3
$source_dn eq 'lib' || $source_dn eq 'bin' || !($target_fn =~ m([/\\]))
$source_dn eq "lib" $source_dn eq "bin" !($target_fn =~ m([/\\]))
Truth table100%4/4
A or B || not(C)
A= $source_dn eq "lib"B= $source_dn eq "bin"C= !($target_fn =~ m([/\\]))
ABCresult
1XX1
01X1
0011
0000
432 $target_fn!~m{[/\\]};
433  
434 77 ▶ if ($source_dn eq 'doc' && $navigation_page) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source_dn eq "doc" and $navigation_page) 55 22 77
Condition100%3/3
$source_dn eq "doc" and $navigation_page
!ll&&!rl&&r
22055
MC/DC100%2/2
$source_dn eq "doc" and $navigation_page
$source_dn eq "doc" $navigation_page
Truth table100%3/3
A and B
A= $source_dn eq "doc"B= $navigation_page
ABresult
0X0
100
111
435 55 ▶ open(my $input_fh, '<', $fn) || die "unable to read $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $input_fh, "<", $fn or die "unable to read ${fn}: $!\n" 55 0 55
436 55 local $/=undef;
437 55 my $markdown=<$input_fh>;
438 55 ▶ close($input_fh) || die "unable to close $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $input_fh or die "unable to close ${fn}: $!\n" 55 0 55
439 55 my $split_hr=$self->split($target_fn, $markdown);
440 55 ▶ if (keys(%{$split_hr}) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$split_hr;} > 1) 17 38 55
441 17 foreach my $page (@{$self->{'page_order'}}) {
442 34 my $page_fn=File::Spec->catfile($docs_dn, $page);
443 34 $self->write_file($page_fn, $split_hr->{$page});
444 34 push(@pages, $page);
445 }
446 17 return;
447 }
448 }
449 60 ▶ copy($fn, $output_fn) || die "unable to copy $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
copy($fn, $output_fn) or die "unable to copy ${fn}: $!\n" 60 0 60
450 60 ▶ push(@pages, $target_fn) if $navigation_page;
Branch: 1 branch
BranchTrueFalseTotal
if $navigation_page 40 20 60
451 }
452 24 }, $source_dn);
453 }
454  
455 22 ▶ die "no Markdown documents discovered in publication sources\n" unless @pages;
Branch: 1 branch
BranchTrueFalseTotal
unless @pages 1 21 22
456 21 ▶ if (grep {$_ eq 'doc'} @{$source_dn_ar}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "doc";} @{$source_dn_ar;}) 21 0 21
457 21 $self->copy_markdown_tree('lib', $docs_dn);
458 21 $self->copy_markdown_tree('bin', $docs_dn);
459 }
460 # Keep a home page without placing its generated link list in navigation.
461 #
462 21 ▶ unless (-f File::Spec->catfile($docs_dn, 'index.md')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "File::Spec"->catfile($docs_dn, "index.md")) 20 1 21
463 20 my $index="# Documentation\n\n";
464 20 $index.="- [$_]($_)\n" foreach @pages;
465 20 $self->write_file(File::Spec->catfile($docs_dn, 'index.md'), $index);
466 }
467  
468 21 foreach my $source_dn (@{$source_dn_ar}) {
469 23 $self->copy_tree(File::Spec->catdir($source_dn, 'images'),
470 File::Spec->catdir($docs_dn, 'images'));
471 23 $self->copy_tree(File::Spec->catdir($source_dn, 'assets'),
472 File::Spec->catdir($docs_dn, 'assets'));
473 }
474 21 return ($temporary_dn, $docs_dn, \@pages);
475  
476 }
477  
478  
479 57 ▶sub split {
Subroutine split: called CC=25 SCAR=32.3
Pod documented
480  
481 57 my ($self, $fn, $markdown)=@_;
482 57 (my $stem=$fn)=~s/\.md$//;
483 57 my (%pages, %anchor, %chapter_anchor, @order);
484 57 my ($page, $fence, $length, $preamble)=('', '', 0, '');
485 57 foreach my $line (split(/(?<=\n)/, $markdown)) {
486 523 ▶ if (!$fence && $line=~/^ {0,3}(`{3,}|~{3,})/) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $fence and $line =~ /^ {0,3}(`{3,}|~{3,})/) { } 27 496 523
elsif ($fence and $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/) { } 27 469 496
elsif (not $fence and $line =~ /^#\s+(.+?)\s*$/) { } 76 447 523
Condition100%3/3
not $fence and $line =~ /^ {0,3}(`{3,}|~{3,})/
!ll&&!rl&&r
8141527
MC/DC100%2/2
not $fence and $line =~ /^ {0,3}(`{3,}|~{3,})/
not $fence $line =~ /^ {0,3}(`{3,}|~{3,})/
Truth table100%3/3
not(A) and B
A= not $fenceB= $line =~ /^ {0,3}(`{3,}|~{3,})/
ABresult
0X0
100
111
487 27 $fence=substr($1, 0, 1);
488 27 $length=length($1);
489 }
490 ▶ elsif ($fence && $line=~/^ {0,3}\Q$fence\E{$length,}\s*$/) {
Condition100%3/3
$fence and $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
!ll&&!rl&&r
4155427
MC/DC100%2/2
$fence and $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
$fence $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
Truth table100%3/3
A and B
A= $fenceB= $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
ABresult
0X0
100
111
491 27 $fence='';
492 }
493 ▶ elsif (!$fence && $line=~/^#\s+(.+?)\s*$/) {
Condition100%3/3
not $fence and $line =~ /^#\s+(.+?)\s*$/
!ll&&!rl&&r
5433976
MC/DC100%2/2
not $fence and $line =~ /^#\s+(.+?)\s*$/
not $fence $line =~ /^#\s+(.+?)\s*$/
Truth table100%3/3
not(A) and B
A= not $fenceB= $line =~ /^#\s+(.+?)\s*$/
ABresult
0X0
100
111
494 76 my $title=$1;
495 76 my ($id)=$title=~/\{#([^}]+)\}/;
496 76 ▶ unless ($id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 15 61 76
497 15 $id=lc($title);
498 15 $id=~s/[^a-z0-9]+/-/g;
499 15 $id=~s/^-|-$//g;
500 }
501 76 ▶ die "empty or unsafe chapter ID in $fn\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $id and $id =~ /^[\w.-]+$/ 0 76 76
Condition33%1/3
$id and $id =~ /^[\w.-]+$/
!ll&&!rl&&r
0076
MC/DC0%0/2
$id and $id =~ /^[\w.-]+$/
$id $id =~ /^[\w.-]+$/
Truth table33%1/3
A and B
A= $idB= $id =~ /^[\w.-]+$/
ABresult
0X0
100
111
502 unless $id && $id=~/^[\w.-]+$/;
503 76 $page="$stem--$id.md";
504 76 ▶ die "duplicate chapter ID $id in $fn\n" if exists($pages{$page});
Branch: 1 branch
BranchTrueFalseTotal
if exists $pages{$page} 1 75 76
505 75 $pages{$page}=$preamble;
506 75 $preamble='';
507 75 $chapter_anchor{$id}=1;
508 75 push(@order, $page);
509 }
510 522 ▶ $anchor{$1}=$page if !$fence && $line=~/\{#([^}]+)\}/ && $page;
Branch: 1 branch
BranchTrueFalseTotal
if not $fence and $line =~ /\{#([^}]+)\}/ and $page 60 462 522
Condition83%5/6
not $fence and $line =~ /\{#([^}]+)\}/ and $page
!ll&&!rl&&r
462060
not $fence and $line =~ /\{#([^}]+)\}/
!ll&&!rl&&r
8138160
MC/DC66%2/3
not $fence and $line =~ /\{#([^}]+)\}/ and $page
not $fence $line =~ /\{#([^}]+)\}/ $page
Truth table75%3/4
not(A) and B and C
A= not $fenceB= $line =~ /\{#([^}]+)\}/C= $page
ABCresult
0XX0
10X0
1100
1111
511 522 ▶ if ($page) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page) { } 522 0 522
512 522 $pages{$page}.=$line;
513 }
514 else {
515 0 $preamble.=$line;
516 }
517 }
518  
519 56 foreach my $current_page (@order) {
520 74 my $text='';
521 74 my ($current_fence, $current_length)=('', 0);
522 74 foreach my $line (split(/(?<=\n)/, $pages{$current_page})) {
523 521 ▶ if (!$current_fence && $line=~/^ {0,3}(`{3,}|~{3,})/) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $current_fence and $line =~ /^ {0,3}(`{3,}|~{3,})/) { } 27 494 521
elsif ($current_fence and $line =~ /^ {0,3}\Q$current_fence\E{$current_length,}\s*$/) { } 27 467 494
elsif (not $current_fence) { } 413 54 467
Condition100%3/3
not $current_fence and $line =~ /^ {0,3}(`{3,}|~{3,})/
!ll&&!rl&&r
8141327
MC/DC100%2/2
not $current_fence and $line =~ /^ {0,3}(`{3,}|~{3,})/
not $current_fence $line =~ /^ {0,3}(`{3,}|~{3,})/
Truth table100%3/3
not(A) and B
A= not $current_fenceB= $line =~ /^ {0,3}(`{3,}|~{3,})/
ABresult
0X0
100
111
524 27 $current_fence=substr($1, 0, 1);
525 27 $current_length=length($1);
526 }
527 ▶ elsif ($current_fence && $line=~/^ {0,3}\Q$current_fence\E{$current_length,}\s*$/) {
Condition100%3/3
$current_fence and $line =~ /^ {0,3}\Q$current_fence\E{$current_length,}\s*$/
!ll&&!rl&&r
4135427
MC/DC100%2/2
$current_fence and $line =~ /^ {0,3}\Q$current_fence\E{$current_length,}\s*$/
$current_fence $line =~ /^ {0,3}\Q$current_fence\E{$current_length,}\s*$/
Truth table100%3/3
A and B
A= $current_fenceB= $line =~ /^ {0,3}\Q$current_fence\E{$current_length,}\s*$/
ABresult
0X0
100
111
528 27 $current_fence='';
529 }
530 elsif (!$current_fence) {
531 413 foreach my $id (keys(%anchor)) {
532 589 my (undef, undef, $target)=File::Spec->splitpath($anchor{$id});
533 589 ▶ my $link=$target.($chapter_anchor{$id} ? '' : "#$id");
Branch: 1 branch
BranchTrueFalseTotal
$chapter_anchor{$id} ? : 589 0 589
534 589 $line=~s{\]\(\#\Q$id\E\)}{]($link)}g;
535 }
536 }
537 521 $text.=$line;
538 }
539 74 $pages{$current_page}=$text;
540 }
541 56 $self->{'page_order'}=\@order;
542 56 return \%pages;
543  
544 }
545  
546  
547 111 ▶sub normalize_node_admonitions {
Subroutine normalize_node_admonitions: called CC=5 SCAR=23.4
Pod undocumented
548  
549 111 my ($self, $markdown)=@_;
550 111 my @output;
551 111 my @line=split(/(?<=\n)/, $markdown);
552 111 ▶ for (my $index=0; $index<@line; $index++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < @line) 994 111 1105
553 994 ▶ if ($line[$index]=~/^!!!\s+(\w+).*?\n?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line[$index] =~ /^!!!\s+(\w+).*?\n?$/) 0 994 994
554 0 my $kind=$self->admonition_type($1);
555 0 push(@output, ":::$kind\n");
556 0 ▶ while ($index + 1 < @line && $line[$index + 1]=~/^(?: |\s*$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index + 1 < @line and $line[$index + 1] =~ /^(?: |\s*$)/) 0 0 0
Condition0%0/3
$index + 1 < @line and $line[$index + 1] =~ /^(?: |\s*$)/
!ll&&!rl&&r
000
MC/DC0%0/2
$index + 1 < @line and $line[$index + 1] =~ /^(?: |\s*$)/
$index + 1 < @line $line[$index + 1] =~ /^(?: |\s*$)/
Truth table0%0/3
A and B
A= $index + 1 < @lineB= $line[$index + 1] =~ /^(?: |\s*$)/
ABresult
0X0
100
111
557 0 $index++;
558 0 my $admonition_line=$line[$index];
559 0 $admonition_line=~s/^ //;
560 0 push(@output, $admonition_line);
561 }
562 0 push(@output, ":::\n");
563 0 next;
564 }
565 994 push(@output, $line[$index]);
566 }
567 111 return join('', @output);
568  
569 }
570  
571  
572 0 ▶sub admonition_type {
Subroutine admonition_type: not called CC=1 SCAR=6.9
Pod undocumented
573  
574 0 my ($self, $kind)=@_;
575 0 return $kind;
576  
577 }
578  
579  
580 111 ▶sub normalize_node_definition_lists {
Subroutine normalize_node_definition_lists: called CC=12 SCAR=24.9
Pod undocumented
581  
582 111 my ($self, $markdown)=@_;
583 111 my @line=split(/(?<=\n)/, $markdown);
584 111 my @output;
585 111 my ($fence, $length)=('', 0);
586 111 ▶ for (my $index=0; $index<@line; $index++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < @line) 700 111 811
587 700 ▶ if (!$fence && $line[$index]=~/^ {0,3}(`{3,}|~{3,})/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $fence and $line[$index] =~ /^ {0,3}(`{3,}|~{3,})/) { } 26 674 700
elsif ($fence and $line[$index] =~ /^ {0,3}\Q$fence\E{$length,}\s*$/) { } 26 1244 1270
Condition100%3/3
not $fence and $line[$index] =~ /^ {0,3}(`{3,}|~{3,})/
!ll&&!rl&&r
7859626
MC/DC100%2/2
not $fence and $line[$index] =~ /^ {0,3}(`{3,}|~{3,})/
not $fence $line[$index] =~ /^ {0,3}(`{3,}|~{3,})/
Truth table100%3/3
not(A) and B
A= not $fenceB= $line[$index] =~ /^ {0,3}(`{3,}|~{3,})/
ABresult
0X0
100
111
588 26 $fence=substr($1, 0, 1);
589 26 $length=length($1);
590 }
591 ▶ elsif ($fence && $line[$index]=~/^ {0,3}\Q$fence\E{$length,}\s*$/) {
Condition100%3/3
$fence and $line[$index] =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
!ll&&!rl&&r
5965226
MC/DC100%2/2
$fence and $line[$index] =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
$fence $line[$index] =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
Truth table100%3/3
A and B
A= $fenceB= $line[$index] =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
ABresult
0X0
100
111
592 26 $fence='';
593 }
594  
595 # Pandoc definition lists are not portable to the Node renderers.
596 # Their two-space continuation indent is also the content indent for
597 # the equivalent CommonMark list item, so the remaining block can be
598 # retained verbatim.
599 #
600 700 ▶ if (!$fence && $index + 2 < @line && $line[$index]!~/^\s*$/ &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $fence and $index + 2 < @line and not $line[$index] =~ /^\s*$/ and $line[$index + 1] =~ /^\s*$/ and $line[$index + 2] =~ /^:\s+(.*)$/) 13 687 700
Condition91%11/12
not $fence and $index + 2 < @line and not $line[$index] =~ /^\s*$/ and $line[$index + 1] =~ /^\s*$/ and $line[$index + 2] =~ /^:\s+(.*)$/
!ll&&!rl&&r
45423313
not $fence and $index + 2 < @line and not $line[$index] =~ /^\s*$/ and $line[$index + 1] =~ /^\s*$/
!ll&&!rl&&r
4540246
not $fence and $index + 2 < @line and not $line[$index] =~ /^\s*$/
!ll&&!rl&&r
287167246
not $fence and $index + 2 < @line
!ll&&!rl&&r
78209413
MC/DC80%4/5
not $fence and $index + 2 < @line and not $line[$index] =~ /^\s*$/ and $line[$index + 1] =~ /^\s*$/ and $line[$index + 2] =~ /^:\s+(.*)$/
not $fence $index + 2 < @line not $line[$index] =~ /^\s*$/ $line[$index + 1] =~ /^\s*$/ $line[$index + 2] =~ /^:\s+(.*)$/
Truth table83%5/6
not(A) and B and not(C) and D and E
A= not $fenceB= $index + 2 < @lineC= not $line[$index] =~ /^\s*$/D= $line[$index + 1] =~ /^\s*$/E= $line[$index + 2] =~ /^:\s+(.*)$/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
601 $line[$index + 1]=~/^\s*$/ && $line[$index + 2]=~/^:\s+(.*)$/) {
602 13 my $term=$line[$index];
603 13 my $description=$1;
604 13 ▶ my $newline=$line[$index + 2]=~/\n\z/ ? "\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
$line[$index + 2] =~ /\n\z/ ? : 13 0 13
605 13 $term=~s/\r?\n\z//;
606 13 $description=~s/\r?\n\z//;
607 13 push(@output, "- **$term**\n\n $description$newline");
608 13 $index+=2;
609 13 next;
610 }
611 687 push(@output, $line[$index]);
612 }
613 111 return join('', @output);
614  
615 }
616  
617  
618 111 ▶sub normalize_node_attributes {
Subroutine normalize_node_attributes: called CC=13 SCAR=25.8
Pod undocumented
619  
620 111 my ($self, $markdown)=@_;
621 111 my @output;
622 111 my ($fence, $length)=('', 0);
623 111 foreach my $line (split(/(?<=\n)/, $markdown)) {
624 966 ▶ if ($fence) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fence) 78 888 966
625 78 ▶ if ($line=~/^ {0,3}\Q$fence\E{$length,}\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/) 26 52 78
626 26 $fence='';
627 }
628 78 push(@output, $line);
629 78 next;
630 }
631  
632 # Retain an authored code-block ID as an adjacent HTML anchor and
633 # pass its first class as the conventional fenced-code language.
634 #
635 888 ▶ if ($line=~/^( {0,3})(`{3,}|~{3,})[ \t]*\{([^}\r\n]+)\}[ \t]*(\r?\n)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^( {0,3})(`{3,}|~{3,})[ \t]*\{([^}\r\n]+)\}[ \t]*(\r?\n)?$/) 13 875 888
636 13 ▶ my ($indent, $delimiter, $attributes, $newline)=($1, $2, $3, $4 || '');
Condition50%1/2
$4 || ''
l!l
130
MC/DC0%0/1
$4 || ''
$4
Truth table50%1/2
A
A= $4
Aresult
11
00
637 13 my ($id)=$attributes=~/(?:^|\s)#([\w.-]+)/;
638 13 my ($language)=$attributes=~/(?:^|\s)\.([\w+-]+)/;
639 13 ▶ push(@output, "$indent<a id=\"$id\"></a>$newline") if defined($id);
Branch: 1 branch
BranchTrueFalseTotal
if defined $id 13 0 13
640 13 ▶ push(@output, $indent.$delimiter.(defined($language) ? $language : '').$newline);
Branch: 1 branch
BranchTrueFalseTotal
defined $language ? : 13 0 13
641 13 $fence=substr($delimiter, 0, 1);
642 13 $length=length($delimiter);
643 13 next;
644 }
645 875 ▶ if ($line=~/^ {0,3}(`{3,}|~{3,})/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^ {0,3}(`{3,}|~{3,})/) 13 862 875
646 13 $fence=substr($1, 0, 1);
647 13 $length=length($1);
648 13 push(@output, $line);
649 13 next;
650 }
651  
652 # Docusaurus and Starlight do not accept Pandoc heading attributes.
653 # A raw anchor preserves the stable identifiers used by split links.
654 #
655 862 ▶ if ($self->heading_anchor_required() &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->heading_anchor_required and $line =~ /^( {0,3})(#{1,6}[^\r\n]*?)\s+\{#([\w.-]+)(?:\s+[^}]*)?\}[ \t]*(\r?\n)?$/) 15 847 862
Condition100%3/3
$self->heading_anchor_required and $line =~ /^( {0,3})(#{1,6}[^\r\n]*?)\s+\{#([\w.-]+)(?:\s+[^}]*)?\}[ \t]*(\r?\n)?$/
!ll&&!rl&&r
28855915
MC/DC100%2/2
$self->heading_anchor_required and $line =~ /^( {0,3})(#{1,6}[^\r\n]*?)\s+\{#([\w.-]+)(?:\s+[^}]*)?\}[ \t]*(\r?\n)?$/
$self->heading_anchor_required $line =~ /^( {0,3})(#{1,6}[^\r\n]*?)\s+\{#([\w.-]+)(?:\s+[^}]*)?\}[ \t]*(\r?\n)?$/
Truth table100%3/3
A and B
A= $self->heading_anchor_requiredB= $line =~ /^( {0,3})(#{1,6}[^\r\n]*?)\s+\{#([\w.-]+)(?:\s+[^}]*)?\}[ \t]*(\r?\n)?$/
ABresult
0X0
100
111
656 $line=~/^( {0,3})(#{1,6}[^\r\n]*?)\s+\{#([\w.-]+)(?:\s+[^}]*)?\}[ \t]*(\r?\n)?$/) {
657 15 ▶ push(@output, "$1<a id=\"$3\"></a>".($4 || '').$1.$2.($4 || ''));
Condition50%2/4
$4 || ''
l!l
150
$4 || ''
l!l
150
MC/DC0%0/1
$4 || ''
$4
MC/DC0%0/1
$4 || ''
$4
Truth table50%1/2
A
A= $4
Aresult
11
00
Truth table50%1/2
A
A= $4
Aresult
11
00
658 15 next;
659 }
660  
661 # Attribute blocks on inline links and images otherwise become
662 # visible text in one or more of the Node renderers.
663 #
664 847 $line=~s{((?:!)?\[[^\]]*\]\([^\)\r\n]+\))\{[^\}\r\n]+\}}{$1}g;
665 847 push(@output, $line);
666 }
667 111 return join('', @output);
668  
669 }
670  
671  
672 288 ▶sub heading_anchor_required {
Subroutine heading_anchor_required: called CC=1 SCAR=0.0
Pod undocumented
673  
674 288 return 0;
675  
676 }
677  
678  
679  
680  
681 123 ▶sub markdown_title {
Subroutine markdown_title: called CC=19 SCAR=40.4
Pod undocumented
682  
683 123 my ($self, $fn, $markdown)=@_;
684 123 my $title;
685  
686 # Prefer authored frontmatter, accepting the simple quoted and unquoted
687 # title forms used by the supported documentation engines.
688 #
689 123 ▶ if ($markdown=~/\A---[ \t]*\r?\n(.*?)^---[ \t]*\r?\n/ms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($markdown =~ /\A---[ \t]*\r?\n(.*?)^---[ \t]*\r?\n/ms) 1 122 123
690 1 my $frontmatter=$1;
691 1 ($title)=$frontmatter=~/^title:[ \t]*(.*?)[ \t]*\r?$/m;
692 1 ▶ if (defined($title) && $title=~/\A"/) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $title and $title =~ /\A"/) { } 1 0 1
elsif (defined $title and $title =~ /\A'(.*)'\z/s) { } 0 0 0
Condition33%1/3
defined $title and $title =~ /\A"/
!ll&&!rl&&r
001
MC/DC0%0/2
defined $title and $title =~ /\A"/
defined $title $title =~ /\A"/
Truth table33%1/3
A and B
A= defined $titleB= $title =~ /\A"/
ABresult
0X0
100
111
693 1 my $decoded=eval {decode_json($title)};
694 1 ▶ $title=$decoded if defined($decoded) && !ref($decoded);
Branch: 1 branch
BranchTrueFalseTotal
if defined $decoded and not ref $decoded 1 0 1
Condition33%1/3
defined $decoded and not ref $decoded
!ll&&!rl&&r
001
MC/DC0%0/2
defined $decoded and not ref $decoded
defined $decoded not ref $decoded
Truth table33%1/3
A and not(B)
A= defined $decodedB= not ref $decoded
ABresult
0X0
100
111
695 }
696 ▶ elsif (defined($title) && $title=~/\A'(.*)'\z/s) {
Condition0%0/3
defined $title and $title =~ /\A'(.*)'\z/s
!ll&&!rl&&r
000
MC/DC0%0/2
defined $title and $title =~ /\A'(.*)'\z/s
defined $title $title =~ /\A'(.*)'\z/s
Truth table0%0/3
A and B
A= defined $titleB= $title =~ /\A'(.*)'\z/s
ABresult
0X0
100
111
697 0 $title=$1;
698 0 $title=~s/''/'/g;
699 }
700 }
701  
702 # Otherwise use the first level-one heading outside a fenced example.
703 #
704 123 ▶ unless (defined($title) && length($title)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $title and length $title) 122 1 123
Condition66%2/3
defined $title and length $title
!ll&&!rl&&r
12201
MC/DC50%1/2
defined $title and length $title
defined $title length $title
Truth table66%2/3
A and B
A= defined $titleB= length $title
ABresult
0X0
100
111
705 122 my ($fence, $length)=('', 0);
706 122 foreach my $line (split(/(?<=\n)/, $markdown)) {
707 122 ▶ if (!$fence && $line=~/^ {0,3}(`{3,}|~{3,})/) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $fence and $line =~ /^ {0,3}(`{3,}|~{3,})/) { } 0 122 122
elsif ($fence and $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/) { } 0 122 122
elsif (not $fence and $line =~ /^#\s+(.+?)\s*$/) { } 122 0 122
Condition33%1/3
not $fence and $line =~ /^ {0,3}(`{3,}|~{3,})/
!ll&&!rl&&r
01220
MC/DC0%0/2
not $fence and $line =~ /^ {0,3}(`{3,}|~{3,})/
not $fence $line =~ /^ {0,3}(`{3,}|~{3,})/
Truth table33%1/3
not(A) and B
A= not $fenceB= $line =~ /^ {0,3}(`{3,}|~{3,})/
ABresult
0X0
100
111
708 0 $fence=substr($1, 0, 1);
709 0 $length=length($1);
710 }
711 ▶ elsif ($fence && $line=~/^ {0,3}\Q$fence\E{$length,}\s*$/) {
Condition33%1/3
$fence and $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
!ll&&!rl&&r
12200
MC/DC0%0/2
$fence and $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
$fence $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
Truth table33%1/3
A and B
A= $fenceB= $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/
ABresult
0X0
100
111
712 0 $fence='';
713 }
714 ▶ elsif (!$fence && $line=~/^#\s+(.+?)\s*$/) {
Condition33%1/3
not $fence and $line =~ /^#\s+(.+?)\s*$/
!ll&&!rl&&r
00122
MC/DC0%0/2
not $fence and $line =~ /^#\s+(.+?)\s*$/
not $fence $line =~ /^#\s+(.+?)\s*$/
Truth table33%1/3
not(A) and B
A= not $fenceB= $line =~ /^#\s+(.+?)\s*$/
ABresult
0X0
100
111
715 122 $title=$1;
716 122 $title=~s/\s+\{#[^}]+\}\s*$//;
717 122 $title=~s/[ \t]+#+[ \t]*$//;
718 122 last;
719 }
720 }
721 }
722  
723 # A filename-derived label is a last resort for headingless documents.
724 #
725 123 ▶ unless (defined($title) && length($title)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $title and length $title) 0 123 123
Condition33%1/3
defined $title and length $title
!ll&&!rl&&r
00123
MC/DC0%0/2
defined $title and length $title
defined $title length $title
Truth table33%1/3
A and B
A= defined $titleB= length $title
ABresult
0X0
100
111
726 0 (undef, undef, $title)=File::Spec->splitpath($fn);
727 0 $title=~s/\.md$//;
728 0 $title=~s/[-_]+/ /g;
729 0 $title=join(' ', map {ucfirst($_)} split(/\s+/, $title));
730 }
731 123 $title=~s/\s+\{#[^}]+\}\s*$//;
732 123 return $title;
733  
734 }
735  
736  
737 60 ▶sub title_frontmatter {
Subroutine title_frontmatter: called CC=3 SCAR=16.3
Pod undocumented
738  
739 60 my ($self, $fn, $markdown)=@_;
740 60 my $title=$self->markdown_title($fn, $markdown);
741 60 ▶ if ($markdown=~/\A---[ \t]*\r?\n(.*?)^---[ \t]*\r?\n/ms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($markdown =~ /\A---[ \t]*\r?\n(.*?)^---[ \t]*\r?\n/ms) 0 60 60
742 0 my $frontmatter=$1;
743 0 ▶ return $markdown if $frontmatter=~/^title:[ \t]*/m;
Branch: 1 branch
BranchTrueFalseTotal
if $frontmatter =~ /^title:[ \t]*/m 0 0 0
744 0 my $title_line='title: '.encode_json($title)."\n";
745 0 $markdown=~s/\A(---[ \t]*\r?\n)/$1$title_line/;
746 0 return $markdown;
747 }
748 60 return "---\ntitle: ".encode_json($title)."\n---\n\n$markdown";
749  
750 }
751  
752  
753 13 ▶sub navigation {
Subroutine navigation: called CC=4 SCAR=13.9
Pod undocumented
754  
755 13 my ($self, $docs_dn, $pages_ar)=@_;
756 13 my @navigation;
757 13 foreach my $page (@{$pages_ar}) {
758 59 my $fn=File::Spec->catfile($docs_dn, $page);
759 59 ▶ open(my $input_fh, '<', $fn) || die "unable to read $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $input_fh, "<", $fn or die "unable to read ${fn}: $!\n" 59 0 59
760 59 local $/=undef;
761 59 my $markdown=<$input_fh>;
762 59 ▶ close($input_fh) || die "unable to close $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $input_fh or die "unable to close ${fn}: $!\n" 59 0 59
763 59 (my $id=$page)=~s/\.md$//;
764 59 $id=~s{\\}{/}g;
765 59 push(@navigation, {
766 file => $page,
767 id => $id,
768 title => $self->markdown_title($page, $markdown)
769 });
770 }
771 13 return \@navigation;
772  
773 }
774  
775  
776 13 ▶sub normalize_node_markdown {
Subroutine normalize_node_markdown: called CC=1 SCAR=0.0
Pod undocumented
777  
778 13 my ($self, $source_dn)=@_;
779 File::Find::find({
780 no_chdir => 1,
781 189 ▶ wanted => sub {
Subroutine __ANON__: called CC=5 SCAR=16.3
782 189 my $fn=$File::Find::name;
783 189 ▶ return unless -f $fn && $fn=~/\.md$/;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $fn and $fn =~ /\.md$/ 78 111 189
Condition66%2/3
-f $fn and $fn =~ /\.md$/
!ll&&!rl&&r
780111
MC/DC50%1/2
-f $fn and $fn =~ /\.md$/
-f $fn $fn =~ /\.md$/
Truth table66%2/3
A and B
A= -f $fnB= $fn =~ /\.md$/
ABresult
0X0
100
111
784 111 ▶ open(my $input_fh, '<', $fn) || die "unable to read $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $input_fh, "<", $fn or die "unable to read ${fn}: $!\n" 111 0 111
785 111 local $/=undef;
786 111 my $markdown=<$input_fh>;
787 111 ▶ close($input_fh) || die "unable to close $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $input_fh or die "unable to close ${fn}: $!\n" 111 0 111
788 111 $markdown=$self->normalize_node_definition_lists($markdown);
789 111 $markdown=$self->normalize_backend_markdown($fn, $markdown);
790 111 $markdown=$self->normalize_node_attributes($markdown);
791 111 $markdown=$self->normalize_node_admonitions($markdown);
792 111 $self->write_file($fn, $markdown);
793 }
794 13 }, $source_dn);
795 13 return 1;
796  
797 }
798  
799  
800 51 ▶sub normalize_backend_markdown {
Subroutine normalize_backend_markdown: called CC=1 SCAR=0.0
Pod undocumented
801  
802 51 my ($self, $fn, $markdown)=@_;
803 51 return $markdown;
804  
805 }
806  
807  
808 2 ▶sub npm_install {
Subroutine npm_install: called CC=3 SCAR=11.0
Pod undocumented
809  
810 2 my ($self, $site_dn)=@_;
811 2 my $npm=$self->option('npm', 'npm');
812 2 my $engine=ref($self);
813 2 $engine=~s/^.*:://;
814 2 print STDERR "Installing $engine npm dependencies...\n";
815 2 ▶ my @quiet=defined($MARKDOWN_PUBLISH_NPM_VERBOSE) &&
Branch: 1 branch
BranchTrueFalseTotal
defined $Markdown::Publish::MARKDOWN_PUBLISH_NPM_VERBOSE && $Markdown::Publish::MARKDOWN_PUBLISH_NPM_VERBOSE eq '1' ? : 1 1 2
Condition66%2/3
defined $Markdown::Publish::MARKDOWN_PUBLISH_NPM_VERBOSE and $Markdown::Publish::MARKDOWN_PUBLISH_NPM_VERBOSE eq 1
!ll&&!rl&&r
011
MC/DC50%1/2
defined $Markdown::Publish::MARKDOWN_PUBLISH_NPM_VERBOSE and $Markdown::Publish::MARKDOWN_PUBLISH_NPM_VERBOSE eq 1
defined $Markdown::Publish::MARKDOWN_PUBLISH_NPM_VERBOSE $Markdown::Publish::MARKDOWN_PUBLISH_NPM_VERBOSE eq 1
Truth table66%2/3
A and B
A= defined $Markdown::Publish::MARKDOWN_PUBLISH_NPM_VERBOSEB= $Markdown::Publish::MARKDOWN_PUBLISH_NPM_VERBOSE eq 1
ABresult
0X0
100
111
816 $MARKDOWN_PUBLISH_NPM_VERBOSE eq '1' ? () : ('--silent');
817 2 $self->system_in_dir($site_dn, $npm, 'install', @quiet);
818 2 print STDERR "$engine npm dependencies installed.\n";
819 2 return 1;
820  
821 }
822  
823  
824 0 ▶sub build {
Subroutine build: not called CC=1 SCAR=6.9
Pod undocumented
825  
826 0 die "publication backend must implement build()\n";
827  
828 }
829  
830  
831 0 ▶sub serve {
Subroutine serve: not called CC=1 SCAR=6.9
Pod undocumented
832  
833 0 die "publication backend must implement serve()\n";
834  
835 }
836  
837  
838 0 ▶sub publish_gh {
Subroutine publish_gh: not called CC=7 SCAR=40.3
Pod documented
839  
840  
841 # Build first, then replace only the disposable publication worktree.
842 # Leave the resulting branch local so pushing remains an explicit Git
843 # operation controlled by the repository's configured upstream.
844 #
845 0 my ($self)=@_;
846 0 my $branch=$self->option('branch', $MARKDOWN_PUBLISH_BRANCH);
847 0 my $base=$self->github_site_base();
848 0 local $self->{'base'}=$base;
849 0 my $site_dn=$self->build();
850 0 $self->command('git', 'check-ref-format', '--branch', $branch);
851 0 my $temporary_dn=abs_path(tempdir(CLEANUP => 1));
852 0 my $work_dn=File::Spec->catdir($temporary_dn, 'pages');
853 0 my $exists=eval {
854 0 $self->command('git', 'rev-parse', '--verify', "refs/heads/$branch");
855 0 1;
856 };
857 0 ▶ $self->command('git', 'worktree', 'add', ($exists ? () : '--detach'), $work_dn,
Branch: 2 branches
BranchTrueFalseTotal
$exists ? : 0 0 0
$exists ? : 0 0 0
858 $exists ? $branch : 'HEAD');
859 0 my $ok=eval {
860 0 ▶ $self->command('git', '-C', $work_dn, 'checkout', '--orphan', $branch)
Branch: 1 branch
BranchTrueFalseTotal
unless $exists 0 0 0
861 unless $exists;
862 0 $self->command('git', '-C', $work_dn, 'rm', '-r', '-f', '--ignore-unmatch', '.');
863 0 $self->copy_tree($site_dn, $work_dn);
864 0 $self->write_file(File::Spec->catfile($work_dn, '.nojekyll'), '');
865 0 $self->command('git', '-C', $work_dn, 'add', '.');
866 0 ▶ my $changed=$exists ?
Branch: 1 branch
BranchTrueFalseTotal
$exists ? : 0 0 0
867 length($self->command('git', '-C', $work_dn, 'diff', '--cached', '--name-only')) : 1;
868 0 ▶ $self->command('git', '-C', $work_dn, 'commit', '-m', 'Update documentation')
Branch: 1 branch
BranchTrueFalseTotal
if $changed 0 0 0
869 if $changed;
870 0 1;
871 };
872 0 my $error=$@;
873 0 $self->command('git', 'worktree', 'remove', '--force', $work_dn);
874 0 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
875 0 return $branch;
876  
877 }
878  
879  
880 1 ▶sub publish_gh_push {
Subroutine publish_gh_push: called CC=1 SCAR=0.0
Pod documented
881  
882  
883 # Keep local branch creation in publish_gh(), then make the remote side
884 # effect explicit by pushing only the resulting branch to origin.
885 #
886 1 my ($self)=@_;
887 1 my $branch=$self->publish_gh();
888 1 $self->command('git', 'push', 'origin', $branch);
889 1 return $branch;
890  
891 }
892  
893  
894 7 ▶sub publish_cloudflare {
Subroutine publish_cloudflare: called CC=14 SCAR=26.5
Pod documented
895  
896  
897 # The site generator owns the build; Wrangler deploys only the resulting
898 # static assets using an explicit or conventional root configuration.
899 #
900 7 my ($self)=@_;
901 7 ▶ my $cloudflare_hr=exists($self->{'cloudflare'}) ? $self->{'cloudflare'} : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'cloudflare'} ? : 4 3 7
902 7 ▶ die "cloudflare publication configuration must be a hash reference\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cloudflare_hr eq "HASH" 1 6 7
903 unless ref($cloudflare_hr) eq 'HASH';
904 6 my $config_fn;
905 6 ▶ if (exists($cloudflare_hr->{'config'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cloudflare_hr->{'config'}) { } 3 3 6
906 3 $config_fn=$cloudflare_hr->{'config'};
907 3 ▶ die "cloudflare publication requires a Wrangler configuration file\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config_fn and length $config_fn 0 3 3
Condition33%1/3
defined $config_fn and length $config_fn
!ll&&!rl&&r
003
MC/DC0%0/2
defined $config_fn and length $config_fn
defined $config_fn length $config_fn
Truth table33%1/3
A and B
A= defined $config_fnB= length $config_fn
ABresult
0X0
100
111
908 unless defined($config_fn) && length($config_fn);
909 }
910 else {
911 3 foreach my $candidate_fn (qw(wrangler.jsonc wrangler.json)) {
912 5 ▶ if (-f $candidate_fn) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $candidate_fn) 2 3 5
913 2 $config_fn=$candidate_fn;
914 2 last;
915 }
916 }
917 3 ▶ die "cloudflare publication requires cloudflare.config or wrangler.jsonc/wrangler.json in the project root\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config_fn 1 2 3
918 unless defined($config_fn);
919 }
920 5 ▶ die "Wrangler configuration not found: $config_fn\n" unless -f $config_fn;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $config_fn 1 4 5
921 4 $config_fn=abs_path($config_fn);
922 4 ▶ my $wrangler=$cloudflare_hr->{'wrangler'} || 'wrangler';
Condition100%2/2
$cloudflare_hr->{'wrangler'} || 'wrangler'
l!l
13
MC/DC100%1/1
$cloudflare_hr->{'wrangler'} || 'wrangler'
$cloudflare_hr->{'wrangler'}
Truth table100%2/2
A
A= $cloudflare_hr->{'wrangler'}
Aresult
11
00
923  
924 4 my $site_dn=$self->build();
925 4 ▶ die "built site directory not found: $site_dn\n" unless -d $site_dn;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $site_dn 1 3 4
926 3 $site_dn=abs_path($site_dn);
927 3 my @command=($wrangler, 'deploy', '--config', $config_fn,
928 '--assets', $site_dn);
929 push(@command, '--env', $cloudflare_hr->{'environment'})
930 3 ▶ if defined($cloudflare_hr->{'environment'}) && length($cloudflare_hr->{'environment'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $cloudflare_hr->{"environment"} and length $cloudflare_hr->{"environment"} 1 2 3
Condition66%2/3
defined $cloudflare_hr->{"environment"} and length $cloudflare_hr->{"environment"}
!ll&&!rl&&r
201
MC/DC50%1/2
defined $cloudflare_hr->{"environment"} and length $cloudflare_hr->{"environment"}
defined $cloudflare_hr->{"environment"} length $cloudflare_hr->{"environment"}
Truth table66%2/3
A and B
A= defined $cloudflare_hr->{"environment"}B= length $cloudflare_hr->{"environment"}
ABresult
0X0
100
111
931 3 $self->system_command(@command);
932 3 return $site_dn;
933  
934 }
935  
936  
937 __END__
« blib/lib/Markdown/Publish/VitePress.pm ↑ Summary lib/Markdown/Publish/MkDocs.pm »