lib/LaTeXML/Common/Config.pm

filter: Statementstmt 12.2% 52 / 424 Branchbran 0.3% 1 / 270 Conditioncond 1.2% 2 / 162 MC/DCmcdc 0.0% 0 / 89 Subroutinesub 19.3% 12 / 62 Podpod 52.6% 10 / 19 totaltotal 7.5% 77 / 1026 CC 203 SCAR 89.2
CC
203
Cov
6%
_prepare_options
15750.0
read
380.0
_obey_profile
210.0
CRAP 7511.4
« lib/LaTeXML/MathGrammar.pm ↑ Summary lib/LaTeXML/Post/MathML.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Common::Config | #
3 # | Configuration logic for LaTeXML | #
4 # |=====================================================================| #
5 # | Part of LaTeXML: | #
6 # | Public domain software, produced as part of work done by the | #
7 # | United States Government & not subject to copyright in the US. | #
8 # |---------------------------------------------------------------------| #
9 # | Bruce Miller <bruce.miller@nist.gov> | #
10 # | Deyan Ginev <deyan.ginev@nist.gov> #_# | #
11 # | http://dlmf.nist.gov/LaTeXML/ (o o) | #
12 # \=========================================================ooo==U==ooo=/ #
13 package LaTeXML::Common::Config;
14 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Getopt::Long qw(:config no_ignore_case);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use Pod::Find qw(pod_where);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use LaTeXML::Util::Pathname;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 our $PROFILES_DB = {}; # Class-wide, caches all profiles that get used while the server is alive
25 5 our $is_bibtex = qr/(^literal\:\s*\@)|(\.bib$)/;
26 5 our $is_archive = qr/(^literal\:PK)|(\.zip$)/;
27  
28 5 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 our @EXPORT = (qw(addMathFormat removeMathFormat maybeAddMathFormat));
30  
31 sub new {
32 0 ▶ my ($class, %opts) = @_;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
33 #TODO: How about defaults in the daemon server use case? Should we support those here?
34 # or are defaults always bad/confusing to allow?
35 0 ▶ %opts = () unless %opts;
Branch: 1 branch
BranchTrueFalseTotal
unless %opts 0 0 0
36 0 return bless { dirty => 1, opts => \%opts }, $class; }
37  
38 ###########################################
39 #### Command-line reader #####
40 ###########################################
41 sub getopt_specification {
42 5 ▶ my (%options) = @_;
Subroutine getopt_specification: called CC=7 SCAR=34.4
Pod undocumented
43 5 ▶ my $opts = $options{options} || {};
Condition50%1/2
$options{'options'} || {}
l!l
05
MC/DC0%0/1
$options{'options'} || {}
$options{'options'}
Truth table50%1/2
A
A= $options{'options'}
Aresult
11
00
44 my $spec = {
45 # Basics and Paths
46 "output=s" => \$$opts{destination},
47 "destination=s" => \$$opts{destination},
48 "log=s" => \$$opts{log},
49 5 "preload=s" => \@{ $$opts{preload} },
50 "preamble=s" => \$$opts{preamble},
51 "postamble=s" => \$$opts{postamble},
52 "base=s" => \$$opts{base},
53 5 "path=s" => \@{ $$opts{paths} },
54 0 ▶ "quiet" => sub { $$opts{verbosity}--; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 ▶ "verbose" => sub { $$opts{verbosity}++; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 "strict" => \$$opts{strict},
57 "includestyles" => \$$opts{includestyles},
58 "inputencoding=s" => \$$opts{inputencoding},
59 # Formats
60 0 ▶ "xml" => sub { $$opts{format} = 'xml'; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
61 0 ▶ "tex" => sub { $$opts{format} = 'tex'; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 0 ▶ "box" => sub { $$opts{format} = 'box'; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 0 ▶ "bibtex" => sub { $$opts{type} = 'BibTeX'; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 ▶ "noparse" => sub { $$opts{mathparse} = 'no'; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 "format=s" => \$$opts{format},
66 "parse=s" => \$$opts{mathparse},
67 # Profiles
68 "profile=s" => \$$opts{profile},
69 "cache_key=s" => \$$opts{cache_key},
70 "mode=s" => \$$opts{profile},
71 "source=s" => \$$opts{source},
72 # Output framing
73 0 ▶ "embed" => sub { $$opts{whatsout} = 'fragment'; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 "whatsin=s" => \$$opts{whatsin},
75 "whatsout=s" => \$$opts{whatsout},
76 # Daemon options
77 "autoflush=i" => \$$opts{input_limit},
78 "timeout=i" => \$$opts{timeout},
79 "expire=i" => \$$opts{expire},
80 "address=s" => \$$opts{address},
81 "port=i" => \$$opts{port},
82 # Post-processing
83 "post!" => \$$opts{post},
84 "validate!" => \$$opts{validate},
85 "omitdoctype!" => \$$opts{omitdoctype},
86 "numbersections!" => \$$opts{numbersections},
87 "timestamp=s" => \$$opts{timestamp},
88 # Various choices for math processing.
89 # Note: Could want OM embedded in mml annotation, too.
90 # In general, could(?) want multiple math reps within <Math>
91 # OR, multiple math reps combined with <mml:sematics>
92 # or, in fact, _other_ parallel means? (om?, omdoc? ...)
93 # So, need to separate multiple transformations from the combination.
94 # However, IF combining, then will need to support a id/ref mechanism.
95 "mathimagemagnification=f" => \$$opts{mathimagemag},
96 "linelength=i" => \$$opts{linelength},
97 "plane1!" => \$$opts{plane1},
98 "hackplane1!" => \$$opts{hackplane1},
99 0 ▶ "mathimages" => sub { addMathFormat($opts, 'images'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
100 0 ▶ "nomathimages" => sub { removeMathFormat($opts, 'images'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
101 0 ▶ "mathsvg" => sub { addMathFormat($opts, 'svg'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 0 ▶ "nomathsvg" => sub { removeMathFormat($opts, 'svg'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
103 0 ▶ "presentationmathml|pmml" => sub { addMathFormat($opts, 'pmml'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 0 ▶ "contentmathml|cmml" => sub { addMathFormat($opts, 'cmml'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
105 0 ▶ "openmath|om" => sub { addMathFormat($opts, 'om'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 0 ▶ "keepXMath|xmath" => sub { addMathFormat($opts, 'xmath'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
107 0 ▶ "nopresentationmathml|nopmml" => sub { removeMathFormat($opts, 'pmml'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
108 0 ▶ "nocontentmathml|nocmml" => sub { removeMathFormat($opts, 'cmml'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
109 0 ▶ "noopenmath|noom" => sub { removeMathFormat($opts, 'om'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 0 ▶ "nokeepXMath|noxmath" => sub { removeMathFormat($opts, 'xmath'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 0 ▶ "mathtex" => sub { addMathFormat($opts, 'mathtex'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 0 ▶ "nomathtex" => sub { removeMathFormat($opts, 'mathtex'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
113 "parallelmath!" => \$$opts{parallelmath},
114 # Some general XSLT/CSS/JavaScript options.
115 "stylesheet=s" => \$$opts{stylesheet},
116 5 "xsltparameter=s" => \@{ $$opts{xsltparameters} },
117 5 "css=s" => \@{ $$opts{css} },
118 "defaultresources!" => \$$opts{defaultresources},
119 5 "javascript=s" => \@{ $$opts{javascript} },
120 "icon=s" => \$$opts{icon},
121 # Options for broader document set processing
122 "split!" => \$$opts{split},
123 0 ▶ "splitat=s" => sub { $$opts{splitat} = $_[1];
Subroutine __ANON__: not called CC=2 SCAR=17.9
124 0 ▶ $$opts{split} = 1 unless defined $$opts{split}; },
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"split"} 0 0 0
125 0 ▶ "splitpath=s" => sub { $$opts{splitpath} = $_[1];
Subroutine __ANON__: not called CC=2 SCAR=17.9
126 0 ▶ $$opts{split} = 1 unless defined $$opts{split}; },
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"split"} 0 0 0
127 0 ▶ "splitnaming=s" => sub { $$opts{splitnaming} = $_[1];
Subroutine __ANON__: not called CC=2 SCAR=17.9
128 0 ▶ $$opts{split} = 1 unless defined $$opts{split}; },
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"split"} 0 0 0
129 "scan!" => \$$opts{scan},
130 "crossref!" => \$$opts{crossref},
131 "urlstyle=s" => \$$opts{urlstyle},
132 "navigationtoc=s" => \$$opts{navtoc},
133 "navtoc=s" => \$$opts{navtoc},
134 # Generating indices
135 "index!" => \$$opts{index},
136 "permutedindex!" => \$$opts{permutedindex},
137 "splitindex!" => \$$opts{splitindex},
138 # Generating Bibliographies
139 5 "bibliography=s" => \@{ $$opts{bibliographies} }, # TODO: Document
140 "splitbibliography!" => \$$opts{splitbibliography},
141 # Options for two phase processing
142 "prescan" => \$$opts{prescan},
143 "dbfile=s" => \$$opts{dbfile},
144 "sitedirectory=s" => \$$opts{sitedirectory},
145 "sourcedirectory=s" => \$$opts{sourcedirectory},
146 # For graphics: vaguely similar issues, but more limited.
147 # includegraphics images (eg. ps) can be converted to webimages (eg.png)
148 # picture/pstricks images can be converted to png or possibly svg.
149 "graphicimages!" => \$$opts{dographics},
150 5 "graphicsmap=s" => \@{ $$opts{graphicsmaps} },
151 "svg!" => \$$opts{svg},
152 "pictureimages!" => \$$opts{picimages},
153 # HELP
154 "comments!" => \$$opts{comments},
155 "VERSION!" => \$$opts{showversion},
156 5 "debug=s" => \@{ $$opts{debug} },
157 "documentid=s" => \$$opts{documentid},
158 "help" => \$$opts{help}
159 5 };
160 5 ▶ return ($spec, $opts) unless ($options{type} && ($options{type} eq 'keyvals'));
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"type"} and $options{"type"} eq "keyvals" 5 0 5
Condition33%1/3
$options{"type"} and $options{"type"} eq "keyvals"
!ll&&!rl&&r
500
MC/DC0%0/2
$options{"type"} and $options{"type"} eq "keyvals"
$options{"type"} $options{"type"} eq "keyvals"
Truth table33%1/3
A and B
A= $options{"type"}B= $options{"type"} eq "keyvals"
ABresult
0X0
100
111
161 # Representation use case:
162 0 ▶ my $keyvals = $options{keyvals} || [];
Condition0%0/2
$options{'keyvals'} || []
l!l
00
MC/DC0%0/1
$options{'keyvals'} || []
$options{'keyvals'}
Truth table0%0/2
A
A= $options{'keyvals'}
Aresult
11
00
163 0 my $rep_spec = {}; # Representation specification
164 0 foreach my $key (keys %$spec) {
165 0 ▶ if ($key =~ /^(.+)=\w$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^(.+)=\w$/) { } 0 0 0
166 0 my $name = $1;
167 0 ▶ $$rep_spec{$key} = sub { CORE::push @$keyvals, [$name, $_[1]] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
168 } else {
169 $$rep_spec{$key} = sub {
170 0 ▶ my $ctl = $_[0]->{ctl};
Subroutine __ANON__: not called CC=2 SCAR=17.9
171 0 ▶ my $used = ($$ctl[0] ? 'no' : '') . $$ctl[1];
Branch: 1 branch
BranchTrueFalseTotal
$ctl->[0] ? : 0 0 0
172 0 CORE::push @$keyvals, [$used, undef] };
173 }
174 }
175 0 return ($rep_spec, $keyvals);
176 }
177 # TODO: Separate the keyvals scan from getopt_specification()
178 # into its own sub, using @GETOPT_KEYS entirely.
179 5 our @GETOPT_KEYS = keys %{ (getopt_specification())[0] };
180  
181 sub read {
182 0 ▶ my ($self, $argref, %read_options) = @_;
Subroutine read: not called CC=19 SCAR=59.4
Pod documented
183 0 my $opts = $$self{opts};
184 0 local @ARGV = @$argref;
185 0 my ($spec) = getopt_specification(options => $opts);
186 0 ▶ my $silent = %read_options && $read_options{silent};
Condition0%0/3
%read_options && $read_options{'silent'}
!ll&&!rl&&r
000
MC/DC0%0/2
%read_options && $read_options{'silent'}
%read_options $read_options{'silent'}
Truth table0%0/3
A && B
A= %read_optionsB= $read_options{'silent'}
ABresult
0X0
100
111
187 0 my $getOptions_success = GetOptions(%{$spec});
188 0 ▶ if (!$getOptions_success && !$silent) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($getOptions_success or $silent) 0 0 0
Condition0%0/3
$getOptions_success or $silent
l!l&&r!l&&!r
000
MC/DC0%0/2
$getOptions_success or $silent
$getOptions_success $silent
Truth table0%0/3
A or B
A= $getOptions_successB= $silent
ABresult
1X1
011
000
189 0 pod2usage(-message => $LaTeXML::IDENTITY, -exitval => 1, -verbose => 99,
190 -input => pod_where({ -inc => 1 }, __PACKAGE__),
191 -sections => 'OPTION SYNOPSIS', -output => \*STDERR);
192 }
193 0 ▶ if (!$silent && $$opts{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $silent and $opts->{"help"}) 0 0 0
Condition0%0/3
not $silent and $opts->{"help"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $silent and $opts->{"help"}
not $silent $opts->{"help"}
Truth table0%0/3
not(A) and B
A= not $silentB= $opts->{"help"}
ABresult
0X0
100
111
194 0 pod2usage(-message => $LaTeXML::IDENTITY, -exitval => 0, -verbose => 99,
195 -input => pod_where({ -inc => 1 }, __PACKAGE__),
196 -sections => 'OPTION SYNOPSIS', output => \*STDOUT);
197 }
198  
199 # Check that options for system I/O (destination and log) are valid before wasting any time...
200 0 foreach my $IO_option (qw(destination log)) {
201 0 ▶ if ($$opts{$IO_option}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{$IO_option}) 0 0 0
202 0 $$opts{$IO_option} = pathname_canonical($$opts{$IO_option});
203 0 ▶ if (my $dir = pathname_directory($$opts{$IO_option})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dir = pathname_directory($opts->{$IO_option})) 0 0 0
204 0 ▶ pathname_mkdir($dir) or croak "Couldn't create $IO_option directory $dir: $!"; } } }
Branch: 1 branch
BranchTrueFalseTotal
pathname_mkdir($dir) or croak("Couldn't create $IO_option directory ${dir}: $!") 0 0 0
205 # Removed math formats are irrelevant for conversion:
206 0 delete $$opts{removed_math_formats};
207  
208 0 ▶ if ($$opts{showversion}) { print STDERR "$LaTeXML::IDENTITY\n"; exit(0); }
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"showversion"}) 0 0 0
209  
210 0 ▶ $$opts{source} = $ARGV[0] unless $$opts{source};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"source"} 0 0 0
211 # Special source-based guessing needs to happen here,
212 # as we won't have access to the source file/literal/resource later on:
213 0 ▶ if (!$$opts{type} || ($$opts{type} eq 'auto')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $opts->{"type"} or $opts->{"type"} eq "auto") 0 0 0
Condition0%0/3
not $opts->{"type"} or $opts->{"type"} eq "auto"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $opts->{"type"} or $opts->{"type"} eq "auto"
not $opts->{"type"} $opts->{"type"} eq "auto"
Truth table0%0/3
not(A) or B
A= not $opts->{"type"}B= $opts->{"type"} eq "auto"
ABresult
1X1
011
000
214 0 ▶ $$opts{type} = 'BibTeX' if ($$opts{source} && ($$opts{source} =~ /$is_bibtex/)); }
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"source"} and $opts->{"source"} =~ /$LaTeXML::Common::Config::is_bibtex/ 0 0 0
Condition0%0/3
$opts->{"source"} and $opts->{"source"} =~ /$LaTeXML::Common::Config::is_bibtex/
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"source"} and $opts->{"source"} =~ /$LaTeXML::Common::Config::is_bibtex/
$opts->{"source"} $opts->{"source"} =~ /$LaTeXML::Common::Config::is_bibtex/
Truth table0%0/3
A and B
A= $opts->{"source"}B= $opts->{"source"} =~ /$LaTeXML::Common::Config::is_bibtex/
ABresult
0X0
100
111
215 0 ▶ if (!$$opts{whatsin}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"whatsin"}) 0 0 0
216 0 ▶ $$opts{whatsin} = 'archive' if ($$opts{source} && ($$opts{source} =~ /$is_archive/)); }
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"source"} and $opts->{"source"} =~ /$LaTeXML::Common::Config::is_archive/ 0 0 0
Condition0%0/3
$opts->{"source"} and $opts->{"source"} =~ /$LaTeXML::Common::Config::is_archive/
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"source"} and $opts->{"source"} =~ /$LaTeXML::Common::Config::is_archive/
$opts->{"source"} $opts->{"source"} =~ /$LaTeXML::Common::Config::is_archive/
Truth table0%0/3
A and B
A= $opts->{"source"}B= $opts->{"source"} =~ /$LaTeXML::Common::Config::is_archive/
ABresult
0X0
100
111
217 0 return $getOptions_success;
218 }
219  
220 sub read_keyvals {
221 0 ▶ my ($self, $conversion_options, %read_options) = @_;
Subroutine read_keyvals: not called CC=6 SCAR=37.4
Pod undocumented
222 0 my $cmdopts = [];
223 0 ▶ while (my ($key, $value) = splice(@$conversion_options, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@$conversion_options, 0, 2)) 0 0 0
224 # TODO: Is skipping over empty values ever harmful? Do we have non-empty defaults anywhere?
225 0 ▶ next if (!length($value)) && (grep { /^$key\=/ } @GETOPT_KEYS);
Branch: 1 branch
BranchTrueFalseTotal
if not length $value and grep {/^$key\=/;} @LaTeXML::Common::Config::GETOPT_KEYS 0 0 0
Condition0%0/3
not length $value and grep {/^$key\=/;} @LaTeXML::Common::Config::GETOPT_KEYS
!ll&&!rl&&r
000
MC/DC0%0/2
not length $value and grep {/^$key\=/;} @LaTeXML::Common::Config::GETOPT_KEYS
not length $value grep {/^$key\=/;} @LaTeXML::Common::Config::GETOPT_KEYS
Truth table0%0/3
not(A) and B
A= not length $valueB= grep {/^$key\=/;} @LaTeXML::Common::Config::GETOPT_KEYS
ABresult
0X0
100
111
226 0 ▶ $key = "--$key" unless $key =~ /^\-\-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /^\-\-/ 0 0 0
227 0 ▶ $value = length($value) ? "=$value" : '';
Branch: 1 branch
BranchTrueFalseTotal
length $value ? : 0 0 0
228 0 CORE::push @$cmdopts, "$key$value";
229 }
230 # Read into a Config object:
231 0 return $self->read($cmdopts, %read_options); }
232  
233 sub scan_to_keyvals {
234 0 ▶ my ($self, $argref, %read_options) = @_;
Subroutine scan_to_keyvals: not called CC=6 SCAR=37.4
Pod undocumented
235 0 local @ARGV = @$argref;
236 0 my ($spec, $keyvals) = getopt_specification(type => 'keyvals');
237 0 ▶ my $silent = %read_options && $read_options{silent};
Condition0%0/3
%read_options && $read_options{'silent'}
!ll&&!rl&&r
000
MC/DC0%0/2
%read_options && $read_options{'silent'}
%read_options $read_options{'silent'}
Truth table0%0/3
A && B
A= %read_optionsB= $read_options{'silent'}
ABresult
0X0
100
111
238 0 my $getOptions_success = GetOptions(%$spec);
239 0 ▶ if (!$getOptions_success && !$silent) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($getOptions_success or $silent) 0 0 0
Condition0%0/3
$getOptions_success or $silent
l!l&&r!l&&!r
000
MC/DC0%0/2
$getOptions_success or $silent
$getOptions_success $silent
Truth table0%0/3
A or B
A= $getOptions_successB= $silent
ABresult
1X1
011
000
240 0 pod2usage(-message => $LaTeXML::IDENTITY, -exitval => 1, -verbose => 99,
241 -input => pod_where({ -inc => 1 }, __PACKAGE__),
242 -sections => 'OPTION SYNOPSIS', -output => \*STDERR);
243 }
244 0 ▶ CORE::push @$keyvals, ['source', $ARGV[0]] if $ARGV[0];
Branch: 1 branch
BranchTrueFalseTotal
if $ARGV[0] 0 0 0
245 0 ▶ return $getOptions_success && $keyvals;
Condition0%0/3
$getOptions_success && $keyvals
!ll&&!rl&&r
000
MC/DC0%0/2
$getOptions_success && $keyvals
$getOptions_success $keyvals
Truth table0%0/3
A && B
A= $getOptions_successB= $keyvals
ABresult
0X0
100
111
246 }
247  
248 ###########################################
249 #### Options Object Hashlike API #####
250 ###########################################
251 sub get {
252 0 ▶ my ($self, $key, $value) = @_;
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
253 0 return $$self{opts}{$key}; }
254  
255 sub set {
256 0 ▶ my ($self, $key, $value) = @_;
Subroutine set: not called CC=1 SCAR=6.9
Pod documented
257 0 $$self{dirty} = 1;
258 0 $$self{opts}{$key} = $value;
259 0 return; }
260  
261 sub push {
262 0 ▶ my ($self, $key, $value) = @_;
Subroutine push: not called CC=2 SCAR=17.9
Pod undocumented
263 0 $$self{dirty} = 1;
264 0 ▶ $$self{opts}{$key} = [] unless ref $$self{opts}{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"opts"}{$key} 0 0 0
265 0 CORE::push @{ $$self{opts}{$key} }, $value;
266 0 return; }
267  
268 sub delete {
269 0 ▶ my ($self, $key) = @_;
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
270 0 $$self{dirty} = 1;
271 0 delete $$self{opts}{$key};
272 0 return; }
273  
274 sub exists {
275 0 ▶ my ($self, $key) = @_;
Subroutine exists: not called CC=1 SCAR=6.9
Pod documented
276 0 return exists $$self{opts}{$key}; }
277  
278 sub defined {
279 0 ▶ my ($self, $key) = @_;
Subroutine defined: not called CC=1 SCAR=6.9
Pod undocumented
280 0 return defined $$self{opts}{$key}; }
281  
282 sub keys {
283 0 ▶ my ($self) = @_;
Subroutine keys: not called CC=1 SCAR=6.9
Pod documented
284 0 return keys %{ $$self{opts} }; }
285  
286 sub options {
287 0 ▶ my ($self) = @_;
Subroutine options: not called CC=1 SCAR=6.9
Pod documented
288 0 return $$self{opts}; }
289  
290 sub clone {
291 0 ▶ my ($self) = @_;
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
292 0 my $clone = LaTeXML::Common::Config->new(%{ $self->options });
293 0 $$clone{dirty} = $$self{dirty};
294 0 return $clone; }
295  
296 ###########################################
297 #### Option Sanity Checking #####
298 ###########################################
299  
300 # Perform all option sanity checks
301 sub check {
302 0 ▶ my ($self) = @_;
Subroutine check: not called CC=2 SCAR=17.9
Pod documented
303 0 ▶ return unless $$self{dirty};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dirty"} 0 0 0
304 # 1. Resolve profile
305 0 $self->_obey_profile;
306 # 2. Place sane defaults where needed
307 0 return $self->_prepare_options; }
308  
309 sub _obey_profile {
310 0 ▶ my ($self) = @_;
Subroutine _obey_profile: not called CC=14 SCAR=53.5
311 0 $$self{dirty} = 1;
312 0 my $opts = $$self{opts};
313 0 ▶ my $profile = lc($$opts{profile} || 'custom');
Condition0%0/2
$opts->{'profile'} || 'custom'
l!l
00
MC/DC0%0/1
$opts->{'profile'} || 'custom'
$opts->{'profile'}
Truth table0%0/2
A
A= $opts->{'profile'}
Aresult
11
00
314 0 $profile =~ s/\.opt$//;
315 # Look at the PROFILES_DB or find a profiles file (otherwise fallback to custom)
316 0 my $profile_opts = {};
317 0 ▶ if ($profile ne 'custom') {
Branch: 1 branch
BranchTrueFalseTotal
if ($profile ne "custom") 0 0 0
318 0 ▶ if (defined $$PROFILES_DB{$profile}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $LaTeXML::Common::Config::PROFILES_DB->{$profile}) { } 0 0 0
elsif (my $file = pathname_find($profile . '.opt', 'paths', $opts->{'paths'}, 'types', scalar [], 'installation_subdir', 'resources/Profiles')) { } 0 0 0
319 0 %$profile_opts = %{ $$PROFILES_DB{$profile} };
320 } elsif (my $file = pathname_find($profile . '.opt', paths => $$opts{paths},
321 types => [], installation_subdir => 'resources/Profiles')) {
322 0 my $conf_tmp = LaTeXML::Common::Config->new;
323 0 $conf_tmp->read(_read_options_file($file));
324 0 $profile_opts = $conf_tmp->options;
325 } else {
326 # Throw an error, fallback to custom
327 0 carp("Warning:unexpected:$profile Profile $profile was not recognized, reverting to 'custom'\n");
328 0 $$opts{profile} = 'custom';
329 0 $profile = 'custom';
330 }
331 }
332 # Erase the profile, save it as cache key
333 0 delete $$opts{profile};
334 0 ▶ $$opts{cache_key} = $profile unless defined $$opts{cache_key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"cache_key"} 0 0 0
335 0 ▶ if (%$profile_opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$profile_opts) 0 0 0
336 # Merge the new options with the profile defaults:
337 0 for my $key (grep { defined $$opts{$_} } (CORE::keys %$opts)) {
338 0 ▶ if ($key =~ /^p(ath|reload)/) { # Paths and preloads get merged in
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^p(ath|reload)/) { } 0 0 0
339 0 ▶ $$profile_opts{$key} = [] unless defined $$profile_opts{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $profile_opts->{$key} 0 0 0
340 0 foreach my $entry (@{ $$opts{$key} }) {
341 0 my $new = 1;
342 0 foreach (@{ $$profile_opts{$key} }) {
343 0 ▶ if ($entry eq $_) { $new = 0; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($entry eq $_) 0 0 0
344 }
345 # If new to the array, push:
346 0 ▶ CORE::push(@{ $$profile_opts{$key} }, $entry) if ($new);
Branch: 1 branch
BranchTrueFalseTotal
if $new 0 0 0
347 }
348 } else { # The other options get overwritten
349 0 $$profile_opts{$key} = $$opts{$key};
350 }
351 }
352 0 %$opts = %$profile_opts; # Move back into the user options
353 }
354 0 return; }
355  
356 # TODO: Best way to throw errors when options don't work out?
357 # How about in the case of Extras::ReadOptions?
358 # Error() and Warn() would be neat, but we have to make sure STDERR is caught beforehand.
359 # Also, there is no eval() here, so we might need a softer handling of Error()s.
360 sub _prepare_options {
361 0 ▶ my ($self) = @_;
Subroutine _prepare_options: not called CC=125 SCAR=96.6
362 0 my $opts = $$self{opts};
363 #======================================================================
364 # I. Sanity check and Completion of Core options.
365 #======================================================================
366 # "safe" and semi-perlcrtic acceptable way to set DEBUG inside arbitrary modules.
367 # Note: 'LaTeXML' refers to the top-level class
368 0 ▶ foreach my $ltx_class (@{ $$opts{debug} || [] }) {
Branch: 1 branch
BranchTrueFalseTotal
$opts->{"debug"} or [] 0 0 0
369 0 ▶ if ($ltx_class eq 'LaTeXML') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ltx_class eq 'LaTeXML') { } 0 0 0
370 0 $LaTeXML::DEBUG{LaTeXML} = 1; }
371 else {
372 0 $LaTeXML::DEBUG{$ltx_class} = 1; } }
373  
374 0 ▶ $$opts{input_limit} = 100 unless defined $$opts{input_limit}; # 100 jobs until restart
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"input_limit"} 0 0 0
375 0 ▶ $$opts{timeout} = 600 unless defined $$opts{timeout}; # 10 minute timeout default
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"timeout"} 0 0 0
376 0 ▶ $$opts{expire} = 600 unless defined $$opts{expire}; # 10 minute timeout default
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"expire"} 0 0 0
377 0 ▶ $$opts{mathparse} = 'RecDescent' unless defined $$opts{mathparse};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"mathparse"} 0 0 0
378 0 ▶ $$opts{inputencoding} = "utf-8" unless defined $$opts{inputencoding};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"inputencoding"} 0 0 0
379 0 ▶ if ($$opts{mathparse} eq 'no') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"mathparse"} eq "no") 0 0 0
380 0 $$opts{mathparse} = 0;
381 0 $$opts{nomathparse} = 1; } #Backwards compatible
382 ## $$opts{verbosity} = 0 unless defined $$opts{verbosity};
383 0 ▶ $$opts{preload} = [] unless defined $$opts{preload};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"preload"} 0 0 0
384 0 ▶ $$opts{paths} = ['.'] unless defined $$opts{paths};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"paths"} 0 0 0
385 0 @{ $$opts{paths} } = map { pathname_canonical($_) } @{ $$opts{paths} };
386 0 foreach (('destination', 'dbfile', 'sourcedirectory', 'sitedirectory')) {
387 0 ▶ $$opts{$_} = pathname_canonical($$opts{$_}) if defined $$opts{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{$_} 0 0 0
388 }
389  
390 0 ▶ if (!defined $$opts{whatsin}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts->{"whatsin"}) 0 0 0
391 0 ▶ if ($$opts{preamble} || $$opts{postamble}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'preamble'} or $opts->{'postamble'}) { } 0 0 0
Condition0%0/3
$opts->{"preamble"} or $opts->{"postamble"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"preamble"} or $opts->{"postamble"}
$opts->{"preamble"} $opts->{"postamble"}
Truth table0%0/3
A or B
A= $opts->{"preamble"}B= $opts->{"postamble"}
ABresult
1X1
011
000
392 # Preamble or postamble imply a fragment whatsin
393 0 $$opts{whatsin} = 'fragment'; }
394 else { # Default input chunk is a document
395 0 $$opts{whatsin} = 'document'; } }
396 0 ▶ $$opts{type} = 'auto' unless defined $$opts{type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"type"} 0 0 0
397 0 ▶ unshift(@{ $$opts{preload} }, ('TeX.pool', 'LaTeX.pool', 'BibTeX.pool')) if ($$opts{type} eq 'BibTeX');
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"type"} eq "BibTeX" 0 0 0
398  
399 # Destination extension might indicate the format:
400 0 ▶ if ((!defined $$opts{extension}) && (defined $$opts{destination})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $opts->{"extension"} and defined $opts->{"destination"}) 0 0 0
Condition0%0/3
not defined $opts->{"extension"} and defined $opts->{"destination"}
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $opts->{"extension"} and defined $opts->{"destination"}
not defined $opts->{"extension"} defined $opts->{"destination"}
Truth table0%0/3
not(A) and B
A= not defined $opts->{"extension"}B= defined $opts->{"destination"}
ABresult
0X0
100
111
401 0 ▶ if ($$opts{destination} =~ /\.([^.]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"destination"} =~ /\.([^.]+)$/) 0 0 0
402 0 $$opts{extension} = $1; } }
403 0 ▶ if ((!defined $$opts{format}) && (defined $$opts{extension})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $opts->{"format"} and defined $opts->{"extension"}) 0 0 0
Condition0%0/3
not defined $opts->{"format"} and defined $opts->{"extension"}
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $opts->{"format"} and defined $opts->{"extension"}
not defined $opts->{"format"} defined $opts->{"extension"}
Truth table0%0/3
not(A) and B
A= not defined $opts->{"format"}B= defined $opts->{"extension"}
ABresult
0X0
100
111
404 0 $$opts{format} = $$opts{extension}; }
405 0 ▶ if ((!defined $$opts{extension}) && (defined $$opts{format})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $opts->{"extension"} and defined $opts->{"format"}) 0 0 0
Condition0%0/3
not defined $opts->{"extension"} and defined $opts->{"format"}
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $opts->{"extension"} and defined $opts->{"format"}
not defined $opts->{"extension"} defined $opts->{"format"}
Truth table0%0/3
not(A) and B
A= not defined $opts->{"extension"}B= defined $opts->{"format"}
ABresult
0X0
100
111
406 0 ▶ if ($$opts{format} =~ /^html/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'format'} =~ /^html/) { } 0 0 0
elsif ($opts->{'format'} =~ /^xhtml/) { } 0 0 0
407 0 $$opts{extension} = 'html'; }
408 elsif ($$opts{format} =~ /^xhtml/) {
409 0 $$opts{extension} = 'xhtml'; }
410 else {
411 0 $$opts{extension} = 'xml'; } }
412 0 ▶ if (!defined $$opts{whatsout}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts->{"whatsout"}) 0 0 0
413 0 ▶ if ((defined $$opts{extension}) && ($$opts{extension} eq 'zip')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{'extension'} and $opts->{'extension'} eq 'zip') { } 0 0 0
Condition0%0/3
defined $opts->{"extension"} and $opts->{"extension"} eq "zip"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"extension"} and $opts->{"extension"} eq "zip"
defined $opts->{"extension"} $opts->{"extension"} eq "zip"
Truth table0%0/3
A and B
A= defined $opts->{"extension"}B= $opts->{"extension"} eq "zip"
ABresult
0X0
100
111
414 0 $$opts{whatsout} = 'archive';
415 } else {
416 0 $$opts{whatsout} = 'document';
417 } }
418 0 ▶ if ($$opts{format}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'format'}) { } 0 0 0
419 # Lower-case for sanity's sake
420 0 $$opts{format} = lc($$opts{format});
421 0 ▶ if ($$opts{format} eq 'zip') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'format'} eq 'zip') { } 0 0 0
422 # Not encouraged! But try to produce something sensible anyway...
423 0 $$opts{format} = 'html5';
424 0 $$opts{whatsout} = 'archive'; }
425 else { # Default HTML is 5
426 0 ▶ $$opts{format} = 'html5' if $$opts{format} eq 'html'; }
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"format"} eq "html" 0 0 0
427  
428 0 $$opts{is_html} = ($$opts{format} =~ /^html/);
429 0 $$opts{is_xhtml} = ($$opts{format} =~ /^(xhtml5?|epub|mobi)$/);
430 0 ▶ $$opts{whatsout} = 'archive' if (($$opts{format} eq 'epub') || ($$opts{format} eq 'mobi'));
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"format"} eq "epub" or $opts->{"format"} eq "mobi" 0 0 0
Condition0%0/3
$opts->{"format"} eq "epub" or $opts->{"format"} eq "mobi"
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"format"} eq "epub" or $opts->{"format"} eq "mobi"
$opts->{"format"} eq "epub" $opts->{"format"} eq "mobi"
Truth table0%0/3
A or B
A= $opts->{"format"} eq "epub"B= $opts->{"format"} eq "mobi"
ABresult
1X1
011
000
431 } else {
432 0 $$opts{format} = 'xml' # We failed to guess format in any-which-way, so XML is default
433 }
434 #======================================================================
435 # II. Sanity check and Completion of Post options.
436 #======================================================================
437 # Any post switch implies post (TODO: whew, lots of those, add them all!):
438 0 ▶ $$opts{math_formats} = [] unless defined $$opts{math_formats};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"math_formats"} 0 0 0
439 $$opts{post} = 1 if ((!defined $$opts{post}) &&
440 0 ▶ (scalar(@{ $$opts{math_formats} })
Condition0%0/5
$opts->{'format'} || ''
l!l
00
$opts->{"whatsout"} and $opts->{"whatsout"} ne "document"
!ll&&!rl&&r
000
MC/DC0%0/1
$opts->{'format'} || ''
$opts->{'format'}
MC/DC0%0/2
$opts->{"whatsout"} and $opts->{"whatsout"} ne "document"
$opts->{"whatsout"} $opts->{"whatsout"} ne "document"
Truth table0%0/2
A
A= $opts->{'format'}
Aresult
11
00
Truth table0%0/3
A and B
A= $opts->{"whatsout"}B= $opts->{"whatsout"} ne "document"
ABresult
0X0
100
111
441 || ($$opts{stylesheet})
442 || $$opts{is_html}
443 || $$opts{is_xhtml}
444 || (($$opts{format} || '') eq 'jats')
445 0 ▶ || ($$opts{whatsout} && ($$opts{whatsout} ne 'document'))
Branch: 1 branch
BranchTrueFalseTotal
if not defined $opts->{"post"} and scalar @{$opts->{"math_formats"};} || $opts->{"stylesheet"} || $opts->{"is_html"} || $opts->{"is_xhtml"} || ($opts->{"format"} || "") eq "jats" || $opts->{"whatsout"} && $opts->{"whatsout"} ne "document" 0 0 0
Condition0%0/18
not defined $opts->{"post"} and scalar @{$opts->{"math_formats"};} || $opts->{"stylesheet"} || $opts->{"is_html"} || $opts->{"is_xhtml"} || ($opts->{"format"} || "") eq "jats" || $opts->{"whatsout"} && $opts->{"whatsout"} ne "document"
!ll&&!rl&&r
000
scalar @{$opts->{"math_formats"};} or $opts->{"stylesheet"} or $opts->{"is_html"} or $opts->{"is_xhtml"} or ($opts->{"format"} || "") eq "jats" or $opts->{"whatsout"} and $opts->{"whatsout"} ne "document"
l!l&&r!l&&!r
000
scalar @{$opts->{"math_formats"};} or $opts->{"stylesheet"} or $opts->{"is_html"} or $opts->{"is_xhtml"} or ($opts->{"format"} || "") eq "jats"
l!l&&r!l&&!r
000
scalar @{$opts->{"math_formats"};} or $opts->{"stylesheet"} or $opts->{"is_html"} or $opts->{"is_xhtml"}
l!l&&r!l&&!r
000
scalar @{$opts->{"math_formats"};} or $opts->{"stylesheet"} or $opts->{"is_html"}
l!l&&r!l&&!r
000
scalar @{$opts->{"math_formats"};} or $opts->{"stylesheet"}
l!l&&r!l&&!r
000
MC/DC0%0/7
not defined $opts->{"post"} and scalar @{$opts->{"math_formats"};} || $opts->{"stylesheet"} || $opts->{"is_html"} || $opts->{"is_xhtml"} || ($opts->{"format"} || "") eq "jats" || $opts->{"whatsout"} && $opts->{"whatsout"} ne "document"
not defined $opts->{"post"} scalar @{$opts->{"math_formats"};} $opts->{"stylesheet"} $opts->{"is_html"} $opts->{"is_xhtml"} ($opts->{"format"} || "") eq "jats" $opts->{"whatsout"} and $opts->{"whatsout"} ne "document"
Truth table0%0/8
not(A) and B or C or D or E or F or G
A= not defined $opts->{"post"}B= scalar @{$opts->{"math_formats"};}C= $opts->{"stylesheet"}D= $opts->{"is_html"}E= $opts->{"is_xhtml"}F= ($opts->{"format"} || "") eq "jats"G= $opts->{"whatsout"} and $opts->{"whatsout"} ne "document"
ABCDEFGresult
0XXXXXX0
10000000
11XXXXX1
101XXXX1
1001XXX1
10001XX1
100001X1
10000011
446 )
447 );
448 # || ... || ... || ...
449 # $$opts{post}=0 if (defined $$opts{mathparse} && (! $$opts{mathparse})); # No-parse overrides post-processing
450 0 ▶ if ($$opts{post}) { # No need to bother if we're not post-processing
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"post"}) 0 0 0
451 # Default: scan and crossref on, other advanced off
452 0 ▶ $$opts{prescan} = undef unless defined $$opts{prescan};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"prescan"} 0 0 0
453 0 ▶ $$opts{dbfile} = undef unless defined $$opts{dbfile};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"dbfile"} 0 0 0
454 0 ▶ $$opts{scan} = 1 unless defined $$opts{scan};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"scan"} 0 0 0
455 0 ▶ $$opts{index} = 1 unless defined $$opts{index};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"index"} 0 0 0
456 0 ▶ $$opts{crossref} = 1 unless defined $$opts{crossref};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"crossref"} 0 0 0
457 $$opts{sitedirectory} = defined $$opts{sitedirectory} ? $$opts{sitedirectory}
458 : (defined $$opts{destination} ? pathname_directory($$opts{destination})
459 : (defined $$opts{dbfile} ? pathname_directory($$opts{dbfile})
460 0 ▶ : "."));
Branch: 3 branches
BranchTrueFalseTotal
defined $opts->{'sitedirectory'} ? : 0 0 0
defined $opts->{'destination'} ? : 0 0 0
defined $opts->{'dbfile'} ? : 0 0 0
461 0 ▶ $$opts{sourcedirectory} = undef unless defined $$opts{sourcedirectory};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"sourcedirectory"} 0 0 0
462 0 ▶ $$opts{numbersections} = 1 unless defined $$opts{numbersections};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"numbersections"} 0 0 0
463 0 ▶ $$opts{navtoc} = undef unless defined $$opts{numbersections};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"numbersections"} 0 0 0
464 0 ▶ $$opts{navtocstyles} = { context => 1, normal => 1, none => 1 } unless defined $$opts{navtocstyles};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"navtocstyles"} 0 0 0
465 0 ▶ $$opts{navtoc} = lc($$opts{navtoc}) if defined $$opts{navtoc};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"navtoc"} 0 0 0
466 0 ▶ delete $$opts{navtoc} if ($$opts{navtoc} && ($$opts{navtoc} eq 'none'));
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"navtoc"} and $opts->{"navtoc"} eq "none" 0 0 0
Condition0%0/3
$opts->{"navtoc"} and $opts->{"navtoc"} eq "none"
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"navtoc"} and $opts->{"navtoc"} eq "none"
$opts->{"navtoc"} $opts->{"navtoc"} eq "none"
Truth table0%0/3
A and B
A= $opts->{"navtoc"}B= $opts->{"navtoc"} eq "none"
ABresult
0X0
100
111
467  
468 0 ▶ if ($$opts{navtoc}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"navtoc"}) 0 0 0
469 0 ▶ if (!$$opts{navtocstyles}->{ $$opts{navtoc} }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"navtocstyles"}{$opts->{"navtoc"}}) 0 0 0
470 0 croak($$opts{navtoc} . " is not a recognized style of navigation TOC"); }
471 0 ▶ if (!$$opts{crossref}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"crossref"}) 0 0 0
472 0 croak("Cannot use option \"navigationtoc\" (" . $$opts{navtoc} . ") without \"crossref\""); } }
473 0 ▶ $$opts{urlstyle} = 'server' unless defined $$opts{urlstyle};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"urlstyle"} 0 0 0
474 0 ▶ $$opts{bibliographies} = [] unless defined $$opts{bibliographies};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"bibliographies"} 0 0 0
475  
476 # Validation:
477 0 ▶ $$opts{validate} = 1 unless defined $$opts{validate};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"validate"} 0 0 0
478 # Graphics:
479 0 ▶ $$opts{mathimagemag} = 1.75 unless defined $$opts{mathimagemag};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"mathimagemag"} 0 0 0
480 0 ▶ if ((defined $$opts{destination}) || ($$opts{whatsout} =~ /^archive/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"destination"} or $opts->{"whatsout"} =~ /^archive/) 0 0 0
Condition0%0/3
defined $opts->{"destination"} or $opts->{"whatsout"} =~ /^archive/
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $opts->{"destination"} or $opts->{"whatsout"} =~ /^archive/
defined $opts->{"destination"} $opts->{"whatsout"} =~ /^archive/
Truth table0%0/3
A or B
A= defined $opts->{"destination"}B= $opts->{"whatsout"} =~ /^archive/
ABresult
1X1
011
000
481 # We want the graphics enabled by default, but only when we have a destination
482 0 ▶ $$opts{dographics} = 1 unless defined $$opts{dographics};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"dographics"} 0 0 0
483 $$opts{picimages} = 1 if (($$opts{format} eq "html4") || ($$opts{format} eq "jats"))
484 0 ▶ && !defined $$opts{picimages};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"format"} eq "html4" || $opts->{"format"} eq "jats" and not defined $opts->{"picimages"} 0 0 0
Condition0%0/6
$opts->{"format"} eq "html4" || $opts->{"format"} eq "jats" and not defined $opts->{"picimages"}
!ll&&!rl&&r
000
$opts->{"format"} eq "html4" or $opts->{"format"} eq "jats"
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts->{"format"} eq "html4" || $opts->{"format"} eq "jats" and not defined $opts->{"picimages"}
$opts->{"format"} eq "html4" $opts->{"format"} eq "jats" not defined $opts->{"picimages"}
Truth table0%0/5
A or B and not(C)
A= $opts->{"format"} eq "html4"B= $opts->{"format"} eq "jats"C= not defined $opts->{"picimages"}
ABCresult
00X0
1X00
0100
1X11
0111
485 }
486 # Split sanity:
487 0 ▶ if ($$opts{split}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"split"}) 0 0 0
488 0 ▶ $$opts{splitat} = 'section' unless defined $$opts{splitat};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"splitat"} 0 0 0
489 0 ▶ $$opts{splitnaming} = 'id' unless defined $$opts{splitnaming};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"splitnaming"} 0 0 0
490 $$opts{splitancestors} = {
491 0 part => [qw()],
492 chapter => [qw(part)],
493 section => [qw(part chapter)],
494 subsection => [qw(part chapter section)],
495 subsubsection => [qw(part chapter section subsection)] };
496 0 $$opts{splitback} = [qw(bibliography appendix index)];
497  
498 $$opts{splitnaming} = _checkOptionValue('--splitnaming', $$opts{splitnaming},
499 0 qw(id idrelative label labelrelative));
500 0 $$opts{splitat} = _checkOptionValue('--splitat', $$opts{splitat}, CORE::keys %{ $$opts{splitancestors} });
501 0 ▶ $$opts{splitpath} = make_splitpaths($opts, $$opts{splitat}) unless defined $$opts{splitpath}; }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"splitpath"} 0 0 0
502 # Check for appropriate combination of split, scan, prescan, dbfile, crossref
503 0 ▶ if ($$opts{split} && (!defined $$opts{destination}) && ($$opts{whatsout} !~ /^archive/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"split"} and not defined $opts->{"destination"} and not $opts->{"whatsout"} =~ /^archive/) 0 0 0
Condition0%0/6
$opts->{"split"} and not defined $opts->{"destination"} and not $opts->{"whatsout"} =~ /^archive/
!ll&&!rl&&r
000
$opts->{"split"} and not defined $opts->{"destination"}
!ll&&!rl&&r
000
MC/DC0%0/3
$opts->{"split"} and not defined $opts->{"destination"} and not $opts->{"whatsout"} =~ /^archive/
$opts->{"split"} not defined $opts->{"destination"} not $opts->{"whatsout"} =~ /^archive/
Truth table0%0/4
A and not(B) and not(C)
A= $opts->{"split"}B= not defined $opts->{"destination"}C= not $opts->{"whatsout"} =~ /^archive/
ABCresult
0XX0
10X0
1100
1111
504 0 croak("Must supply --destination when using --split"); }
505 0 ▶ if ($$opts{prescan} && !$$opts{scan}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"prescan"} and not $opts->{"scan"}) 0 0 0
Condition0%0/3
$opts->{"prescan"} and not $opts->{"scan"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"prescan"} and not $opts->{"scan"}
$opts->{"prescan"} not $opts->{"scan"}
Truth table0%0/3
A and not(B)
A= $opts->{"prescan"}B= not $opts->{"scan"}
ABresult
0X0
100
111
506 0 croak("Makes no sense to --prescan with scanning disabled (--noscan)"); }
507 0 ▶ if ($$opts{prescan} && (!defined $$opts{dbfile})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"prescan"} and not defined $opts->{"dbfile"}) 0 0 0
Condition0%0/3
$opts->{"prescan"} and not defined $opts->{"dbfile"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"prescan"} and not defined $opts->{"dbfile"}
$opts->{"prescan"} not defined $opts->{"dbfile"}
Truth table0%0/3
A and not(B)
A= $opts->{"prescan"}B= not defined $opts->{"dbfile"}
ABresult
0X0
100
111
508 0 croak("Cannot prescan documents (--prescan) without specifying --dbfile"); }
509 0 ▶ if (!$$opts{prescan} && $$opts{crossref} && !($$opts{scan} || (defined $$opts{dbfile}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $opts->{"prescan"} and $opts->{"crossref"} and not $opts->{"scan"} || defined $opts->{"dbfile"}) 0 0 0
Condition0%0/9
not $opts->{"prescan"} and $opts->{"crossref"} and not $opts->{"scan"} || defined $opts->{"dbfile"}
!ll&&!rl&&r
000
not $opts->{"prescan"} and $opts->{"crossref"}
!ll&&!rl&&r
000
$opts->{'scan'} || defined $opts->{'dbfile'}
l!l&&r!l&&!r
000
MC/DC0%0/4
not $opts->{"prescan"} and $opts->{"crossref"} and not $opts->{"scan"} || defined $opts->{"dbfile"}
not $opts->{"prescan"} $opts->{"crossref"} $opts->{'scan'} defined $opts->{'dbfile'}
Truth table0%0/5
not(A) and B and not(C || D)
A= not $opts->{"prescan"}B= $opts->{"crossref"}C= $opts->{'scan'}D= defined $opts->{'dbfile'}
ABCDresult
0XXX0
10XX0
111X0
11010
11001
510 0 croak("Cannot cross-reference (--crossref) without --scan or --dbfile "); }
511 0 ▶ if ($$opts{crossref}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"crossref"}) 0 0 0
512 0 $$opts{urlstyle} = _checkOptionValue('--urlstyle', $$opts{urlstyle}, qw(server negotiated file)); }
513 0 ▶ if (($$opts{permutedindex} || $$opts{splitindex}) && (!defined $$opts{index})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"permutedindex"} || $opts->{"splitindex"} and not defined $opts->{"index"}) 0 0 0
Condition0%0/6
$opts->{"permutedindex"} || $opts->{"splitindex"} and not defined $opts->{"index"}
!ll&&!rl&&r
000
$opts->{"permutedindex"} or $opts->{"splitindex"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts->{"permutedindex"} || $opts->{"splitindex"} and not defined $opts->{"index"}
$opts->{"permutedindex"} $opts->{"splitindex"} not defined $opts->{"index"}
Truth table0%0/5
A or B and not(C)
A= $opts->{"permutedindex"}B= $opts->{"splitindex"}C= not defined $opts->{"index"}
ABCresult
00X0
1X00
0100
1X11
0111
514 0 $$opts{index} = 1; }
515 0 ▶ if (!$$opts{prescan} && $$opts{index} && !($$opts{scan} || defined $$opts{crossref})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $opts->{"prescan"} and $opts->{"index"} and not $opts->{"scan"} || defined $opts->{"crossref"}) 0 0 0
Condition0%0/9
not $opts->{"prescan"} and $opts->{"index"} and not $opts->{"scan"} || defined $opts->{"crossref"}
!ll&&!rl&&r
000
not $opts->{"prescan"} and $opts->{"index"}
!ll&&!rl&&r
000
$opts->{'scan'} || defined $opts->{'crossref'}
l!l&&r!l&&!r
000
MC/DC0%0/4
not $opts->{"prescan"} and $opts->{"index"} and not $opts->{"scan"} || defined $opts->{"crossref"}
not $opts->{"prescan"} $opts->{"index"} $opts->{'scan'} defined $opts->{'crossref'}
Truth table0%0/5
not(A) and B and not(C || D)
A= not $opts->{"prescan"}B= $opts->{"index"}C= $opts->{'scan'}D= defined $opts->{'crossref'}
ABCDresult
0XXX0
10XX0
111X0
11010
11001
516 0 croak("Cannot generate index (--index) without --scan or --dbfile"); }
517 0 ▶ if (!$$opts{prescan} && @{ $$opts{bibliographies} } && !($$opts{scan} || defined $$opts{crossref})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $opts->{"prescan"} and @{$opts->{"bibliographies"};} and not $opts->{"scan"} || defined $opts->{"crossref"}) 0 0 0
Condition0%0/9
not $opts->{"prescan"} and @{$opts->{"bibliographies"};} and not $opts->{"scan"} || defined $opts->{"crossref"}
!ll&&!rl&&r
000
not $opts->{"prescan"} and @{$opts->{"bibliographies"};}
!ll&&!rl&&r
000
$opts->{'scan'} || defined $opts->{'crossref'}
l!l&&r!l&&!r
000
MC/DC0%0/4
not $opts->{"prescan"} and @{$opts->{"bibliographies"};} and not $opts->{"scan"} || defined $opts->{"crossref"}
not $opts->{"prescan"} @{$opts->{"bibliographies"};} $opts->{'scan'} defined $opts->{'crossref'}
Truth table0%0/5
not(A) and B and not(C || D)
A= not $opts->{"prescan"}B= @{$opts->{"bibliographies"};}C= $opts->{'scan'}D= defined $opts->{'crossref'}
ABCDresult
0XXX0
10XX0
111X0
11010
11001
518 0 croak("Cannot generate bibliography (--bibliography) without --scan or --dbfile"); }
519  
520 # There is now a legitimate case to preserve graphics here.
521 # if ((!defined $$opts{destination}) && ($$opts{whatsout} !~ /^archive/)
522 # && (_checkMathFormat($opts, 'images') || _checkMathFormat($opts, 'svg')
523 # || $$opts{dographics} || $$opts{picimages})) {
524 # croak("Must supply --destination unless all auxilliary file writing is disabled"
525 # . "(--nomathimages --nomathsvg --nographicimages --nopictureimages --nodefaultcss)"); }
526  
527 # Format:
528 #Default is XHTML, XML otherwise (TODO: Expand)
529 0 ▶ if (!defined $$opts{format}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts->{"format"}) 0 0 0
530 0 ▶ if ($$opts{stylesheet}) { $$opts{format} = "xml"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'stylesheet'}) { } 0 0 0
531 0 else { $$opts{format} = "xhtml"; }
532 }
533  
534 0 ▶ if (!$$opts{stylesheet}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"stylesheet"}) 0 0 0
535 0 ▶ if ($$opts{format} eq 'xhtml') { $$opts{stylesheet} = "LaTeXML-xhtml.xsl"; }
Branch: 6 branches
BranchTrueFalseTotal
if ($opts->{'format'} eq 'xhtml') { } 0 0 0
elsif ($opts->{'format'} eq 'html4') { } 0 0 0
elsif ($opts->{'format'} =~ /^epub|mobi$/) { } 0 0 0
elsif ($opts->{'format'} eq 'html5') { } 0 0 0
elsif ($opts->{'format'} eq 'jats') { } 0 0 0
elsif ($opts->{'format'} eq 'xml') { } 0 0 0
536 0 elsif ($$opts{format} eq "html4") { $$opts{stylesheet} = "LaTeXML-html4.xsl"; }
537 0 elsif ($$opts{format} =~ /^epub|mobi$/) { $$opts{stylesheet} = "LaTeXML-epub3.xsl"; }
538 0 elsif ($$opts{format} eq "html5") { $$opts{stylesheet} = "LaTeXML-html5.xsl"; }
539 0 elsif ($$opts{format} eq "jats") { $$opts{stylesheet} = "LaTeXML-jats.xsl"; }
540 0 elsif ($$opts{format} eq "xml") { delete $$opts{stylesheet}; }
541 0 else { croak("Unrecognized target format: " . $$opts{format}); }
542 }
543 # Check format and complete math and image options
544 0 ▶ if ($$opts{format} eq 'html4') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"format"} eq "html4") 0 0 0
545 0 ▶ $$opts{svg} = 0 unless defined $$opts{svg}; # No SVG by default in HTML.
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"svg"} 0 0 0
546 0 croak("Default html4 stylesheet only supports math images, not " . join(', ', @{ $$opts{math_formats} }))
547 if (!defined $$opts{stylesheet})
548 0 ▶ && scalar(grep { $_ ne 'images' } @{ $$opts{math_formats} });
Branch: 1 branch
BranchTrueFalseTotal
if not defined $opts->{"stylesheet"} and scalar grep({$_ ne "images";} @{$$opts{"math_formats"};}) 0 0 0
Condition0%0/2
not defined $opts->{"stylesheet"} and scalar grep({$_ ne "images";} @{$$opts{"math_formats"};})
!ll
00
MC/DC0%0/1
not defined $opts->{"stylesheet"} and scalar grep({$_ ne "images";} @{$$opts{"math_formats"};})
not defined $opts->{"stylesheet"}
Truth table0%0/2
not(A)
A= not defined $opts->{"stylesheet"}
Aresult
00
11
549 0 ▶ croak("Default html stylesheet does not support svg") if $$opts{svg};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"svg"} 0 0 0
550 0 $$opts{math_formats} = [];
551 0 maybeAddMathFormat($opts, 'images');
552 }
553 0 ▶ $$opts{svg} = 1 unless defined $$opts{svg}; # If we're not making HTML, SVG is on by default
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"svg"} 0 0 0
554 # PMML default if we're HTMLy and all else fails and no mathimages:
555 0 ▶ if (((!defined $$opts{math_formats}) || (!scalar(@{ $$opts{math_formats} })))
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $opts->{"math_formats"} && scalar @{$opts->{"math_formats"};} and $opts->{"is_html"} || $opts->{"is_xhtml"} || $opts->{"format"} eq "jats") 0 0 0
Condition0%0/12
not defined $opts->{"math_formats"} && scalar @{$opts->{"math_formats"};} and $opts->{"is_html"} || $opts->{"is_xhtml"} || $opts->{"format"} eq "jats"
!ll&&!rl&&r
000
defined $opts->{'math_formats'} && scalar @{$opts->{'math_formats'};}
!ll&&!rl&&r
000
$opts->{"is_html"} or $opts->{"is_xhtml"} or $opts->{"format"} eq "jats"
l!l&&r!l&&!r
000
$opts->{"is_html"} or $opts->{"is_xhtml"}
l!l&&r!l&&!r
000
MC/DC0%0/5
not defined $opts->{"math_formats"} && scalar @{$opts->{"math_formats"};} and $opts->{"is_html"} || $opts->{"is_xhtml"} || $opts->{"format"} eq "jats"
defined $opts->{'math_formats'} scalar @{$opts->{'math_formats'};} $opts->{"is_html"} $opts->{"is_xhtml"} $opts->{"format"} eq "jats"
Truth table0%0/9
not(A && B) and C or D or E
A= defined $opts->{'math_formats'}B= scalar @{$opts->{'math_formats'};}C= $opts->{"is_html"}D= $opts->{"is_xhtml"}E= $opts->{"format"} eq "jats"
ABCDEresult
11XXX0
0X0000
100000
0X1XX1
0X01X1
0X0011
101XX1
1001X1
100011
556 && ($$opts{is_html} || $$opts{is_xhtml} || ($$opts{format} eq 'jats'))) {
557 0 CORE::push @{ $$opts{math_formats} }, 'pmml';
558 }
559 # use parallel markup if there are multiple formats requested.
560 0 ▶ $$opts{parallelmath} = 1 if ($$opts{math_formats} && (@{ $$opts{math_formats} } > 1));
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"math_formats"} and @{$opts->{"math_formats"};} > 1 0 0 0
Condition0%0/3
$opts->{"math_formats"} and @{$opts->{"math_formats"};} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"math_formats"} and @{$opts->{"math_formats"};} > 1
$opts->{"math_formats"} @{$opts->{"math_formats"};} > 1
Truth table0%0/3
A and B
A= $opts->{"math_formats"}B= @{$opts->{"math_formats"};} > 1
ABresult
0X0
100
111
561 }
562 # If really nothing hints to define format, then default it to XML
563 0 ▶ $$opts{format} = 'xml' unless defined $$opts{format};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"format"} 0 0 0
564 0 $$self{dirty} = 0;
565 0 return; }
566  
567 ## Public Utilities:
568  
569 sub addMathFormat {
570 0 ▶ my ($opts, $fmt) = @_;
Subroutine addMathFormat: not called CC=4 SCAR=30.0
Pod undocumented
571 0 ▶ $$opts{math_formats} = [] unless defined $$opts{math_formats};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"math_formats"} 0 0 0
572 0 CORE::push(@{ $$opts{math_formats} }, $fmt)
573 0 ▶ unless (grep { $_ eq $fmt } @{ $$opts{math_formats} }) || $$opts{removed_math_formats}->{$fmt};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $fmt;} @{$$opts{"math_formats"};} or $opts->{"removed_math_formats"}{$fmt} 0 0 0
Condition0%0/3
grep {$_ eq $fmt;} @{$$opts{"math_formats"};} or $opts->{"removed_math_formats"}{$fmt}
l!l&&r!l&&!r
000
MC/DC0%0/2
grep {$_ eq $fmt;} @{$$opts{"math_formats"};} or $opts->{"removed_math_formats"}{$fmt}
grep {$_ eq $fmt;} @{$$opts{"math_formats"};} $opts->{"removed_math_formats"}{$fmt}
Truth table0%0/3
A or B
A= grep {$_ eq $fmt;} @{$$opts{"math_formats"};}B= $opts->{"removed_math_formats"}{$fmt}
ABresult
1X1
011
000
574 0 return; }
575  
576 sub removeMathFormat {
577 0 ▶ my ($opts, $fmt) = @_;
Subroutine removeMathFormat: not called CC=1 SCAR=6.9
Pod undocumented
578 0 @{ $$opts{math_formats} } = grep { $_ ne $fmt } @{ $$opts{math_formats} };
579 0 $$opts{removed_math_formats}->{$fmt} = 1;
580 0 return; }
581  
582 # Add a default math format, when no math formatter is requested, unless specifically forbidden
583 sub maybeAddMathFormat {
584 0 ▶ my ($opts, $fmt) = @_;
Subroutine maybeAddMathFormat: not called CC=3 SCAR=24.8
Pod undocumented
585 0 unshift(@{ $$opts{math_formats} }, $fmt)
586 0 ▶ unless @{ $$opts{math_formats} } || $$opts{removed_math_formats}{$fmt};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$opts->{"math_formats"};} or $opts->{"removed_math_formats"}{$fmt} 0 0 0
Condition0%0/3
@{$opts->{"math_formats"};} or $opts->{"removed_math_formats"}{$fmt}
l!l&&r!l&&!r
000
MC/DC0%0/2
@{$opts->{"math_formats"};} or $opts->{"removed_math_formats"}{$fmt}
@{$opts->{"math_formats"};} $opts->{"removed_math_formats"}{$fmt}
Truth table0%0/3
A or B
A= @{$opts->{"math_formats"};}B= $opts->{"removed_math_formats"}{$fmt}
ABresult
1X1
011
000
587 0 return; }
588  
589 sub _checkMathFormat {
590 0 ▶ my ($opts, $fmt) = @_;
Subroutine _checkMathFormat: not called CC=1 SCAR=6.9
591 0 return grep { $_ eq $fmt } @{ $$opts{math_formats} }; }
592  
593 ## Utilities:
594  
595 sub _checkOptionValue {
596 0 ▶ my ($option, $value, @choices) = @_;
Subroutine _checkOptionValue: not called CC=4 SCAR=30.0
597 0 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) 0 0 0
598 0 foreach my $choice (@choices) {
599 0 ▶ return $choice if substr($choice, 0, length($value)) eq $value; } }
Branch: 1 branch
BranchTrueFalseTotal
if substr($choice, 0, length $value) eq $value 0 0 0
600 0 croak("Value for $option, $value, doesn't match " . join(', ', @choices)); }
601  
602 # Contrived xpath, since backmatter can now be at any level!
603 sub make_splitpaths {
604 0 ▶ my ($opts, $splitat) = @_;
Subroutine make_splitpaths: not called CC=4 SCAR=30.0
Pod undocumented
605 0 my @paths = ();
606 0 my $anc = $$opts{splitancestors}{$splitat};
607 0 ▶ foreach my $unit ($splitat, ($anc ? @$anc : ())) {
Branch: 1 branch
BranchTrueFalseTotal
$anc ? : 0 0 0
608 0 CORE::push(@paths, "//ltx:$unit");
609 0 foreach my $back (@{ $$opts{splitback} }) {
610 CORE::push(@paths, "//ltx:$back\["
611 . join(' or ', "preceding-sibling::ltx:$unit",
612 0 map { "parent::ltx:$_"; } @{ $$opts{splitancestors}{$unit} })
613 . "]"); } }
614 0 return join(' | ', @paths); }
615  
616 ### This is from t/lib/TestDaemon.pm and ideally belongs in Util::Pathname
617 sub _read_options_file {
618 0 ▶ my ($file) = @_;
Subroutine _read_options_file: not called CC=14 SCAR=53.5
619 0 my $opts = [];
620 0 my $OPT;
621 #### Now can we report status to right places before we've gotten configuration??? (verbosity, logfile...)
622 #### ProgressSpinup("Loading profile $file");
623 0 ▶ unless (open($OPT, "<", $file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $OPT, "<", $file) 0 0 0
624 0 Error('expected', $file, "Could not open options file '$file'");
625 0 return; }
626 0 ▶ while (my $line = <$OPT>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $OPT)) 0 0 0
627 # Cleanup comments, padding on the input line.
628 0 $line =~ s/(?<!\\)#.*$//; # Strip trailing comments starting w/ # (but \# is quoted)
629 0 $line =~ s/\\#/#/g; # unslashify any \#
630 0 $line =~ s/^\s+//; # Trim leading & trailing whitespace
631 0 $line =~ s/\s+$//;
632 0 ▶ next unless $line; # if line isn't empty, after that.....
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
633 0 chomp($line);
634 0 ▶ if ($line =~ /(\S+)\s*=\s*(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /(\S+)\s*=\s*(.*)/) { } 0 0 0
635 0 ▶ my ($key, $value) = ($1, $2 || '');
Condition0%0/2
$2 || ''
l!l
00
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
636 0 $value =~ s/\s+$//;
637 # Special treatment for --path=$env:
638 0 ▶ if ($value =~ /^\$(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^\$(.+)$/) { } 0 0 0
639 0 my @values = ();
640 0 my $env_name = $1;
641 0 my $env_value;
642 # Allow $env/foo paths, starting with $env prefixes
643 0 ▶ if ($env_name =~ /^([^\/]+)(\/+)(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env_name =~ m[^([^/]+)(/+)(.+)$]) { } 0 0 0
644 0 my $trailer = $3;
645 0 ▶ if (my $env_path = $ENV{$1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $env_path = $ENV{$1}) 0 0 0
646 0 ▶ $env_path .= '/' unless $env_path =~ /\/$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $env_path =~ m[/$] 0 0 0
647 0 CORE::push @values, $env_path . $trailer; } }
648 else {
649 # But also the standard behaviour, where the $env is an array of paths
650 0 $env_value = $ENV{$env_name};
651 0 ▶ next unless $env_value;
Branch: 1 branch
BranchTrueFalseTotal
unless $env_value 0 0 0
652 0 @values = grep { -d $_ } reverse(split(':', $env_value));
653 0 ▶ next unless @values; }
Branch: 1 branch
BranchTrueFalseTotal
unless @values 0 0 0
654 0 CORE::push(@$opts, "--$key=$_") foreach (@values); }
655 else {
656 0 ▶ $value = $value ? "=$value" : '';
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
657 0 CORE::push @$opts, "--$key" . $value; } }
658 else {
659 0 Warning('unexpected', $line, undef,
660 "Unrecognized configuration data '$line'"); }
661 }
662 0 close $OPT;
663 #### ProgressSpindown("Loading profile $file");
664 0 return $opts; }
665  
666 5 1;
667  
668 __END__
« lib/LaTeXML/MathGrammar.pm ↑ Summary lib/LaTeXML/Post/MathML.pm »