Publish.pm

filter: Statementstmt 67.9% 481 / 708 Branchbran 51.7% 208 / 402 Conditioncond 53.0% 114 / 215 MC/DCmcdc 37.3% 47 / 126 Subroutinesub 66.6% 54 / 81 Podpod 21.3% 13 / 61 totaltotal 57.5% 917 / 1593 CC 435 SCAR 29.0
CC
435
Cov
61%
markdown_title
57.0
markdown_title
57.0
publish_gh
56.0
CRAP 18.2
« Publish/MkDocs.pm ↑ Summary Publish/Starlight.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 4 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 ▶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 $AUTHORITY='cpan:ASPEER';
40 $VERSION='1.005';
41  
42  
43 # Supported publication actions
44 #
45 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 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 1;
61  
62  
63 #======================================================================================================================
64  
65 82 ▶sub new {
Subroutine new: called CC=13 SCAR=37.3
Pod documented
66  
67 0 ▶ my ($class, $opt_hr)=@_;
Subroutine new: not called CC=13 SCAR=37.3
Pod documented
68 0 ▶ $opt_hr={} unless defined($opt_hr);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $opt_hr 0 0 0
unless defined $opt_hr 13 69 82
69 0 ▶ die "publication configuration must be a hash reference\n"
Branch: 2 branches
BranchTrueFalseTotal
unless ref $opt_hr eq "HASH" 0 0 0
unless ref $opt_hr eq "HASH" 0 82 82
70 unless ref($opt_hr) eq 'HASH';
71 0 ▶ if ($class eq __PACKAGE__) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 0 0 0
if ($class eq __PACKAGE__) 20 62 82
72 0 ▶ if (exists($opt_hr->{'config_file'})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opt_hr->{"config_file"}) 0 0 0
if (exists $opt_hr->{"config_file"}) 2 18 20
73 die "config_file cannot be combined with inline publication settings\n"
74 0 ▶ unless keys(%{$opt_hr})==1;
Branch: 2 branches
BranchTrueFalseTotal
unless keys %{$opt_hr;} == 1 0 0 0
unless keys %{$opt_hr;} == 1 1 1 2
75 0 return $class->load_config($opt_hr->{'config_file'});
76 }
77 my $publisher=defined($ENV{'MARKDOWN_PUBLISH_MODULE'}) ?
78 $ENV{'MARKDOWN_PUBLISH_MODULE'} :
79 0 ▶ (exists($opt_hr->{'module'}) ? $opt_hr->{'module'} : $MARKDOWN_PUBLISH_MODULE);
Branch: 4 branches
BranchTrueFalseTotal
defined $ENV{'MARKDOWN_PUBLISH_MODULE'} ? : 0 0 0
exists $opt_hr->{'module'} ? : 0 0 0
defined $ENV{'MARKDOWN_PUBLISH_MODULE'} ? : 4 14 18
exists $opt_hr->{'module'} ? : 12 2 14
80 0 ▶ die "publication module is not defined\n"
Branch: 2 branches
BranchTrueFalseTotal
unless defined $publisher and length $publisher 0 0 0
unless defined $publisher and length $publisher 0 18 18
Condition16%1/6
defined $publisher and length $publisher
!ll&&!rl&&r
000
defined $publisher and length $publisher
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $publisher and length $publisher
defined $publisher length $publisher
MC/DC0%0/2
defined $publisher and length $publisher
defined $publisher length $publisher
Truth table0%0/3
A and B
A= defined $publisherB= length $publisher
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $publisherB= length $publisher
ABresult
0X0
100
111
81 unless defined($publisher) && length($publisher);
82 0 ▶ $publisher=$module_alias{lc($publisher)} || $publisher;
Condition33%2/6
$module_alias{lc $publisher} || $publisher
l!l&&r!l&&!r
000
$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
MC/DC0%0/2
$module_alias{lc $publisher} || $publisher
$module_alias{lc $publisher} $publisher
Truth table0%0/3
A || B
A= $module_alias{lc $publisher}B= $publisher
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $module_alias{lc $publisher}B= $publisher
ABresult
1X1
011
000
83 0 (my $publisher_fn=$publisher)=~s{::}{/}g;
84 0 my $loaded=eval {
85 0 require "$publisher_fn.pm";
86 0 1;
87 };
88 0 ▶ die "unable to load publication module $publisher: $@"
Branch: 2 branches
BranchTrueFalseTotal
unless $loaded 0 0 0
unless $loaded 2 16 18
89 unless $loaded;
90 0 ▶ die "$publisher is not a Markdown::Publish subclass\n"
Branch: 2 branches
BranchTrueFalseTotal
unless $publisher->isa(__PACKAGE__) 0 0 0
unless $publisher->isa(__PACKAGE__) 1 15 16
91 unless $publisher->isa(__PACKAGE__);
92 0 return $publisher->new($opt_hr);
93 }
94 0 my $self=bless({%{$opt_hr}}, $class);
95 0 return $self;
96  
97 }
98  
99  
100 5 ▶sub load_config {
Subroutine load_config: called CC=6 SCAR=26.0
Pod documented
101  
102  
103 # Read a standalone JSON configuration and accept either the complete
104 # metadata extension or its publish section.
105 #
106 0 ▶ my ($class, $config_fn)=@_;
Subroutine load_config: not called CC=6 SCAR=26.0
Pod documented
107 0 ▶ open(my $config_fh, '<', $config_fn) ||
Branch: 2 branches
BranchTrueFalseTotal
open my $config_fh, "<", $config_fn or die "unable to read publication configuration ${config_fn}: $!\n" 0 0 0
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 0 local $/=undef;
110 0 my $json=<$config_fh>;
111 0 ▶ close($config_fh) ||
Branch: 2 branches
BranchTrueFalseTotal
close $config_fh or die "unable to close publication configuration ${config_fn}: $!\n" 0 0 0
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 0 my $config_hr=decode_json($json);
114 0 ▶ die "publication configuration in $config_fn must be an object\n"
Branch: 2 branches
BranchTrueFalseTotal
unless ref $config_hr eq "HASH" 0 0 0
unless ref $config_hr eq "HASH" 0 5 5
115 unless ref($config_hr) eq 'HASH';
116  
117 0 ▶ if (ref($config_hr->{'x_documentation'}) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $config_hr->{"x_documentation"} eq "HASH") 0 0 0
if (ref $config_hr->{"x_documentation"} eq "HASH") 3 2 5
118 0 $config_hr=$config_hr->{'x_documentation'};
119 }
120 0 ▶ if (ref($config_hr->{'publish'}) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $config_hr->{"publish"} eq "HASH") 0 0 0
if (ref $config_hr->{"publish"} eq "HASH") 5 0 5
121 0 $config_hr=$config_hr->{'publish'};
122 }
123 0 return $class->new($config_hr);
124  
125 }
126  
127  
128 140 ▶sub option {
Subroutine option: called CC=2 SCAR=9.2
Pod undocumented
129  
130 0 ▶ my ($self, $name, $default)=@_;
Subroutine option: not called CC=2 SCAR=9.2
Pod undocumented
131 0 ▶ return $self->{$name} if exists($self->{$name});
Branch: 2 branches
BranchTrueFalseTotal
if exists $self->{$name} 0 0 0
if exists $self->{$name} 32 108 140
132 0 return $default;
133  
134 }
135  
136  
137 20 ▶sub configuration_files {
Subroutine configuration_files: called CC=7 SCAR=27.0
Pod undocumented
138  
139 0 ▶ my ($self)=@_;
Subroutine configuration_files: not called CC=7 SCAR=27.0
Pod undocumented
140 0 my $config_fn=$self->option('config', undef);
141 0 my $extend_fn=$self->option('config_extend', undef);
142 0 ▶ my $has_config=defined($config_fn) && length($config_fn);
Condition33%2/6
defined $config_fn && length $config_fn
!ll&&!rl&&r
000
defined $config_fn && length $config_fn
!ll&&!rl&&r
1505
MC/DC0%0/2
defined $config_fn && length $config_fn
defined $config_fn length $config_fn
MC/DC50%1/2
defined $config_fn && length $config_fn
defined $config_fn length $config_fn
Truth table0%0/3
A && B
A= defined $config_fnB= length $config_fn
ABresult
0X0
100
111
Truth table66%2/3
A && B
A= defined $config_fnB= length $config_fn
ABresult
0X0
100
111
143 0 ▶ my $has_extend=defined($extend_fn) && length($extend_fn);
Condition33%2/6
defined $extend_fn && length $extend_fn
!ll&&!rl&&r
000
defined $extend_fn && length $extend_fn
!ll&&!rl&&r
1307
MC/DC0%0/2
defined $extend_fn && length $extend_fn
defined $extend_fn length $extend_fn
MC/DC50%1/2
defined $extend_fn && length $extend_fn
defined $extend_fn length $extend_fn
Truth table0%0/3
A && B
A= defined $extend_fnB= length $extend_fn
ABresult
0X0
100
111
Truth table66%2/3
A && B
A= defined $extend_fnB= length $extend_fn
ABresult
0X0
100
111
144 0 ▶ die "config and config_extend cannot be combined\n"
Branch: 2 branches
BranchTrueFalseTotal
if $has_config and $has_extend 0 0 0
if $has_config and $has_extend 1 19 20
Condition50%3/6
$has_config and $has_extend
!ll&&!rl&&r
000
$has_config and $has_extend
!ll&&!rl&&r
1541
MC/DC0%0/2
$has_config and $has_extend
$has_config $has_extend
MC/DC100%2/2
$has_config and $has_extend
$has_config $has_extend
Truth table0%0/3
A and B
A= $has_configB= $has_extend
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= $has_configB= $has_extend
ABresult
0X0
100
111
145 if $has_config && $has_extend;
146 0 ▶ return ($has_config ? $config_fn : undef,
Branch: 4 branches
BranchTrueFalseTotal
$has_config ? : 0 0 0
$has_extend ? : 0 0 0
$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=15.7
Pod undocumented
153  
154 0 ▶ my ($self, $pages_ar, $navigation_ar)=@_;
Subroutine configuration_context: not called CC=3 SCAR=15.7
Pod undocumented
155 0 ▶ $pages_ar=[] unless defined($pages_ar);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $pages_ar 0 0 0
unless defined $pages_ar 0 3 3
156 0 ▶ $navigation_ar=[] unless defined($navigation_ar);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $navigation_ar 0 0 0
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 0 pages => [@{$pages_ar}],
162 0 navigation => [map {{%{$_}}} @{$navigation_ar}]
163 };
164  
165 }
166  
167  
168 13 ▶sub site_base {
Subroutine site_base: called CC=10 SCAR=35.8
Pod undocumented
169  
170 0 ▶ my ($self, $default)=@_;
Subroutine site_base: not called CC=10 SCAR=35.8
Pod undocumented
171 0 ▶ my $base=exists($self->{'base'}) ? $self->{'base'} : $default;
Branch: 2 branches
BranchTrueFalseTotal
exists $self->{'base'} ? : 0 0 0
exists $self->{'base'} ? : 11 2 13
172 0 ▶ return undef unless defined($base);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $base 0 0 0
unless defined $base 0 13 13
173 0 ▶ die "publication base must start and end with / and contain no empty or dot segments\n"
Branch: 2 branches
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?#]/ 0 0 0
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
Condition30%11/36
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
000
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
000
ref $base or not length $base or not $base =~ m[\A/] or not $base =~ m[/\z] or $base =~ m[//]
l!l&&r!l&&!r
000
ref $base or not length $base or not $base =~ m[\A/] or not $base =~ m[/\z]
l!l&&r!l&&!r
000
ref $base or not length $base or not $base =~ m[\A/]
l!l&&r!l&&!r
000
ref $base or not length $base
l!l&&r!l&&!r
000
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/DC0%0/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?#]/
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 table0%0/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
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 0 return $base;
177  
178 }
179  
180  
181 3 ▶sub github_repository_name {
Subroutine github_repository_name: called CC=7 SCAR=28.7
Pod undocumented
182  
183 0 ▶ my ($self)=@_;
Subroutine github_repository_name: not called CC=7 SCAR=28.7
Pod undocumented
184 0 my $remote;
185 0 eval {$remote=$self->command('git', 'config', '--get', 'remote.origin.url')};
186 0 ▶ if (defined($remote) && length($remote)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $remote and length $remote) 0 0 0
if (defined $remote and length $remote) 2 1 3
Condition33%2/6
defined $remote and length $remote
!ll&&!rl&&r
000
defined $remote and length $remote
!ll&&!rl&&r
102
MC/DC0%0/2
defined $remote and length $remote
defined $remote length $remote
MC/DC50%1/2
defined $remote and length $remote
defined $remote length $remote
Truth table0%0/3
A and B
A= defined $remoteB= length $remote
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= defined $remoteB= length $remote
ABresult
0X0
100
111
187 0 $remote=~s/[\r\n]+\z//;
188 0 $remote=~s{[/\\]+\z}{};
189 0 $remote=~s{\.git\z}{}i;
190 0 ▶ if ($remote=~m{([^/\\:]+)\z}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($remote =~ m[([^/\\:]+)\z]) 0 0 0
if ($remote =~ m[([^/\\:]+)\z]) 2 0 2
191 0 my $repository=$1;
192 0 ▶ return $repository if $repository=~/\A[A-Za-z0-9._-]+\z/;
Branch: 2 branches
BranchTrueFalseTotal
if $repository =~ /\A[A-Za-z0-9._-]+\z/ 0 0 0
if $repository =~ /\A[A-Za-z0-9._-]+\z/ 2 0 2
193 }
194 }
195 0 my $root_dn=$self->command('git', 'rev-parse', '--show-toplevel');
196 0 $root_dn=~s/[\r\n]+\z//;
197 0 my $repository=basename($root_dn);
198 0 ▶ die "unable to determine GitHub repository name\n"
Branch: 2 branches
BranchTrueFalseTotal
unless defined $repository and $repository =~ /\A[A-Za-z0-9._-]+\z/ 0 0 0
unless defined $repository and $repository =~ /\A[A-Za-z0-9._-]+\z/ 0 1 1
Condition16%1/6
defined $repository and $repository =~ /\A[A-Za-z0-9._-]+\z/
!ll&&!rl&&r
000
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/
MC/DC0%0/2
defined $repository and $repository =~ /\A[A-Za-z0-9._-]+\z/
defined $repository $repository =~ /\A[A-Za-z0-9._-]+\z/
Truth table0%0/3
A and B
A= defined $repositoryB= $repository =~ /\A[A-Za-z0-9._-]+\z/
ABresult
0X0
100
111
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 0 return $repository;
201  
202 }
203  
204  
205 3 ▶sub github_base {
Subroutine github_base: called CC=2 SCAR=9.2
Pod undocumented
206  
207 0 ▶ my ($self)=@_;
Subroutine github_base: not called CC=2 SCAR=9.2
Pod undocumented
208 0 my $repository=$self->github_repository_name();
209 0 ▶ return '/' if $repository=~/\.github\.io\z/i;
Branch: 2 branches
BranchTrueFalseTotal
if $repository =~ /\.github\.io\z/i 0 0 0
if $repository =~ /\.github\.io\z/i 1 2 3
210 0 return "/$repository/";
211  
212 }
213  
214  
215 4 ▶sub github_site_base {
Subroutine github_site_base: called CC=2 SCAR=9.2
Pod undocumented
216  
217 0 ▶ my ($self)=@_;
Subroutine github_site_base: not called CC=2 SCAR=9.2
Pod undocumented
218 0 ▶ return $self->site_base('/') if exists($self->{'base'});
Branch: 2 branches
BranchTrueFalseTotal
if exists $self->{"base"} 0 0 0
if exists $self->{"base"} 1 3 4
219 0 return $self->github_base();
220  
221 }
222  
223  
224 6 ▶sub validate_action {
Subroutine validate_action: called CC=3 SCAR=15.3
Pod undocumented
225  
226 0 ▶ my ($self, $action)=@_;
Subroutine validate_action: not called CC=3 SCAR=15.3
Pod undocumented
227 die "unknown publication action: $action\n"
228 0 ▶ unless defined($action) && $ACTION{$action};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $action and $ACTION{$action} 0 0 0
unless defined $action and $ACTION{$action} 1 5 6
Condition33%2/6
defined $action and $ACTION{$action}
!ll&&!rl&&r
000
defined $action and $ACTION{$action}
!ll&&!rl&&r
015
MC/DC0%0/2
defined $action and $ACTION{$action}
defined $action $ACTION{$action}
MC/DC50%1/2
defined $action and $ACTION{$action}
defined $action $ACTION{$action}
Truth table0%0/3
A and B
A= defined $actionB= $ACTION{$action}
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= defined $actionB= $ACTION{$action}
ABresult
0X0
100
111
229 0 return 1;
230  
231 }
232  
233  
234 6 ▶sub run {
Subroutine run: called CC=5 SCAR=20.9
Pod documented
235  
236 0 ▶ my ($self, $action)=@_;
Subroutine run: not called CC=5 SCAR=20.9
Pod documented
237 0 $self->validate_action($action);
238 0 ▶ return $self->build() if $action eq 'build';
Branch: 2 branches
BranchTrueFalseTotal
if $action eq "build" 0 0 0
if $action eq "build" 1 4 5
239 0 ▶ return $self->serve() if $action eq 'serve';
Branch: 2 branches
BranchTrueFalseTotal
if $action eq "serve" 0 0 0
if $action eq "serve" 1 3 4
240 0 ▶ return $self->publish_gh() if $action eq 'gh';
Branch: 2 branches
BranchTrueFalseTotal
if $action eq "gh" 0 0 0
if $action eq "gh" 1 2 3
241 0 ▶ return $self->publish_gh_push() if $action eq 'gh-push';
Branch: 2 branches
BranchTrueFalseTotal
if $action eq "gh-push" 0 0 0
if $action eq "gh-push" 1 1 2
242 0 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)=@_;
Subroutine command: not called CC=2 SCAR=17.9
Pod undocumented
250 0 my ($output, $error);
251 0 run3(\@command, \undef, \$output, \$error);
252 0 ▶ die "command failed (@command): $error\n" if $?;
Branch: 2 branches
BranchTrueFalseTotal
if $? 0 0 0
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)=@_;
Subroutine system_command: not called CC=2 SCAR=17.9
Pod undocumented
261 0 system(@command);
262 0 ▶ die "command failed (@command)\n" if $?;
Branch: 2 branches
BranchTrueFalseTotal
if $? 0 0 0
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)=@_;
Subroutine system_in_dir: not called CC=4 SCAR=30.0
Pod undocumented
271 0 my $cwd=getcwd();
272 0 ▶ chdir($dir) || die "unable to chdir $dir: $!\n";
Branch: 2 branches
BranchTrueFalseTotal
chdir $dir or die "unable to chdir ${dir}: $!\n" 0 0 0
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: 2 branches
BranchTrueFalseTotal
chdir $cwd or die "unable to chdir ${cwd}: $!\n" 0 0 0
chdir $cwd or die "unable to chdir ${cwd}: $!\n" 0 0 0
276 0 ▶ die $error unless $ok;
Branch: 2 branches
BranchTrueFalseTotal
unless $ok 0 0 0
unless $ok 0 0 0
277 0 return 1;
278  
279 }
280  
281  
282 261 ▶sub write_file {
Subroutine write_file: called CC=5 SCAR=24.7
Pod undocumented
283  
284 0 ▶ my ($self, $fn, $text)=@_;
Subroutine write_file: not called CC=5 SCAR=24.7
Pod undocumented
285 0 my (undef, $parent_dn)=File::Spec->splitpath($fn);
286 0 ▶ make_path($parent_dn) if length($parent_dn) && !-d $parent_dn;
Branch: 2 branches
BranchTrueFalseTotal
if length $parent_dn and not -d $parent_dn 0 0 0
if length $parent_dn and not -d $parent_dn 0 261 261
Condition16%1/6
length $parent_dn and not -d $parent_dn
!ll&&!rl&&r
000
length $parent_dn and not -d $parent_dn
!ll&&!rl&&r
02610
MC/DC0%0/2
length $parent_dn and not -d $parent_dn
length $parent_dn not -d $parent_dn
MC/DC0%0/2
length $parent_dn and not -d $parent_dn
length $parent_dn not -d $parent_dn
Truth table0%0/3
A and not(B)
A= length $parent_dnB= not -d $parent_dn
ABresult
0X0
100
111
Truth table33%1/3
A and not(B)
A= length $parent_dnB= not -d $parent_dn
ABresult
0X0
100
111
287 0 ▶ open(my $output_fh, '>', $fn) || die "unable to write $fn: $!\n";
Branch: 2 branches
BranchTrueFalseTotal
open my $output_fh, ">", $fn or die "unable to write ${fn}: $!\n" 0 0 0
open my $output_fh, ">", $fn or die "unable to write ${fn}: $!\n" 261 0 261
288 0 print {$output_fh} $text;
289 0 ▶ close($output_fh) || die "unable to close $fn: $!\n";
Branch: 2 branches
BranchTrueFalseTotal
close $output_fh or die "unable to close ${fn}: $!\n" 0 0 0
close $output_fh or die "unable to close ${fn}: $!\n" 261 0 261
290 0 return 1;
291  
292 }
293  
294  
295 53 ▶sub copy_tree {
Subroutine copy_tree: called CC=2 SCAR=10.1
Pod undocumented
296  
297 0 ▶ my ($self, $source_dn, $target_dn)=@_;
Subroutine copy_tree: not called CC=2 SCAR=10.1
Pod undocumented
298 0 ▶ return unless -d $source_dn;
Branch: 2 branches
BranchTrueFalseTotal
unless -d $source_dn 0 0 0
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=23.4
302 0 ▶ my $fn=$File::Find::name;
Subroutine __ANON__: not called CC=5 SCAR=23.4
303 0 ▶ return if -l $fn;
Branch: 2 branches
BranchTrueFalseTotal
if -l $fn 0 0 0
if -l $fn 0 102 102
304 0 my $relative=File::Spec->abs2rel($fn, $source_dn);
305 0 my $output_fn=File::Spec->catfile($target_dn, $relative);
306 0 ▶ if (-d $fn) {
Branch: 4 branches
BranchTrueFalseTotal
if (-d $fn) { } 0 0 0
elsif (-f $fn) { } 0 0 0
if (-d $fn) { } 42 60 102
elsif (-f $fn) { } 60 0 60
307 0 make_path($output_fn);
308 }
309 elsif (-f $fn) {
310 0 ▶ copy($fn, $output_fn) || die "unable to copy $fn: $!\n";
Branch: 2 branches
BranchTrueFalseTotal
copy($fn, $output_fn) or die "unable to copy ${fn}: $!\n" 0 0 0
copy($fn, $output_fn) or die "unable to copy ${fn}: $!\n" 60 0 60
311 }
312 }
313 0 }, $source_dn);
314 0 return 1;
315  
316 }
317  
318  
319 22 ▶sub source_directories {
Subroutine source_directories: called CC=5 SCAR=26.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 0 ▶ my ($self)=@_;
Subroutine source_directories: not called CC=5 SCAR=26.7
Pod documented
326 0 ▶ if (exists($self->{'sources'})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{"sources"}) 0 0 0
if (exists $self->{"sources"}) 16 6 22
327 die "publication sources must be an array reference\n"
328 0 ▶ unless ref($self->{'sources'}) eq 'ARRAY';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $self->{"sources"} eq "ARRAY" 0 0 0
unless ref $self->{"sources"} eq "ARRAY" 0 16 16
329 0 return [@{$self->{'sources'}}];
330 }
331 0 ▶ return ['doc'] if -d 'doc';
Branch: 2 branches
BranchTrueFalseTotal
if -d "doc" 0 0 0
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: 2 branches
BranchTrueFalseTotal
if @source_dn 0 0 0
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=14.2
Pod undocumented
341  
342 0 ▶ my ($self, $source_dn, $fn)=@_;
Subroutine target_filename: not called CC=3 SCAR=14.2
Pod undocumented
343 0 my $relative=File::Spec->abs2rel($fn, $source_dn);
344 0 ▶ if ($source_dn eq 'lib') {
Branch: 2 branches
BranchTrueFalseTotal
if ($source_dn eq "lib") 0 0 0
if ($source_dn eq "lib") 1 76 77
345 0 $relative=~s/\.pm\.md$/.md/;
346 0 $relative=~s{[/\\]}{_}g;
347 0 return File::Spec->catfile('modules', $relative);
348 }
349 0 ▶ if ($source_dn eq 'bin') {
Branch: 2 branches
BranchTrueFalseTotal
if ($source_dn eq "bin") 0 0 0
if ($source_dn eq "bin") 1 75 76
350 0 return File::Spec->catfile('utilities', $relative);
351 }
352 0 return $relative;
353  
354 }
355  
356  
357 42 ▶sub copy_markdown_tree {
Subroutine copy_markdown_tree: called CC=2 SCAR=7.5
Pod undocumented
358  
359 0 ▶ my ($self, $source_dn, $docs_dn)=@_;
Subroutine copy_markdown_tree: not called CC=2 SCAR=7.5
Pod undocumented
360 0 ▶ return unless -d $source_dn;
Branch: 2 branches
BranchTrueFalseTotal
unless -d $source_dn 0 0 0
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 wanted => sub {
365 114 ▶ my $fn=$File::Find::name;
Subroutine __ANON__: called CC=6 SCAR=18.4
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 0 }, $source_dn);
377 0 return 1;
378  
379 }
380  
381  
382 sub rewrite_source_url {
383  
384 36 ▶ my ($self, $source_fn, $target_fn, $url)=@_;
Subroutine rewrite_source_url: called CC=9 SCAR=22.4
Pod undocumented
385 36 ▶ return $url unless $url=~m{^\.\./};
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ m[^\.\./] 0 36 36
386 36 my ($path, $suffix)=$url=~/^([^?#]+)(.*)$/;
387 36 ▶ return $url unless defined($path) && $path=~/\.md$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path and $path =~ /\.md$/ 0 36 36
Condition33%1/3
defined $path and $path =~ /\.md$/
!ll&&!rl&&r
0036
MC/DC0%0/2
defined $path and $path =~ /\.md$/
defined $path $path =~ /\.md$/
Truth table33%1/3
A and B
A= defined $pathB= $path =~ /\.md$/
ABresult
0X0
100
111
388  
389 36 my (undef, $source_dn)=File::Spec->splitpath($source_fn);
390 36 my $candidate_fn=File::Spec->catfile($source_dn, split(m{/}, $path));
391 36 ▶ return $url if -l $candidate_fn || !-f $candidate_fn;
Branch: 1 branch
BranchTrueFalseTotal
if -l $candidate_fn or not -f $candidate_fn 4 32 36
Condition66%2/3
-l $candidate_fn or not -f $candidate_fn
l!l&&r!l&&!r
0432
MC/DC50%1/2
-l $candidate_fn or not -f $candidate_fn
-l $candidate_fn not -f $candidate_fn
Truth table66%2/3
A or not(B)
A= -l $candidate_fnB= not -f $candidate_fn
ABresult
1X1
011
000
392 32 my $repository_dn=abs_path('.');
393 32 my $resolved_fn=abs_path($candidate_fn);
394 32 ▶ return $url unless defined($resolved_fn);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $resolved_fn 0 32 32
395 32 my $relative_fn=File::Spec->abs2rel($resolved_fn, $repository_dn);
396 32 $relative_fn=~s{\\}{/}g;
397 32 ▶ return $url unless $relative_fn=~m{^(?:lib|bin)/};
Branch: 1 branch
BranchTrueFalseTotal
unless $relative_fn =~ m[^(?:lib|bin)/] 4 28 32
398  
399 28 my (undef, $target_dn)=File::Spec->splitpath($target_fn);
400 28 ▶ $target_dn='.' unless length($target_dn);
Branch: 1 branch
BranchTrueFalseTotal
unless length $target_dn 8 20 28
401 28 my $rewritten=File::Spec->abs2rel($relative_fn, $target_dn);
402 28 $rewritten=~s{\\}{/}g;
403 28 return $rewritten.$suffix;
404  
405 }
406  
407  
408 sub rewrite_link_segment {
409  
410 614 ▶ my ($self, $source_fn, $target_fn, $text)=@_;
Subroutine rewrite_link_segment: called CC=1 SCAR=0.0
Pod undocumented
411 614 $text=~s{
412 (\]\(\s*<?)
413 (\.\./[^\s)>]+)
414 (>?)
415 (?=\s|\))
416 }{
417 32 my ($prefix, $url, $close)=($1, $2, $3);
418 32 $prefix.$self->rewrite_source_url($source_fn, $target_fn, $url).$close;
419 }egx;
420 614 $text=~s{
421 (^\ {0,3}\[[^\]\n]+\]:\s*<?)
422 (\.\./[^\s>]+)
423 (>?)
424 (?=\s|$)
425 }{
426 4 my ($prefix, $url, $close)=($1, $2, $3);
427 4 $prefix.$self->rewrite_source_url($source_fn, $target_fn, $url).$close;
428 }egmx;
429 614 return $text;
430  
431 }
432  
433  
434 sub rewrite_link_line {
435  
436 597 ▶ my ($self, $source_fn, $target_fn, $line)=@_;
Subroutine rewrite_link_line: called CC=3 SCAR=11.0
Pod undocumented
437 597 my ($output, $offset)=('', 0);
438 597 while (1) {
439 614 pos($line)=$offset;
440 614 ▶ last unless $line=~/(`+)/g;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /(`+)/g 597 17 614
441 17 my ($marker, $start, $after)=($1, $-[0], $+[0]);
442 17 my $end=index($line, $marker, $after);
443 17 ▶ last if $end < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $end < 0 0 17 17
444 17 $output.=$self->rewrite_link_segment($source_fn, $target_fn,
445 substr($line, $offset, $start - $offset));
446 17 my $length=$end + length($marker) - $start;
447 17 $output.=substr($line, $start, $length);
448 17 $offset=$start + $length;
449 }
450 597 $output.=$self->rewrite_link_segment($source_fn, $target_fn,
451 substr($line, $offset));
452 597 return $output;
453  
454 }
455  
456  
457 sub rewrite_source_links {
458  
459 # Source-relative links remain useful while browsing the repository. Rebase
460 # only mirrored lib/bin Markdown targets for the disposable document tree.
461 #
462 75 ▶ my ($self, $source_fn, $target_fn, $markdown)=@_;
Subroutine rewrite_source_links: called CC=7 SCAR=19.5
Pod undocumented
463 75 my ($output, $fence, $length)=('', '', 0);
464 75 foreach my $line (split(/(?<=\n)/, $markdown)) {
465 713 ▶ if (!$fence && $line=~/^ {0,3}(`{3,}|~{3,})/) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $fence and $line =~ /^ {0,3}(`{3,}|~{3,})/) { } 30 683 713
elsif ($fence and $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/) { } 30 653 683
elsif (not $fence) { } 597 56 653
Condition100%3/3
not $fence and $line =~ /^ {0,3}(`{3,}|~{3,})/
!ll&&!rl&&r
8659730
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
466 30 $fence=substr($1, 0, 1);
467 30 $length=length($1);
468 }
469 ▶ 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
5975630
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
470 30 $fence='';
471 }
472 elsif (!$fence) {
473 597 $line=$self->rewrite_link_line($source_fn, $target_fn, $line);
474 }
475 713 $output.=$line;
476 }
477 75 return $output;
478  
479 }
480  
481  
482 sub promote_home {
483  
484 # Keep the first page's original path available for authored links.
485 # Only a top-level page can be copied to index without rebasing its links.
486 #
487 19 ▶ my ($self, $docs_dn, $pages_ar)=@_;
Subroutine promote_home: called CC=5 SCAR=16.2
Pod undocumented
488 19 ▶ return unless @{$pages_ar};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$pages_ar;} 0 19 19
489 19 my $has_index=grep {$_ eq 'index.md'} @{$pages_ar};
490 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
491 18 my $first_fn=File::Spec->catfile($docs_dn, $pages_ar->[0]);
492 18 my $index_fn=File::Spec->catfile($docs_dn, 'index.md');
493 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
494 18 $pages_ar->[0]='index.md';
495 18 return 1;
496  
497 }
498  
499  
500 sub prepare_docs {
501  
502  
503 # Assemble the configured source roots and mirror lib/bin Markdown when
504 # doc is selected. Nested documents remain linkable but outside generated
505 # navigation.
506 #
507 22 ▶ my ($self)=@_;
Subroutine prepare_docs: called CC=8 SCAR=20.8
Pod documented
508 22 my $temporary_dn=abs_path(tempdir(CLEANUP => 1));
509 22 my $docs_dn=File::Spec->catdir($temporary_dn, 'docs');
510 22 make_path($docs_dn);
511 22 my @pages;
512 22 my $source_dn_ar=$self->source_directories();
513  
514 22 foreach my $source_dn (@{$source_dn_ar}) {
515 24 ▶ die "publication source directory not found: $source_dn\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $source_dn 0 24 24
516 unless -d $source_dn;
517 File::Find::find({
518 no_chdir => 1,
519 46 ▶ preprocess => sub {sort @_},
Subroutine __ANON__: called CC=1 SCAR=0.0
520 wanted => sub {
521 144 ▶ my $fn=$File::Find::name;
Subroutine __ANON__: called CC=17 SCAR=28.5
522 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
523 21 $File::Find::prune=1;
524 21 return;
525 }
526 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
527 77 my $target_fn=$self->target_filename($source_dn, $fn);
528 77 my $output_fn=File::Spec->catfile($docs_dn, $target_fn);
529 77 my (undef, $parent_dn)=File::Spec->splitpath($output_fn);
530 77 make_path($parent_dn);
531 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
532 $target_fn!~m{[/\\]};
533  
534 77 ▶ if ($source_dn eq 'doc') {
Branch: 1 branch
BranchTrueFalseTotal
if ($source_dn eq "doc") 75 2 77
535 75 ▶ 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" 75 0 75
536 75 local $/=undef;
537 75 my $markdown=<$input_fh>;
538 75 ▶ close($input_fh) || die "unable to close $fn: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $input_fh or die "unable to close ${fn}: $!\n" 75 0 75
539 75 $markdown=$self->rewrite_source_links($fn, $target_fn, $markdown);
540 75 ▶ if ($navigation_page) {
Branch: 1 branch
BranchTrueFalseTotal
if ($navigation_page) 55 20 75
541 55 my $split_hr=$self->split($target_fn, $markdown);
542 55 ▶ if (keys(%{$split_hr}) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$split_hr;} > 1) 17 38 55
543 17 foreach my $page (@{$self->{'page_order'}}) {
544 34 my $page_fn=File::Spec->catfile($docs_dn, $page);
545 34 $self->write_file($page_fn, $split_hr->{$page});
546 34 push(@pages, $page);
547 }
548 17 return;
549 }
550 }
551 58 $self->write_file($output_fn, $markdown);
552 58 ▶ push(@pages, $target_fn) if $navigation_page;
Branch: 1 branch
BranchTrueFalseTotal
if $navigation_page 38 20 58
553 58 return;
554 }
555 2 ▶ 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" 2 0 2
556 2 ▶ push(@pages, $target_fn) if $navigation_page;
Branch: 1 branch
BranchTrueFalseTotal
if $navigation_page 2 0 2
557 }
558 24 }, $source_dn);
559 }
560  
561 22 ▶ die "no Markdown documents discovered in publication sources\n" unless @pages;
Branch: 1 branch
BranchTrueFalseTotal
unless @pages 1 21 22
562 21 ▶ if (grep {$_ eq 'doc'} @{$source_dn_ar}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "doc";} @{$source_dn_ar;}) 21 0 21
563 21 $self->copy_markdown_tree('lib', $docs_dn);
564 21 $self->copy_markdown_tree('bin', $docs_dn);
565 }
566 # Keep a home page without placing its generated link list in navigation.
567 #
568 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
569 20 my $index="# Documentation\n\n";
570 20 $index.="- [$_]($_)\n" foreach @pages;
571 20 $self->write_file(File::Spec->catfile($docs_dn, 'index.md'), $index);
572 }
573  
574 21 foreach my $source_dn (@{$source_dn_ar}) {
575 23 $self->copy_tree(File::Spec->catdir($source_dn, 'images'),
576 File::Spec->catdir($docs_dn, 'images'));
577 23 $self->copy_tree(File::Spec->catdir($source_dn, 'assets'),
578 File::Spec->catdir($docs_dn, 'assets'));
579 }
580 21 return ($temporary_dn, $docs_dn, \@pages);
581  
582 }
583  
584  
585 sub split {
586  
587 57 ▶ my ($self, $fn, $markdown)=@_;
Subroutine split: called CC=25 SCAR=32.3
Pod documented
588 57 (my $stem=$fn)=~s/\.md$//;
589 57 my (%pages, %anchor, %chapter_anchor, @order);
590 57 my ($page, $fence, $length, $preamble)=('', '', 0, '');
591 57 foreach my $line (split(/(?<=\n)/, $markdown)) {
592 587 ▶ if (!$fence && $line=~/^ {0,3}(`{3,}|~{3,})/) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $fence and $line =~ /^ {0,3}(`{3,}|~{3,})/) { } 31 556 587
elsif ($fence and $line =~ /^ {0,3}\Q$fence\E{$length,}\s*$/) { } 31 525 556
elsif (not $fence and $line =~ /^#\s+(.+?)\s*$/) { } 76 507 583
Condition100%3/3
not $fence and $line =~ /^ {0,3}(`{3,}|~{3,})/
!ll&&!rl&&r
8946731
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
593 31 $fence=substr($1, 0, 1);
594 31 $length=length($1);
595 }
596 ▶ 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
4675831
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
597 31 $fence='';
598 }
599 ▶ elsif (!$fence && $line=~/^#\s+(.+?)\s*$/) {
Condition100%3/3
not $fence and $line =~ /^#\s+(.+?)\s*$/
!ll&&!rl&&r
5839176
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
600 76 my $title=$1;
601 76 my ($id)=$title=~/\{#([^}]+)\}/;
602 76 ▶ unless ($id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 15 61 76
603 15 $id=lc($title);
604 15 $id=~s/[^a-z0-9]+/-/g;
605 15 $id=~s/^-|-$//g;
606 }
607 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
608 unless $id && $id=~/^[\w.-]+$/;
609 76 $page="$stem--$id.md";
610 76 ▶ die "duplicate chapter ID $id in $fn\n" if exists($pages{$page});
Branch: 1 branch
BranchTrueFalseTotal
if exists $pages{$page} 1 75 76
611 75 $pages{$page}=$preamble;
612 75 $preamble='';
613 75 $chapter_anchor{$id}=1;
614 75 push(@order, $page);
615 }
616 586 ▶ $anchor{$1}=$page if !$fence && $line=~/\{#([^}]+)\}/ && $page;
Branch: 1 branch
BranchTrueFalseTotal
if not $fence and $line =~ /\{#([^}]+)\}/ and $page 60 526 586
Condition83%5/6
not $fence and $line =~ /\{#([^}]+)\}/ and $page
!ll&&!rl&&r
526060
not $fence and $line =~ /\{#([^}]+)\}/
!ll&&!rl&&r
8943760
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
617 586 ▶ if ($page) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page) { } 586 0 586
618 586 $pages{$page}.=$line;
619 }
620 else {
621 0 $preamble.=$line;
622 }
623 }
624  
625 56 foreach my $current_page (@order) {
626 74 my $text='';
627 74 my ($current_fence, $current_length)=('', 0);
628 74 foreach my $line (split(/(?<=\n)/, $pages{$current_page})) {
629 585 ▶ if (!$current_fence && $line=~/^ {0,3}(`{3,}|~{3,})/) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $current_fence and $line =~ /^ {0,3}(`{3,}|~{3,})/) { } 31 554 585
elsif ($current_fence and $line =~ /^ {0,3}\Q$current_fence\E{$current_length,}\s*$/) { } 31 523 554
elsif (not $current_fence) { } 465 58 523
Condition100%3/3
not $current_fence and $line =~ /^ {0,3}(`{3,}|~{3,})/
!ll&&!rl&&r
8946531
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
630 31 $current_fence=substr($1, 0, 1);
631 31 $current_length=length($1);
632 }
633 ▶ 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
4655831
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
634 31 $current_fence='';
635 }
636 elsif (!$current_fence) {
637 465 foreach my $id (keys(%anchor)) {
638 693 my (undef, undef, $target)=File::Spec->splitpath($anchor{$id});
639 693 ▶ my $link=$target.($chapter_anchor{$id} ? '' : "#$id");
Branch: 1 branch
BranchTrueFalseTotal
$chapter_anchor{$id} ? : 693 0 693
640 693 $line=~s{\]\(\#\Q$id\E\)}{]($link)}g;
641 }
642 }
643 585 $text.=$line;
644 }
645 74 $pages{$current_page}=$text;
646 }
647 56 $self->{'page_order'}=\@order;
648 56 return \%pages;
649  
650 }
651  
652  
653 sub normalize_node_admonitions {
654  
655 111 ▶ my ($self, $markdown)=@_;
Subroutine normalize_node_admonitions: called CC=5 SCAR=23.4
Pod undocumented
656 111 my @output;
657 111 my @line=split(/(?<=\n)/, $markdown);
658 111 ▶ for (my $index=0; $index<@line; $index++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < @line) 994 111 1105
659 994 ▶ if ($line[$index]=~/^!!!\s+(\w+).*?\n?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line[$index] =~ /^!!!\s+(\w+).*?\n?$/) 0 994 994
660 0 my $kind=$self->admonition_type($1);
661 0 push(@output, ":::$kind\n");
662 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
663 0 $index++;
664 0 my $admonition_line=$line[$index];
665 0 $admonition_line=~s/^ //;
666 0 push(@output, $admonition_line);
667 }
668 0 push(@output, ":::\n");
669 0 next;
670 }
671 994 push(@output, $line[$index]);
672 }
673 111 return join('', @output);
674  
675 }
676  
677  
678 sub admonition_type {
679  
680 0 ▶ my ($self, $kind)=@_;
Subroutine admonition_type: not called CC=1 SCAR=6.9
Pod undocumented
681 0 return $kind;
682  
683 }
684  
685  
686 sub normalize_node_definition_lists {
687  
688 111 ▶ my ($self, $markdown)=@_;
Subroutine normalize_node_definition_lists: called CC=12 SCAR=24.9
Pod undocumented
689 111 my @line=split(/(?<=\n)/, $markdown);
690 111 my @output;
691 111 my ($fence, $length)=('', 0);
692 111 ▶ for (my $index=0; $index<@line; $index++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < @line) 700 111 811
693 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
694 26 $fence=substr($1, 0, 1);
695 26 $length=length($1);
696 }
697 ▶ 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
698 26 $fence='';
699 }
700  
701 # Pandoc definition lists are not portable to the Node renderers.
702 # Their two-space continuation indent is also the content indent for
703 # the equivalent CommonMark list item, so the remaining block can be
704 # retained verbatim.
705 #
706 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
707 $line[$index + 1]=~/^\s*$/ && $line[$index + 2]=~/^:\s+(.*)$/) {
708 13 my $term=$line[$index];
709 13 my $description=$1;
710 13 ▶ my $newline=$line[$index + 2]=~/\n\z/ ? "\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
$line[$index + 2] =~ /\n\z/ ? : 13 0 13
711 13 $term=~s/\r?\n\z//;
712 13 $description=~s/\r?\n\z//;
713 13 push(@output, "- **$term**\n\n $description$newline");
714 13 $index+=2;
715 13 next;
716 }
717 687 push(@output, $line[$index]);
718 }
719 111 return join('', @output);
720  
721 }
722  
723  
724 sub normalize_node_attributes {
725  
726 111 ▶ my ($self, $markdown)=@_;
Subroutine normalize_node_attributes: called CC=13 SCAR=25.8
Pod undocumented
727 111 my @output;
728 111 my ($fence, $length)=('', 0);
729 111 foreach my $line (split(/(?<=\n)/, $markdown)) {
730 966 ▶ if ($fence) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fence) 78 888 966
731 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
732 26 $fence='';
733 }
734 78 push(@output, $line);
735 78 next;
736 }
737  
738 # Retain an authored code-block ID as an adjacent HTML anchor and
739 # pass its first class as the conventional fenced-code language.
740 #
741 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
742 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
743 13 my ($id)=$attributes=~/(?:^|\s)#([\w.-]+)/;
744 13 my ($language)=$attributes=~/(?:^|\s)\.([\w+-]+)/;
745 13 ▶ push(@output, "$indent<a id=\"$id\"></a>$newline") if defined($id);
Branch: 1 branch
BranchTrueFalseTotal
if defined $id 13 0 13
746 13 ▶ push(@output, $indent.$delimiter.(defined($language) ? $language : '').$newline);
Branch: 1 branch
BranchTrueFalseTotal
defined $language ? : 13 0 13
747 13 $fence=substr($delimiter, 0, 1);
748 13 $length=length($delimiter);
749 13 next;
750 }
751 875 ▶ if ($line=~/^ {0,3}(`{3,}|~{3,})/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^ {0,3}(`{3,}|~{3,})/) 13 862 875
752 13 $fence=substr($1, 0, 1);
753 13 $length=length($1);
754 13 push(@output, $line);
755 13 next;
756 }
757  
758 # Docusaurus and Starlight do not accept Pandoc heading attributes.
759 # A raw anchor preserves the stable identifiers used by split links.
760 #
761 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
762 $line=~/^( {0,3})(#{1,6}[^\r\n]*?)\s+\{#([\w.-]+)(?:\s+[^}]*)?\}[ \t]*(\r?\n)?$/) {
763 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
764 15 next;
765 }
766  
767 # Attribute blocks on inline links and images otherwise become
768 # visible text in one or more of the Node renderers.
769 #
770 847 $line=~s{((?:!)?\[[^\]]*\]\([^\)\r\n]+\))\{[^\}\r\n]+\}}{$1}g;
771 847 push(@output, $line);
772 }
773 111 return join('', @output);
774  
775 }
776  
777  
778 sub heading_anchor_required {
779  
780 288 ▶ return 0;
Subroutine heading_anchor_required: called CC=1 SCAR=0.0
Pod undocumented
781  
782 }
783  
784  
785  
786  
787 sub markdown_title {
788  
789 123 ▶ my ($self, $fn, $markdown)=@_;
Subroutine markdown_title: called CC=19 SCAR=40.4
Pod undocumented
790 123 my $title;
791  
792 # Prefer authored frontmatter, accepting the simple quoted and unquoted
793 # title forms used by the supported documentation engines.
794 #
795 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
796 1 my $frontmatter=$1;
797 1 ($title)=$frontmatter=~/^title:[ \t]*(.*?)[ \t]*\r?$/m;
798 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
799 1 my $decoded=eval {decode_json($title)};
800 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
801 }
802 ▶ 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
803 0 $title=$1;
804 0 $title=~s/''/'/g;
805 }
806 }
807  
808 # Otherwise use the first level-one heading outside a fenced example.
809 #
810 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
811 122 my ($fence, $length)=('', 0);
812 122 foreach my $line (split(/(?<=\n)/, $markdown)) {
813 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
814 0 $fence=substr($1, 0, 1);
815 0 $length=length($1);
816 }
817 ▶ 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
818 0 $fence='';
819 }
820 ▶ 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
821 122 $title=$1;
822 122 $title=~s/\s+\{#[^}]+\}\s*$//;
823 122 $title=~s/[ \t]+#+[ \t]*$//;
824 122 last;
825 }
826 }
827 }
828  
829 # A filename-derived label is a last resort for headingless documents.
830 #
831 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
832 0 (undef, undef, $title)=File::Spec->splitpath($fn);
833 0 $title=~s/\.md$//;
834 0 $title=~s/[-_]+/ /g;
835 0 $title=join(' ', map {ucfirst($_)} split(/\s+/, $title));
836 }
837 123 $title=~s/\s+\{#[^}]+\}\s*$//;
838 123 return $title;
839  
840 }
841  
842  
843 sub title_frontmatter {
844  
845 60 ▶ my ($self, $fn, $markdown)=@_;
Subroutine title_frontmatter: called CC=3 SCAR=16.3
Pod undocumented
846 60 my $title=$self->markdown_title($fn, $markdown);
847 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
848 0 my $frontmatter=$1;
849 0 ▶ return $markdown if $frontmatter=~/^title:[ \t]*/m;
Branch: 1 branch
BranchTrueFalseTotal
if $frontmatter =~ /^title:[ \t]*/m 0 0 0
850 0 my $title_line='title: '.encode_json($title)."\n";
851 0 $markdown=~s/\A(---[ \t]*\r?\n)/$1$title_line/;
852 0 return $markdown;
853 }
854 60 return "---\ntitle: ".encode_json($title)."\n---\n\n$markdown";
855  
856 }
857  
858  
859 sub navigation {
860  
861 13 ▶ my ($self, $docs_dn, $pages_ar)=@_;
Subroutine navigation: called CC=4 SCAR=13.9
Pod undocumented
862 13 my @navigation;
863 13 foreach my $page (@{$pages_ar}) {
864 59 my $fn=File::Spec->catfile($docs_dn, $page);
865 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
866 59 local $/=undef;
867 59 my $markdown=<$input_fh>;
868 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
869 59 (my $id=$page)=~s/\.md$//;
870 59 $id=~s{\\}{/}g;
871 59 push(@navigation, {
872 file => $page,
873 id => $id,
874 title => $self->markdown_title($page, $markdown)
875 });
876 }
877 13 return \@navigation;
878  
879 }
880  
881  
882 sub normalize_node_markdown {
883  
884 13 ▶ my ($self, $source_dn)=@_;
Subroutine normalize_node_markdown: called CC=1 SCAR=0.0
Pod undocumented
885 File::Find::find({
886 no_chdir => 1,
887 wanted => sub {
888 189 ▶ my $fn=$File::Find::name;
Subroutine __ANON__: called CC=5 SCAR=16.3
889 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
890 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
891 111 local $/=undef;
892 111 my $markdown=<$input_fh>;
893 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
894 111 $markdown=$self->normalize_node_definition_lists($markdown);
895 111 $markdown=$self->normalize_backend_markdown($fn, $markdown);
896 111 $markdown=$self->normalize_node_attributes($markdown);
897 111 $markdown=$self->normalize_node_admonitions($markdown);
898 111 $self->write_file($fn, $markdown);
899 }
900 13 }, $source_dn);
901 13 return 1;
902  
903 }
904  
905  
906 sub normalize_backend_markdown {
907  
908 51 ▶ my ($self, $fn, $markdown)=@_;
Subroutine normalize_backend_markdown: called CC=1 SCAR=0.0
Pod undocumented
909 51 return $markdown;
910  
911 }
912  
913  
914 sub npm_install {
915  
916 2 ▶ my ($self, $site_dn)=@_;
Subroutine npm_install: called CC=3 SCAR=11.0
Pod undocumented
917 2 my $npm=$self->option('npm', 'npm');
918 2 my $engine=ref($self);
919 2 $engine=~s/^.*:://;
920 2 print STDERR "Installing $engine npm dependencies...\n";
921 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
922 $MARKDOWN_PUBLISH_NPM_VERBOSE eq '1' ? () : ('--silent');
923 2 $self->system_in_dir($site_dn, $npm, 'install', @quiet);
924 2 print STDERR "$engine npm dependencies installed.\n";
925 2 return 1;
926  
927 }
928  
929  
930 sub build {
931  
932 0 ▶ die "publication backend must implement build()\n";
Subroutine build: not called CC=1 SCAR=6.9
Pod undocumented
933  
934 }
935  
936  
937 sub serve {
938  
939 0 ▶ die "publication backend must implement serve()\n";
Subroutine serve: not called CC=1 SCAR=6.9
Pod undocumented
940  
941 }
942  
943  
944 sub publish_gh {
945  
946  
947 # Build first, then replace only the disposable publication worktree.
948 # Leave the resulting branch local so pushing remains an explicit Git
949 # operation controlled by the repository's configured upstream.
950 #
951 0 ▶ my ($self)=@_;
Subroutine publish_gh: not called CC=7 SCAR=40.3
Pod documented
952 0 my $branch=$self->option('branch', $MARKDOWN_PUBLISH_BRANCH);
953 0 my $base=$self->github_site_base();
954 0 local $self->{'base'}=$base;
955 0 my $site_dn=$self->build();
956 0 $self->command('git', 'check-ref-format', '--branch', $branch);
957 0 my $temporary_dn=abs_path(tempdir(CLEANUP => 1));
958 0 my $work_dn=File::Spec->catdir($temporary_dn, 'pages');
959 0 my $exists=eval {
960 0 $self->command('git', 'rev-parse', '--verify', "refs/heads/$branch");
961 0 1;
962 };
963 0 ▶ $self->command('git', 'worktree', 'add', ($exists ? () : '--detach'), $work_dn,
Branch: 2 branches
BranchTrueFalseTotal
$exists ? : 0 0 0
$exists ? : 0 0 0
964 $exists ? $branch : 'HEAD');
965 0 my $ok=eval {
966 0 ▶ $self->command('git', '-C', $work_dn, 'checkout', '--orphan', $branch)
Branch: 1 branch
BranchTrueFalseTotal
unless $exists 0 0 0
967 unless $exists;
968 0 $self->command('git', '-C', $work_dn, 'rm', '-r', '-f', '--ignore-unmatch', '.');
969 0 $self->copy_tree($site_dn, $work_dn);
970 0 $self->write_file(File::Spec->catfile($work_dn, '.nojekyll'), '');
971 0 $self->command('git', '-C', $work_dn, 'add', '.');
972 0 ▶ my $changed=$exists ?
Branch: 1 branch
BranchTrueFalseTotal
$exists ? : 0 0 0
973 length($self->command('git', '-C', $work_dn, 'diff', '--cached', '--name-only')) : 1;
974 0 ▶ $self->command('git', '-C', $work_dn, 'commit', '-m', 'Update documentation')
Branch: 1 branch
BranchTrueFalseTotal
if $changed 0 0 0
975 if $changed;
976 0 1;
977 };
978 0 my $error=$@;
979 0 $self->command('git', 'worktree', 'remove', '--force', $work_dn);
980 0 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
981 0 return $branch;
982  
983 }
984  
985  
986 sub publish_gh_push {
987  
988  
989 # Keep local branch creation in publish_gh(), then make the remote side
990 # effect explicit by pushing only the resulting branch to origin.
991 #
992 1 ▶ my ($self)=@_;
Subroutine publish_gh_push: called CC=1 SCAR=0.0
Pod documented
993 1 my $branch=$self->publish_gh();
994 1 $self->command('git', 'push', 'origin', $branch);
995 1 return $branch;
996  
997 }
998  
999  
1000 sub publish_cloudflare {
1001  
1002  
1003 # The site generator owns the build; Wrangler deploys only the resulting
1004 # static assets using an explicit or conventional root configuration.
1005 #
1006 7 ▶ my ($self)=@_;
Subroutine publish_cloudflare: called CC=14 SCAR=26.5
Pod documented
1007 7 ▶ my $cloudflare_hr=exists($self->{'cloudflare'}) ? $self->{'cloudflare'} : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'cloudflare'} ? : 4 3 7
1008 7 ▶ die "cloudflare publication configuration must be a hash reference\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cloudflare_hr eq "HASH" 1 6 7
1009 unless ref($cloudflare_hr) eq 'HASH';
1010 6 my $config_fn;
1011 6 ▶ if (exists($cloudflare_hr->{'config'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cloudflare_hr->{'config'}) { } 3 3 6
1012 3 $config_fn=$cloudflare_hr->{'config'};
1013 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
1014 unless defined($config_fn) && length($config_fn);
1015 }
1016 else {
1017 3 foreach my $candidate_fn (qw(wrangler.jsonc wrangler.json)) {
1018 5 ▶ if (-f $candidate_fn) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $candidate_fn) 2 3 5
1019 2 $config_fn=$candidate_fn;
1020 2 last;
1021 }
1022 }
1023 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
1024 unless defined($config_fn);
1025 }
1026 5 ▶ die "Wrangler configuration not found: $config_fn\n" unless -f $config_fn;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $config_fn 1 4 5
1027 4 $config_fn=abs_path($config_fn);
1028 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
1029  
1030 4 my $site_dn=$self->build();
1031 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
1032 3 $site_dn=abs_path($site_dn);
1033 3 my @command=($wrangler, 'deploy', '--config', $config_fn,
1034 '--assets', $site_dn);
1035 push(@command, '--env', $cloudflare_hr->{'environment'})
1036 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
1037 3 $self->system_command(@command);
1038 3 return $site_dn;
1039  
1040 }
1041  
1042  
1043 __END__
« Publish/MkDocs.pm ↑ Summary Publish/Starlight.pm »