lib/LaTeXML/Core/Parameter.pm

filter: Statementstmt 25.4% 31 / 122 Branchbran 0.0% 0 / 64 Conditioncond 0.0% 0 / 51 MC/DCmcdc 0.0% 0 / 29 Subroutinesub 47.6% 10 / 21 Podpod 11.1% 1 / 9 totaltotal 14.1% 42 / 296 CC 51 SCAR 47.0
CC
51
Cov
13%
new
306.0
read
129.6
digest
75.2
CRAP 110.0
« lib/LaTeXML/Core/KeyVals.pm ↑ Summary lib/LaTeXML/Core/Definition/Constructor.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Core::Parameter | #
3 # | Representation of a single Parameter for Control Sequences | #
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 # | http://dlmf.nist.gov/LaTeXML/ (o o) | #
11 # \=========================================================ooo==U==ooo=/ #
12  
13 package LaTeXML::Core::Parameter;
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 LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use LaTeXML::Common::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use LaTeXML::Core::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use LaTeXML::Core::Tokens;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use base qw(LaTeXML::Common::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # sub new {
24 # my ($class, $spec, %options) = @_;
25 # return bless { spec => $spec, %options }, $class; }
26  
27 # Create a parameter reading object for a specific type.
28 # If either a declared entry or a function Read<Type> accessible from LaTeXML::Package::Pool
29 # is defined.
30 0 ▶sub new {
Subroutine new: not called CC=17 SCAR=57.2
Pod undocumented
31 0 my ($class, $type, $spec, %options) = @_;
32 0 my $descriptor = $STATE->lookupMapping('PARAMETER_TYPES', $type);
33 0 ▶ if (!defined $descriptor) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $descriptor) 0 0 0
34 0 ▶ if ($type =~ /^Optional(.+)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /^Optional(.+)$/) { } 0 0 0
elsif ($type =~ /^Skip(.+)$/) { } 0 0 0
35 0 my $basetype = $1;
36 0 ▶ if ($descriptor = $STATE->lookupMapping('PARAMETER_TYPES', $basetype)) { }
Branch: 2 branches
BranchTrueFalseTotal
if ($descriptor = $LaTeXML::Core::Parameter::STATE->lookupMapping('PARAMETER_TYPES', $basetype)) { } 0 0 0
elsif (my $reader = checkReaderFunction("Read$type") || checkReaderFunction("Read$basetype")) { } 0 0 0
37 ▶ elsif (my $reader = checkReaderFunction("Read$type") || checkReaderFunction("Read$basetype")) {
Condition0%0/3
checkReaderFunction("Read$type") || checkReaderFunction("Read$basetype")
l!l&&r!l&&!r
000
MC/DC0%0/2
checkReaderFunction("Read$type") || checkReaderFunction("Read$basetype")
checkReaderFunction("Read$type") checkReaderFunction("Read$basetype")
Truth table0%0/3
A || B
A= checkReaderFunction("Read$type")B= checkReaderFunction("Read$basetype")
ABresult
1X1
011
000
38 0 $descriptor = { reader => $reader }; }
39 0 ▶ $descriptor = { %$descriptor, optional => 1 } if $descriptor; }
Branch: 1 branch
BranchTrueFalseTotal
if $descriptor 0 0 0
40 elsif ($type =~ /^Skip(.+)$/) {
41 0 my $basetype = $1;
42 0 ▶ if ($descriptor = $STATE->lookupMapping('PARAMETER_TYPES', $basetype)) { }
Branch: 2 branches
BranchTrueFalseTotal
if ($descriptor = $LaTeXML::Core::Parameter::STATE->lookupMapping('PARAMETER_TYPES', $basetype)) { } 0 0 0
elsif (my $reader = checkReaderFunction($type) || checkReaderFunction("Read$basetype")) { } 0 0 0
43 ▶ elsif (my $reader = checkReaderFunction($type) || checkReaderFunction("Read$basetype")) {
Condition0%0/3
checkReaderFunction($type) || checkReaderFunction("Read$basetype")
l!l&&r!l&&!r
000
MC/DC0%0/2
checkReaderFunction($type) || checkReaderFunction("Read$basetype")
checkReaderFunction($type) checkReaderFunction("Read$basetype")
Truth table0%0/3
A || B
A= checkReaderFunction($type)B= checkReaderFunction("Read$basetype")
ABresult
1X1
011
000
44 0 $descriptor = { reader => $reader }; }
45 0 ▶ $descriptor = { %$descriptor, novalue => 1, optional => 1 } if $descriptor; }
Branch: 1 branch
BranchTrueFalseTotal
if $descriptor 0 0 0
46 else {
47 0 my $reader = checkReaderFunction("Read$type");
48 0 ▶ $descriptor = { reader => $reader } if $reader; } }
Branch: 1 branch
BranchTrueFalseTotal
if $reader 0 0 0
49 0 ▶ Fatal('misdefined', $type || 'no_type', undef, "Unrecognized parameter type in \"$spec\"") unless $descriptor;
Branch: 1 branch
BranchTrueFalseTotal
unless $descriptor 0 0 0
Condition0%0/2
$type || 'no_type'
l!l
00
MC/DC0%0/1
$type || 'no_type'
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
50 # Convert semiverbatim to list of extra SPECIALS.
51 0 my %data = (%{$descriptor}, %options);
52 0 ▶ $data{semiverbatim} = [] if $data{semiverbatim} && (ref $data{semiverbatim} ne 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if $data{"semiverbatim"} and ref $data{"semiverbatim"} ne "ARRAY" 0 0 0
Condition0%0/3
$data{"semiverbatim"} and ref $data{"semiverbatim"} ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$data{"semiverbatim"} and ref $data{"semiverbatim"} ne "ARRAY"
$data{"semiverbatim"} ref $data{"semiverbatim"} ne "ARRAY"
Truth table0%0/3
A and B
A= $data{"semiverbatim"}B= ref $data{"semiverbatim"} ne "ARRAY"
ABresult
0X0
100
111
53 0 return bless { spec => $spec, type => $type, %data }, $class; }
54  
55 # Check whether a reader function is accessible within LaTeXML::Package::Pool
56 0 ▶sub checkReaderFunction {
Subroutine checkReaderFunction: not called CC=3 SCAR=24.8
Pod undocumented
57 0 my ($function) = @_;
58 0 ▶ if (defined $LaTeXML::Package::Pool::{$function}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $LaTeXML::Package::Pool::{$function}) 0 0 0
59 0 local *reader = $LaTeXML::Package::Pool::{$function};
60 0 ▶ if (defined &reader) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &LaTeXML::Core::Parameter::reader) 0 0 0
61 0 return \&reader; } } }
62  
63 0 ▶sub stringify {
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
64 0 my ($self) = @_;
65 0 return $$self{spec}; }
66  
67 0 ▶sub setupCatcodes {
Subroutine setupCatcodes: not called CC=2 SCAR=17.9
Pod undocumented
68 0 my ($self) = @_;
69 0 ▶ if ($$self{semiverbatim}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"semiverbatim"}) 0 0 0
70 0 $STATE->beginSemiverbatim(@{ $$self{semiverbatim} }); }
71 0 return; }
72  
73 0 ▶sub revertCatcodes {
Subroutine revertCatcodes: not called CC=2 SCAR=17.9
Pod undocumented
74 0 my ($self) = @_;
75 0 ▶ if ($$self{semiverbatim}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"semiverbatim"}) 0 0 0
76 0 $STATE->endSemiverbatim(); }
77 0 return; }
78  
79 0 ▶sub read {
Subroutine read: not called CC=12 SCAR=48.6
Pod undocumented
80 0 my ($self, $gullet, $fordefn) = @_;
81 # For semiverbatim, I had messed with catcodes, but there are cases
82 # (eg. \caption(...\label{badchars}}) where you really need to
83 # cleanup after the fact!
84 # Hmmm, seem to still need it...
85 0 ▶ if ($$self{semiverbatim}) { # Open coded setupCatcodes
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"semiverbatim"}) 0 0 0
86 0 $STATE->beginSemiverbatim(@{ $$self{semiverbatim} }); }
87 5 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
88 0 ▶ my $value = &{ $$self{reader} }($gullet, @{ $$self{extra} || [] });
Condition0%0/2
$self->{'extra'} || []
l!l
00
MC/DC0%0/1
$self->{'extra'} || []
$self->{'extra'}
Truth table0%0/2
A
A= $self->{'extra'}
Aresult
11
00
89 0 ▶ $value = $value->neutralize(@{ $$self{semiverbatim} }) if $$self{semiverbatim} && (ref $value)
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"semiverbatim"} and ref $value and $value->can("neutralize") 0 0 0
Condition0%0/6
$self->{"semiverbatim"} and ref $value and $value->can("neutralize")
!ll&&!rl&&r
000
$self->{"semiverbatim"} and ref $value
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"semiverbatim"} and ref $value and $value->can("neutralize")
$self->{"semiverbatim"} ref $value $value->can("neutralize")
Truth table0%0/4
A and B and C
A= $self->{"semiverbatim"}B= ref $valueC= $value->can("neutralize")
ABCresult
0XX0
10X0
1100
1111
90 && $value->can('neutralize');
91 0 ▶ if ($$self{semiverbatim}) { # Open coded revertCatcodes
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"semiverbatim"}) 0 0 0
92 0 $STATE->endSemiverbatim(); }
93 0 ▶ if ((!defined $value) && !$$self{optional}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $value || $self->{'optional'}) { } 0 0 0
elsif ($value and $self->{'optional'} and $self->{'type'} =~ /^OptionalMatch/) { } 0 0 0
Condition0%0/3
defined $value || $self->{'optional'}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $value || $self->{'optional'}
defined $value $self->{'optional'}
Truth table0%0/3
A || B
A= defined $valueB= $self->{'optional'}
ABresult
1X1
011
000
94 0 Error('expected', $self, $gullet,
95 "Missing argument " . Stringify($self) . " for " . Stringify($fordefn),
96 "Ended at " . ToString($gullet->getLocator));
97 0 $value = T_OTHER('missing'); }
98 ▶ elsif ($value && $$self{optional} && $$self{type} =~ /^OptionalMatch/) {
Condition0%0/6
$value and $self->{"optional"} and $self->{"type"} =~ /^OptionalMatch/
!ll&&!rl&&r
000
$value and $self->{"optional"}
!ll&&!rl&&r
000
MC/DC0%0/3
$value and $self->{"optional"} and $self->{"type"} =~ /^OptionalMatch/
$value $self->{"optional"} $self->{"type"} =~ /^OptionalMatch/
Truth table0%0/4
A and B and C
A= $valueB= $self->{"optional"}C= $self->{"type"} =~ /^OptionalMatch/
ABCresult
0XX0
10X0
1100
1111
99 # experiment: skip spaces after a successful OptionalMatch read
100 0 $gullet->skipSpaces; }
101 0 return $value; }
102  
103 # This is needed by structured parameter types like KeyVals
104 # where the argument may already have been tokenized before the KeyVals
105 # (and the parameter types for the keys) had a chance to properly parse.
106 # Yuck!
107 0 ▶sub reparse {
Subroutine reparse: not called CC=4 SCAR=30.0
Pod undocumented
108 0 my ($self, $gullet, $tokens) = @_;
109 # Needs neutralization, since the keyvals may have been tokenized already???
110 # perhaps a better test would involve whether $tokens is, in fact, Tokens?
111 0 ▶ if (($$self{type} eq 'Plain') || $$self{undigested}) { # Gack!
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'type'} eq 'Plain' or $self->{'undigested'}) { } 0 0 0
elsif ($self->{'semiverbatim'}) { } 0 0 0
Condition0%0/3
$self->{"type"} eq "Plain" or $self->{"undigested"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"type"} eq "Plain" or $self->{"undigested"}
$self->{"type"} eq "Plain" $self->{"undigested"}
Truth table0%0/3
A or B
A= $self->{"type"} eq "Plain"B= $self->{"undigested"}
ABresult
1X1
011
000
112 0 return $tokens; }
113 elsif ($$self{semiverbatim}) { # Needs neutralization
114 0 return $tokens->neutralize(@{ $$self{semiverbatim} }); } # but maybe specific to catcodes
115 else {
116 0 ▶ return $gullet->readingFromMouth(LaTeXML::Core::Mouth->new(), sub { # start with empty mouth
Subroutine __ANON__: not called CC=5 SCAR=34.0
117 0 my ($gulletx) = @_;
118 0 my @tokens = $tokens->unlist;
119 0 ▶ if (@tokens # Strip outer braces from dimensions & friends
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens and $self->{"type"} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/ and $tokens[0]->getCatcode == 1 and $tokens[-1]->getCatcode == 2) 0 0 0
Condition0%0/9
@tokens and $self->{"type"} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/ and $tokens[0]->getCatcode == 1 and $tokens[-1]->getCatcode == 2
!ll&&!rl&&r
000
@tokens and $self->{"type"} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/ and $tokens[0]->getCatcode == 1
!ll&&!rl&&r
000
@tokens and $self->{"type"} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/
!ll&&!rl&&r
000
MC/DC0%0/4
@tokens and $self->{"type"} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/ and $tokens[0]->getCatcode == 1 and $tokens[-1]->getCatcode == 2
@tokens $self->{"type"} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/ $tokens[0]->getCatcode == 1 $tokens[-1]->getCatcode == 2
Truth table0%0/5
A and B and C and D
A= @tokensB= $self->{"type"} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/C= $tokens[0]->getCatcode == 1D= $tokens[-1]->getCatcode == 2
ABCDresult
0XXX0
10XX0
110X0
11100
11111
120 && ($$self{type} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/)
121 && ($tokens[0]->getCatcode == CC_BEGIN) && ($tokens[-1]->getCatcode == CC_END)) {
122 0 shift(@tokens); pop(@tokens); }
123 0 $gulletx->unread(@tokens); # but put back tokens to be read
124 0 my $value = $self->read($gulletx);
125 0 $gulletx->skipSpaces;
126 0 return $value; }); } }
127  
128 0 ▶sub digest {
Subroutine digest: not called CC=9 SCAR=43.2
Pod undocumented
129 5 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
130 0 my ($self, $stomach, $value, $fordefn) = @_;
131 # If semiverbatim, Expand (before digest), so tokens can be neutralized; BLECH!!!!
132 0 ▶ if ($$self{semiverbatim}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"semiverbatim"}) 0 0 0
133 0 $STATE->beginSemiverbatim(@{ $$self{semiverbatim} });
134 0 ▶ if ((ref $value eq 'LaTeXML::Core::Token') || (ref $value eq 'LaTeXML::Core::Tokens')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "LaTeXML::Core::Token" or ref $value eq "LaTeXML::Core::Tokens") 0 0 0
Condition0%0/3
ref $value eq "LaTeXML::Core::Token" or ref $value eq "LaTeXML::Core::Tokens"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $value eq "LaTeXML::Core::Token" or ref $value eq "LaTeXML::Core::Tokens"
ref $value eq "LaTeXML::Core::Token" ref $value eq "LaTeXML::Core::Tokens"
Truth table0%0/3
A or B
A= ref $value eq "LaTeXML::Core::Token"B= ref $value eq "LaTeXML::Core::Tokens"
ABresult
1X1
011
000
135 0 ▶ $stomach->getGullet->readingFromMouth(LaTeXML::Core::Mouth->new(), sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
136 0 my ($igullet) = @_;
137 0 $igullet->unread($value);
138 0 my @tokens = ();
139 0 ▶ while (defined(my $token = $igullet->getPendingComment || $igullet->readXToken(1))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = $igullet->getPendingComment || $igullet->readXToken(1))) 0 0 0
Condition0%0/3
$igullet->getPendingComment || $igullet->readXToken(1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$igullet->getPendingComment || $igullet->readXToken(1)
$igullet->getPendingComment $igullet->readXToken(1)
Truth table0%0/3
A || B
A= $igullet->getPendingCommentB= $igullet->readXToken(1)
ABresult
1X1
011
000
140 0 push(@tokens, $token); }
141 0 $value = Tokens(@tokens);
142 0 $value = $value->neutralize; }); } }
143 0 ▶ if (my $pre = $$self{beforeDigest}) { # Done for effect only.
Branch: 1 branch
BranchTrueFalseTotal
if (my $pre = $self->{"beforeDigest"}) 0 0 0
144 0 &$pre($stomach); } # maybe pass extras?
145 0 ▶ $value = $value->beDigested($stomach) if (ref $value) && !$$self{undigested};
Branch: 1 branch
BranchTrueFalseTotal
if ref $value and not $self->{"undigested"} 0 0 0
Condition0%0/3
ref $value and not $self->{"undigested"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and not $self->{"undigested"}
ref $value not $self->{"undigested"}
Truth table0%0/3
A and not(B)
A= ref $valueB= not $self->{"undigested"}
ABresult
0X0
100
111
146 0 ▶ if (my $post = $$self{afterDigest}) { # Done for effect only.
Branch: 1 branch
BranchTrueFalseTotal
if (my $post = $self->{"afterDigest"}) 0 0 0
147 0 &$post($stomach); } # maybe pass extras?
148 0 ▶ $STATE->endSemiverbatim() if $$self{semiverbatim}; # Corner case?
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"semiverbatim"} 0 0 0
149 0 return $value; }
150  
151 0 ▶sub revert {
Subroutine revert: not called CC=3 SCAR=24.8
Pod undocumented
152 0 my ($self, $value) = @_;
153 0 ▶ if (my $reverter = $$self{reversion}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reverter = $self->{'reversion'}) { } 0 0 0
154 0 ▶ return &$reverter($value, @{ $$self{extra} || [] }); }
Condition0%0/2
$self->{'extra'} || []
l!l
00
MC/DC0%0/1
$self->{'extra'} || []
$self->{'extra'}
Truth table0%0/2
A
A= $self->{'extra'}
Aresult
11
00
155 else {
156 0 return Revert($value); } }
157  
158 #======================================================================
159 5 1;
160  
161 __END__
« lib/LaTeXML/Core/KeyVals.pm ↑ Summary lib/LaTeXML/Core/Definition/Constructor.pm »