lib/LaTeXML/Core/Parameter.pm

filter: Statementstmt 21.3% 25 / 117 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 44 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 42.1% 8 / 19 Podpod 11.1% 1 / 9 totaltotal 11.9% 34 / 285 CC 51 SCAR 47.5
CC
51
Cov
11%
new
306.0
read
132.0
digest
90.0
CRAP 115.7
« lib/LaTeXML/Common/Model/RelaxNG.pm ↑ Summary lib/LaTeXML/Core/KeyVals.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 sub new {
31 0 ▶ my ($class, $type, $spec, %options) = @_;
Subroutine new: not called CC=17 SCAR=57.2
Pod undocumented
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 sub checkReaderFunction {
57 0 ▶ my ($function) = @_;
Subroutine checkReaderFunction: not called CC=3 SCAR=24.8
Pod undocumented
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 sub stringify {
64 0 ▶ my ($self) = @_;
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
65 0 return $$self{spec}; }
66  
67 sub setupCatcodes {
68 0 ▶ my ($self) = @_;
Subroutine setupCatcodes: not called CC=2 SCAR=17.9
Pod undocumented
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 sub revertCatcodes {
74 0 ▶ my ($self) = @_;
Subroutine revertCatcodes: not called CC=2 SCAR=17.9
Pod undocumented
75 0 ▶ if ($$self{semiverbatim}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"semiverbatim"}) 0 0 0
76 0 $STATE->endSemiverbatim(); }
77 0 return; }
78  
79 sub read {
80 0 ▶ my ($self, $gullet, $fordefn) = @_;
Subroutine read: not called CC=11 SCAR=48.8
Pod undocumented
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  
88 0 ▶ my $value = &{ $$self{reader} }($gullet, @{ $$self{extra} || [] });
Branch: 1 branch
BranchTrueFalseTotal
$self->{"extra"} or [] 0 0 0
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 ▶ $value = $value->packParameters if $value && $$self{packParameters};
Branch: 1 branch
BranchTrueFalseTotal
if $value and $self->{"packParameters"} 0 0 0
Condition0%0/3
$value and $self->{"packParameters"}
!ll&&!rl&&r
000
MC/DC0%0/2
$value and $self->{"packParameters"}
$value $self->{"packParameters"}
Truth table0%0/3
A and B
A= $valueB= $self->{"packParameters"}
ABresult
0X0
100
111
92 0 ▶ if ($$self{semiverbatim}) { # Open coded revertCatcodes
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"semiverbatim"}) 0 0 0
93 0 $STATE->endSemiverbatim(); }
94 0 ▶ if ((!defined $value) && !$$self{optional}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value or $self->{"optional"}) 0 0 0
Condition0%0/3
defined $value or $self->{"optional"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $value or $self->{"optional"}
defined $value $self->{"optional"}
Truth table0%0/3
A or B
A= defined $valueB= $self->{"optional"}
ABresult
1X1
011
000
95 0 Error('expected', $self, $gullet,
96 "Missing argument " . Stringify($self) . " for " . Stringify($fordefn),
97 "Ended at " . ToString($gullet->getLocator));
98 0 $value = T_OTHER('missing'); }
99 0 return $value; }
100  
101 # This is needed by structured parameter types like KeyVals
102 # where the argument may already have been tokenized before the KeyVals
103 # (and the parameter types for the keys) had a chance to properly parse.
104 # Yuck!
105 sub reparse {
106 0 ▶ my ($self, $gullet, $tokens) = @_;
Subroutine reparse: not called CC=6 SCAR=37.4
Pod undocumented
107 # Needs neutralization, since the keyvals may have been tokenized already???
108 # perhaps a better test would involve whether $tokens is, in fact, Tokens?
109 0 ▶ $tokens = $tokens->packParameters if $tokens && $$self{packParameters};
Branch: 1 branch
BranchTrueFalseTotal
if $tokens and $self->{"packParameters"} 0 0 0
Condition0%0/3
$tokens and $self->{"packParameters"}
!ll&&!rl&&r
000
MC/DC0%0/2
$tokens and $self->{"packParameters"}
$tokens $self->{"packParameters"}
Truth table0%0/3
A and B
A= $tokensB= $self->{"packParameters"}
ABresult
0X0
100
111
110 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
111 0 return $tokens; }
112 elsif ($$self{semiverbatim}) { # Needs neutralization
113 0 return $tokens->neutralize(@{ $$self{semiverbatim} }); } # but maybe specific to catcodes
114 else {
115 return $gullet->readingFromMouth(LaTeXML::Core::Mouth->new(), sub { # start with empty mouth
116 0 ▶ my ($gulletx) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
117 0 my @tokens = $tokens->unlist;
118 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]->equals(bless( ["{",1], 'LaTeXML::Core::Token' )) and $tokens[-1]->equals(bless( ["}",2], 'LaTeXML::Core::Token' ))) 0 0 0
Condition0%0/9
@tokens and $self->{"type"} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/ and $tokens[0]->equals(bless( ["{",1], 'LaTeXML::Core::Token' )) and $tokens[-1]->equals(bless( ["}",2], 'LaTeXML::Core::Token' ))
!ll&&!rl&&r
000
@tokens and $self->{"type"} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/ and $tokens[0]->equals(bless( ["{",1], 'LaTeXML::Core::Token' ))
!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]->equals(bless( ["{",1], 'LaTeXML::Core::Token' )) and $tokens[-1]->equals(bless( ["}",2], 'LaTeXML::Core::Token' ))
@tokens $self->{"type"} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/ $tokens[0]->equals(bless( ["{",1], 'LaTeXML::Core::Token' )) $tokens[-1]->equals(bless( ["}",2], 'LaTeXML::Core::Token' ))
Truth table0%0/5
A and B and C and D
A= @tokensB= $self->{"type"} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/C= $tokens[0]->equals(bless( ["{",1], 'LaTeXML::Core::Token' ))D= $tokens[-1]->equals(bless( ["}",2], 'LaTeXML::Core::Token' ))
ABCDresult
0XXX0
10XX0
110X0
11100
11111
119 && ($$self{type} =~ /^(?:Number|Dimension|Glue|MuDimension|MuGlue)$/)
120 && $tokens[0]->equals(T_BEGIN) && $tokens[-1]->equals(T_END)) {
121 0 shift(@tokens); pop(@tokens); }
122 0 $gulletx->unread(@tokens); # but put back tokens to be read
123 0 my $value = $self->read($gulletx);
124 0 $gulletx->skipSpaces;
125 0 return $value; }); } }
126  
127 sub digest {
128 0 ▶ my ($self, $stomach, $value, $fordefn) = @_;
Subroutine digest: not called CC=9 SCAR=45.0
Pod undocumented
129 # If semiverbatim, Expand (before digest), so tokens can be neutralized; BLECH!!!!
130 0 ▶ if ($$self{semiverbatim}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"semiverbatim"}) 0 0 0
131 0 $STATE->beginSemiverbatim(@{ $$self{semiverbatim} });
132 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
133 $stomach->getGullet->readingFromMouth(LaTeXML::Core::Mouth->new(), sub {
134 0 ▶ my ($igullet) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
135 0 $igullet->unread($value);
136 0 my @tokens = ();
137 0 ▶ while (defined(my $token = $igullet->readXToken(1, 1))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = $igullet->readXToken(1, 1))) 0 0 0
138 0 push(@tokens, $token); }
139 0 $value = Tokens(@tokens);
140 0 $value = $value->neutralize; }); } }
141 0 ▶ if (my $pre = $$self{beforeDigest}) { # Done for effect only.
Branch: 1 branch
BranchTrueFalseTotal
if (my $pre = $self->{"beforeDigest"}) 0 0 0
142 0 &$pre($stomach); } # maybe pass extras?
143 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
144 0 ▶ if (my $post = $$self{afterDigest}) { # Done for effect only.
Branch: 1 branch
BranchTrueFalseTotal
if (my $post = $self->{"afterDigest"}) 0 0 0
145 0 &$post($stomach); } # maybe pass extras?
146 0 ▶ $STATE->endSemiverbatim() if $$self{semiverbatim}; # Corner case?
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"semiverbatim"} 0 0 0
147 0 return $value; }
148  
149 sub revert {
150 0 ▶ my ($self, $value) = @_;
Subroutine revert: not called CC=3 SCAR=24.8
Pod undocumented
151 0 ▶ if (my $reverter = $$self{reversion}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reverter = $self->{'reversion'}) { } 0 0 0
152 0 ▶ return &$reverter($value, @{ $$self{extra} || [] }); }
Branch: 1 branch
BranchTrueFalseTotal
$self->{"extra"} or [] 0 0 0
153 else {
154 0 return Revert($value); } }
155  
156 #======================================================================
157 5 1;
158  
159 __END__
« lib/LaTeXML/Common/Model/RelaxNG.pm ↑ Summary lib/LaTeXML/Core/KeyVals.pm »