Publish/MkDocs.pm

filter: Statementstmt 52.8% 66 / 125 Branchbran 36.6% 22 / 60 Conditioncond 38.3% 23 / 60 MC/DCmcdc 23.5% 8 / 34 Subroutinesub 71.4% 10 / 14 Podpod 0.0% 0 / 6 totaltotal 43.1% 129 / 299 CC 53 SCAR 40.8
CC
53
Cov
45%
prepare
94.2
prepare
94.2
serve
17.8
CRAP 59.0
↑ Summary Publish.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::MkDocs;
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 @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 # Parent and supporting packages
24 #
25 2 ▶use Markdown::Publish ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use Markdown::Publish::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use Cwd qw(abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use JSON::PP qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31  
32 # Inheritance and version information
33 #
34 2 @ISA=qw(Markdown::Publish);
35 2 $VERSION='1.004';
36  
37  
38 # Done
39 #
40 2 1;
41  
42  
43 #======================================================================================================================
44  
45  
46 7 ▶sub prepare {
Subroutine prepare: called CC=19 SCAR=45.5
Pod undocumented
47  
48 0 ▶ my ($self, $preview)=@_;
Subroutine prepare: not called CC=19 SCAR=45.5
Pod undocumented
49 0 my ($config_fn, $extend_fn)=$self->configuration_files();
50 0 ▶ die "config_extend cannot be used with direct MkDocs configuration\n"
Branch: 2 branches
BranchTrueFalseTotal
if defined $extend_fn and $self->option("config_mode", "") eq "direct" 0 0 0
if defined $extend_fn and $self->option("config_mode", "") eq "direct" 1 6 7
Condition50%3/6
defined $extend_fn and $self->option("config_mode", "") eq "direct"
!ll&&!rl&&r
000
defined $extend_fn and $self->option("config_mode", "") eq "direct"
!ll&&!rl&&r
511
MC/DC0%0/2
defined $extend_fn and $self->option("config_mode", "") eq "direct"
defined $extend_fn $self->option("config_mode", "") eq "direct"
MC/DC100%2/2
defined $extend_fn and $self->option("config_mode", "") eq "direct"
defined $extend_fn $self->option("config_mode", "") eq "direct"
Truth table0%0/3
A and B
A= defined $extend_fnB= $self->option("config_mode", "") eq "direct"
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= defined $extend_fnB= $self->option("config_mode", "") eq "direct"
ABresult
0X0
100
111
51 if defined($extend_fn) && $self->option('config_mode', '') eq 'direct';
52 0 ▶ $config_fn='mkdocs.yml'
Branch: 2 branches
BranchTrueFalseTotal
if not defined $config_fn || defined $extend_fn and -f "mkdocs.yml" 0 0 0
if not defined $config_fn || defined $extend_fn and -f "mkdocs.yml" 0 6 6
Condition41%5/12
not defined $config_fn || defined $extend_fn and -f "mkdocs.yml"
!ll&&!rl&&r
000
defined $config_fn || defined $extend_fn
l!l&&r!l&&!r
000
not defined $config_fn || defined $extend_fn and -f "mkdocs.yml"
!ll&&!rl&&r
240
defined $config_fn || defined $extend_fn
l!l&&r!l&&!r
114
MC/DC0%0/3
not defined $config_fn || defined $extend_fn and -f "mkdocs.yml"
defined $config_fn defined $extend_fn -f "mkdocs.yml"
MC/DC0%0/3
not defined $config_fn || defined $extend_fn and -f "mkdocs.yml"
defined $config_fn defined $extend_fn -f "mkdocs.yml"
Truth table0%0/4
not(A || B) and C
A= defined $config_fnB= defined $extend_fnC= -f "mkdocs.yml"
ABCresult
1XX0
01X0
0000
0011
Truth table75%3/4
not(A || B) and C
A= defined $config_fnB= defined $extend_fnC= -f "mkdocs.yml"
ABCresult
1XX0
01X0
0000
0011
53 if !defined($config_fn) && !defined($extend_fn) && -f 'mkdocs.yml';
54 0 ▶ if (defined($config_fn) && length($config_fn) &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $config_fn and length $config_fn and $self->option("config_mode", "") eq "direct" || $config_fn eq "mkdocs.yml") 0 0 0
if (defined $config_fn and length $config_fn and $self->option("config_mode", "") eq "direct" || $config_fn eq "mkdocs.yml") 0 6 6
Condition27%5/18
defined $config_fn and length $config_fn and $self->option("config_mode", "") eq "direct" || $config_fn eq "mkdocs.yml"
!ll&&!rl&&r
000
defined $config_fn and length $config_fn
!ll&&!rl&&r
000
$self->option("config_mode", "") eq "direct" or $config_fn eq "mkdocs.yml"
l!l&&r!l&&!r
000
defined $config_fn and length $config_fn and $self->option("config_mode", "") eq "direct" || $config_fn eq "mkdocs.yml"
!ll&&!rl&&r
510
defined $config_fn and length $config_fn
!ll&&!rl&&r
501
$self->option("config_mode", "") eq "direct" or $config_fn eq "mkdocs.yml"
l!l&&r!l&&!r
001
MC/DC0%0/4
defined $config_fn and length $config_fn and $self->option("config_mode", "") eq "direct" || $config_fn eq "mkdocs.yml"
defined $config_fn length $config_fn $self->option("config_mode", "") eq "direct" $config_fn eq "mkdocs.yml"
MC/DC0%0/4
defined $config_fn and length $config_fn and $self->option("config_mode", "") eq "direct" || $config_fn eq "mkdocs.yml"
defined $config_fn length $config_fn $self->option("config_mode", "") eq "direct" $config_fn eq "mkdocs.yml"
Truth table0%0/5
A and B and C or D
A= defined $config_fnB= length $config_fnC= $self->option("config_mode", "") eq "direct"D= $config_fn eq "mkdocs.yml"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
Truth table40%2/5
A and B and C or D
A= defined $config_fnB= length $config_fnC= $self->option("config_mode", "") eq "direct"D= $config_fn eq "mkdocs.yml"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
55 ($self->option('config_mode', '') eq 'direct' || $config_fn eq 'mkdocs.yml')) {
56 0 ▶ die "MkDocs configuration not found: $config_fn\n" unless -f $config_fn;
Branch: 2 branches
BranchTrueFalseTotal
unless -f $config_fn 0 0 0
unless -f $config_fn 0 0 0
57 0 return abs_path($config_fn);
58 }
59 0 ▶ $config_fn=$extend_fn if defined($extend_fn);
Branch: 2 branches
BranchTrueFalseTotal
if defined $extend_fn 0 0 0
if defined $extend_fn 1 5 6
60 0 ▶ $config_fn='doc/mkdocs/mkdocs.yml'
Branch: 2 branches
BranchTrueFalseTotal
if not defined $config_fn and -f "doc/mkdocs/mkdocs.yml" 0 0 0
if not defined $config_fn and -f "doc/mkdocs/mkdocs.yml" 1 5 6
Condition50%3/6
not defined $config_fn and -f "doc/mkdocs/mkdocs.yml"
!ll&&!rl&&r
000
not defined $config_fn and -f "doc/mkdocs/mkdocs.yml"
!ll&&!rl&&r
231
MC/DC0%0/2
not defined $config_fn and -f "doc/mkdocs/mkdocs.yml"
not defined $config_fn -f "doc/mkdocs/mkdocs.yml"
MC/DC100%2/2
not defined $config_fn and -f "doc/mkdocs/mkdocs.yml"
not defined $config_fn -f "doc/mkdocs/mkdocs.yml"
Truth table0%0/3
not(A) and B
A= not defined $config_fnB= -f "doc/mkdocs/mkdocs.yml"
ABresult
0X0
100
111
Truth table100%3/3
not(A) and B
A= not defined $config_fnB= -f "doc/mkdocs/mkdocs.yml"
ABresult
0X0
100
111
61 if !defined($config_fn) && -f 'doc/mkdocs/mkdocs.yml';
62  
63 0 my ($temporary_dn, $docs_dn, $pages_ar)=$self->prepare_docs();
64 0 $self->promote_home($docs_dn, $pages_ar);
65 0 my $generated_fn=File::Spec->catfile($temporary_dn, 'mkdocs.yml');
66 0 my $output_dn=File::Spec->rel2abs($self->option('output', $MARKDOWN_PUBLISH_OUTPUT_DN));
67 0 my $config='';
68 0 ▶ if (defined($config_fn) && length($config_fn)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $config_fn and length $config_fn) { } 0 0 0
if (defined $config_fn and length $config_fn) { } 3 3 6
Condition33%2/6
defined $config_fn and length $config_fn
!ll&&!rl&&r
000
defined $config_fn and length $config_fn
!ll&&!rl&&r
303
MC/DC0%0/2
defined $config_fn and length $config_fn
defined $config_fn length $config_fn
MC/DC50%1/2
defined $config_fn and length $config_fn
defined $config_fn length $config_fn
Truth table0%0/3
A and B
A= defined $config_fnB= length $config_fn
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= defined $config_fnB= length $config_fn
ABresult
0X0
100
111
69 0 ▶ die "MkDocs configuration not found: $config_fn\n" unless -f $config_fn;
Branch: 2 branches
BranchTrueFalseTotal
unless -f $config_fn 0 0 0
unless -f $config_fn 0 3 3
70 0 $config.='INHERIT: '.encode_json(abs_path($config_fn))."\n";
71 }
72 else {
73 0 $config.='site_name: '.encode_json($self->option('name', 'Documentation'))."\n";
74 0 $config.="theme:\n name: material\n";
75 0 $config.="markdown_extensions:\n - admonition\n - attr_list\n - def_list\n - footnotes\n - tables\n - pymdownx.superfences\n";
76 }
77 0 $config.='docs_dir: '.encode_json(abs_path($docs_dn))."\n";
78 0 $config.='site_dir: '.encode_json($output_dn)."\n";
79 0 ▶ $config.="plugins:\n - search\n" if $preview;
Branch: 2 branches
BranchTrueFalseTotal
if $preview 0 0 0
if $preview 2 4 6
80 0 $config.="nav:\n";
81 0 $config.=' - '.encode_json($_)."\n" foreach @{$pages_ar};
82 0 $self->write_file($generated_fn, $config);
83 0 return $generated_fn;
84  
85 }
86  
87  
88 0 ▶sub build {
Subroutine build: not called CC=2 SCAR=17.9
Pod undocumented
89  
90 0 ▶ my ($self)=@_;
Subroutine build: not called CC=2 SCAR=17.9
Pod undocumented
91 0 my $output_dn=File::Spec->rel2abs($self->option('output', $MARKDOWN_PUBLISH_OUTPUT_DN));
92 0 my $config_fn=$self->prepare(0);
93 0 my @command=($self->option('command', 'mkdocs'), 'build');
94 0 ▶ push(@command, '--strict') if $self->option('strict', 1);
Branch: 2 branches
BranchTrueFalseTotal
if $self->option("strict", 1) 0 0 0
if $self->option("strict", 1) 0 0 0
95 0 push(@command, '-f', $config_fn, '--site-dir', $output_dn);
96 0 $self->command(@command);
97 0 return $output_dn;
98  
99 }
100  
101  
102 5 ▶sub serve {
Subroutine serve: called CC=8 SCAR=28.8
Pod undocumented
103  
104 0 ▶ my ($self)=@_;
Subroutine serve: not called CC=8 SCAR=28.8
Pod undocumented
105 0 my $config_fn=$self->prepare(1);
106 0 my @command=($self->option('command', 'mkdocs'), 'serve', '-f', $config_fn);
107 0 my $address=$self->option('address', undef);
108 0 ▶ unless (exists($self->{'address'})) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"address"}) 0 0 0
unless (exists $self->{"address"}) 3 2 5
109 0 my $host=$self->option('host', $MARKDOWN_PUBLISH_HOST);
110 0 my $port=$self->option('port', $MARKDOWN_PUBLISH_PORT);
111 0 ▶ if (defined($host) || defined($port)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $host or defined $port) 0 0 0
if (defined $host or defined $port) 2 1 3
Condition50%3/6
defined $host or defined $port
l!l&&r!l&&!r
000
defined $host or defined $port
l!l&&r!l&&!r
111
MC/DC0%0/2
defined $host or defined $port
defined $host defined $port
MC/DC100%2/2
defined $host or defined $port
defined $host defined $port
Truth table0%0/3
A or B
A= defined $hostB= defined $port
ABresult
1X1
011
000
Truth table100%3/3
A or B
A= defined $hostB= defined $port
ABresult
1X1
011
000
112 0 ▶ $host='127.0.0.1' unless defined($host);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $host 0 0 0
unless defined $host 1 1 2
113 0 ▶ $port=8000 unless defined($port);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $port 0 0 0
unless defined $port 0 2 2
114 0 $address="$host:$port";
115 }
116 }
117 0 ▶ push(@command, '-a', $address) if defined($address) && length($address);
Branch: 2 branches
BranchTrueFalseTotal
if defined $address and length $address 0 0 0
if defined $address and length $address 4 1 5
Condition33%2/6
defined $address and length $address
!ll&&!rl&&r
000
defined $address and length $address
!ll&&!rl&&r
104
MC/DC0%0/2
defined $address and length $address
defined $address length $address
MC/DC50%1/2
defined $address and length $address
defined $address length $address
Truth table0%0/3
A and B
A= defined $addressB= length $address
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= defined $addressB= length $address
ABresult
0X0
100
111
118 0 return $self->system_command(@command);
119  
120 }
121 __END__
↑ Summary Publish.pm »