lib/Markdown/Publish/MkDocs.pm

filter: Statementstmt 86.8% 66 / 76 Branchbran 73.3% 22 / 30 Conditioncond 76.6% 23 / 30 MC/DCmcdc 47.0% 8 / 17 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 3 totaltotal 77.2% 129 / 167 CC 27 SCAR 25.8
CC
27
Cov
82%
prepare
21.3
serve
8.0
build
6.0
CRAP 13.2
« lib/Markdown/Publish.pm ↑ Summary blib/lib/Markdown/Publish/Docusaurus.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.003';
36  
37  
38 # Done
39 #
40 2 1;
41  
42  
43 #======================================================================================================================
44  
45  
46 7 ▶sub prepare {
Subroutine prepare: called CC=19 SCAR=30.6
Pod undocumented
47  
48 7 my ($self, $preview)=@_;
49 7 my ($config_fn, $extend_fn)=$self->configuration_files();
50 7 ▶ die "config_extend cannot be used with direct MkDocs configuration\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $extend_fn and $self->option("config_mode", "") eq "direct" 1 6 7
Condition100%3/3
defined $extend_fn and $self->option("config_mode", "") eq "direct"
!ll&&!rl&&r
511
MC/DC100%2/2
defined $extend_fn and $self->option("config_mode", "") eq "direct"
defined $extend_fn $self->option("config_mode", "") eq "direct"
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 6 ▶ $config_fn='mkdocs.yml'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $config_fn || defined $extend_fn and -f "mkdocs.yml" 0 6 6
Condition83%5/6
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"
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 6 ▶ if (defined($config_fn) && length($config_fn) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config_fn and length $config_fn and $self->option("config_mode", "") eq "direct" || $config_fn eq "mkdocs.yml") 0 6 6
Condition55%5/9
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"
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: 1 branch
BranchTrueFalseTotal
unless -f $config_fn 0 0 0
57 0 return abs_path($config_fn);
58 }
59 6 ▶ $config_fn=$extend_fn if defined($extend_fn);
Branch: 1 branch
BranchTrueFalseTotal
if defined $extend_fn 1 5 6
60 6 ▶ $config_fn='doc/mkdocs/mkdocs.yml'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $config_fn and -f "doc/mkdocs/mkdocs.yml" 1 5 6
Condition100%3/3
not defined $config_fn and -f "doc/mkdocs/mkdocs.yml"
!ll&&!rl&&r
231
MC/DC100%2/2
not defined $config_fn and -f "doc/mkdocs/mkdocs.yml"
not defined $config_fn -f "doc/mkdocs/mkdocs.yml"
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 6 my ($temporary_dn, $docs_dn, $pages_ar)=$self->prepare_docs();
64 6 $self->promote_home($docs_dn, $pages_ar);
65 6 my $generated_fn=File::Spec->catfile($temporary_dn, 'mkdocs.yml');
66 6 my $output_dn=File::Spec->rel2abs($self->option('output', $MARKDOWN_PUBLISH_OUTPUT_DN));
67 6 my $config='';
68 6 ▶ if (defined($config_fn) && length($config_fn)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config_fn and length $config_fn) { } 3 3 6
Condition66%2/3
defined $config_fn and length $config_fn
!ll&&!rl&&r
303
MC/DC50%1/2
defined $config_fn and length $config_fn
defined $config_fn length $config_fn
Truth table66%2/3
A and B
A= defined $config_fnB= length $config_fn
ABresult
0X0
100
111
69 3 ▶ die "MkDocs configuration not found: $config_fn\n" unless -f $config_fn;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $config_fn 0 3 3
70 3 $config.='INHERIT: '.encode_json(abs_path($config_fn))."\n";
71 }
72 else {
73 3 $config.='site_name: '.encode_json($self->option('name', 'Documentation'))."\n";
74 3 $config.="theme:\n name: material\n";
75 3 $config.="markdown_extensions:\n - admonition\n - attr_list\n - def_list\n - footnotes\n - tables\n - pymdownx.superfences\n";
76 }
77 6 $config.='docs_dir: '.encode_json(abs_path($docs_dn))."\n";
78 6 $config.='site_dir: '.encode_json($output_dn)."\n";
79 6 ▶ $config.="plugins:\n - search\n" if $preview;
Branch: 1 branch
BranchTrueFalseTotal
if $preview 2 4 6
80 6 $config.="nav:\n";
81 6 $config.=' - '.encode_json($_)."\n" foreach @{$pages_ar};
82 6 $self->write_file($generated_fn, $config);
83 6 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)=@_;
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: 1 branch
BranchTrueFalseTotal
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=20.8
Pod undocumented
103  
104 5 my ($self)=@_;
105 5 my $config_fn=$self->prepare(1);
106 5 my @command=($self->option('command', 'mkdocs'), 'serve', '-f', $config_fn);
107 5 my $address=$self->option('address', undef);
108 5 ▶ unless (exists($self->{'address'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"address"}) 3 2 5
109 3 my $host=$self->option('host', $MARKDOWN_PUBLISH_HOST);
110 3 my $port=$self->option('port', $MARKDOWN_PUBLISH_PORT);
111 3 ▶ if (defined($host) || defined($port)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $host or defined $port) 2 1 3
Condition100%3/3
defined $host or defined $port
l!l&&r!l&&!r
111
MC/DC100%2/2
defined $host or defined $port
defined $host defined $port
Truth table100%3/3
A or B
A= defined $hostB= defined $port
ABresult
1X1
011
000
112 2 ▶ $host='127.0.0.1' unless defined($host);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 1 1 2
113 2 ▶ $port=8000 unless defined($port);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port 0 2 2
114 2 $address="$host:$port";
115 }
116 }
117 5 ▶ push(@command, '-a', $address) if defined($address) && length($address);
Branch: 1 branch
BranchTrueFalseTotal
if defined $address and length $address 4 1 5
Condition66%2/3
defined $address and length $address
!ll&&!rl&&r
104
MC/DC50%1/2
defined $address and length $address
defined $address length $address
Truth table66%2/3
A and B
A= defined $addressB= length $address
ABresult
0X0
100
111
118 5 return $self->system_command(@command);
119  
120 }
121 __END__
« lib/Markdown/Publish.pm ↑ Summary blib/lib/Markdown/Publish/Docusaurus.pm »