lib/LaTeXML/Core/Whatsit.pm

filter: Statementstmt 24.6% 37 / 150 Branchbran 0.0% 0 / 82 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 40.0% 12 / 30 Podpod 88.8% 16 / 18 totaltotal 19.8% 65 / 327 CC 53 SCAR 51.3
CC
53
Cov
14%
computeSize
380.0
revert
306.0
equals
110.0
CRAP 168.4
« lib/LaTeXML/Post/MathML/Linebreaker.pm ↑ Summary lib/LaTeXML/Common/Object.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Core::Whatsit | #
3 # | Digested objects produced in the Stomach | #
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 # LaTeXML Whatsit.
14 # Some arbitrary object, possibly with arguments.
15 # Particularly as an intermediate representation for invocations of control
16 # sequences that do NOT get expanded or processed, but are taken to represent
17 # some semantic something or other.
18 # These get preserved in the expanded/processed token stream to be
19 # converted into XML objects in the document.
20 #**********************************************************************
21 package LaTeXML::Core::Whatsit;
22 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use LaTeXML::Common::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use LaTeXML::Common::Locator;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 ▶use LaTeXML::Core::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 4 ▶use LaTeXML::Core::Tokens;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 4 ▶use LaTeXML::Common::Dimension;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 4 ▶use List::Util qw(min max);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 4 ▶use LaTeXML::Core::List;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 4 ▶use base qw(LaTeXML::Core::Box);
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 # Specially recognized (some required?) properties:
36 # font : The font object
37 # locator : a locator object, where in the source this whatsit was created
38 # isMath : whether this is a math object
39 # id
40 # body
41 # trailer
42 sub new {
43 0 ▶ my ($class, $defn, $args, %properties) = @_;
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
44 0 ▶ return bless { definition => $defn, args => $args || [], properties => {%properties} }, $class; }
Condition0%0/2
$args || []
l!l
00
MC/DC0%0/1
$args || []
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
45  
46 sub getDefinition {
47 0 ▶ my ($self) = @_;
Subroutine getDefinition: not called CC=1 SCAR=6.9
Pod documented
48 0 return $$self{definition}; }
49  
50 sub isMath {
51 0 ▶ my ($self) = @_;
Subroutine isMath: not called CC=1 SCAR=6.9
Pod documented
52 0 return $$self{properties}{isMath}; }
53  
54 sub getProperty {
55 0 ▶ my ($self, $key) = @_;
Subroutine getProperty: not called CC=1 SCAR=6.9
Pod documented
56 0 return $$self{properties}{$key}; }
57  
58 sub getArg {
59 0 ▶ my ($self, $n) = @_;
Subroutine getArg: not called CC=1 SCAR=6.9
Pod documented
60 0 return $$self{args}[$n - 1]; }
61  
62 sub getArgs {
63 0 ▶ my ($self) = @_;
Subroutine getArgs: not called CC=1 SCAR=6.9
Pod documented
64 0 return @{ $$self{args} }; }
65  
66 sub setArgs {
67 0 ▶ my ($self, @args) = @_;
Subroutine setArgs: not called CC=1 SCAR=6.9
Pod documented
68 0 $$self{args} = [@args];
69 0 return; }
70  
71 sub getBody {
72 0 ▶ my ($self) = @_;
Subroutine getBody: not called CC=1 SCAR=6.9
Pod documented
73 0 return $$self{properties}{body}; }
74  
75 sub setBody {
76 0 ▶ my ($self, @body) = @_;
Subroutine setBody: not called CC=5 SCAR=34.0
Pod documented
77 0 my $trailer = pop(@body);
78 0 $$self{properties}{body} = List(@body);
79 0 ▶ $$self{properties}{body}->setProperty(mode => 'math') if $self->isMath;
Branch: 1 branch
BranchTrueFalseTotal
if $self->isMath 0 0 0
80 0 $$self{properties}{trailer} = $trailer;
81 # And copy any otherwise undefined properties from the trailer
82 0 ▶ if ($trailer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailer) 0 0 0
83 0 $$self{properties}{locator} = LaTeXML::Common::Locator->newRange($self->getLocator, $trailer->getLocator);
84 0 my %trailerhash = $trailer->getProperties;
85 0 foreach my $prop (keys %trailerhash) {
86 0 ▶ $$self{properties}{$prop} = $trailer->getProperty($prop) unless defined $$self{properties}{$prop}; } }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"properties"}{$prop} 0 0 0
87 0 return; }
88  
89 sub getTrailer {
90 0 ▶ my ($self) = @_;
Subroutine getTrailer: not called CC=1 SCAR=6.9
Pod documented
91 0 return $$self{properties}{trailer}; }
92  
93 # So a Whatsit can stand in for a List
94 sub unlist {
95 0 ▶ my ($self) = @_;
Subroutine unlist: not called CC=1 SCAR=6.9
Pod documented
96 0 return ($self); }
97  
98 sub revert {
99 0 ▶ my ($self) = @_;
Subroutine revert: not called CC=17 SCAR=57.2
Pod documented
100 # WARNING: Forbidden knowledge?
101 # (1) provide a means to get the RAW, internal markup that can (hopefully) be RE-digested
102 # this is needed for getting the numerator of \over into textstyle!
103 # (2) caching the reversion (which is a big performance boost)
104 0 ▶ if (my $saved = !$LaTeXML::REVERT_RAW
Branch: 2 branches
BranchTrueFalseTotal
if (my $saved = !$LaTeXML::REVERT_RAW && ($LaTeXML::DUAL_BRANCH ? $self->{'dual_reversion'}{$LaTeXML::DUAL_BRANCH} : $self->{'reversion'})) { } 0 0 0
$LaTeXML::DUAL_BRANCH ? : 0 0 0
Condition0%0/3
!$LaTeXML::REVERT_RAW && ($LaTeXML::DUAL_BRANCH ? $self->{'dual_reversion'}{$LaTeXML::DUAL_BRANCH} : $self->{'reversion'})
!ll&&!rl&&r
000
MC/DC0%0/2
!$LaTeXML::REVERT_RAW && ($LaTeXML::DUAL_BRANCH ? $self->{'dual_reversion'}{$LaTeXML::DUAL_BRANCH} : $self->{'reversion'})
!$LaTeXML::REVERT_RAW ($LaTeXML::DUAL_BRANCH ? $self->{'dual_reversion'}{$LaTeXML::DUAL_BRANCH} : $self->{'reversion'})
Truth table0%0/3
not(A) && B
A= !$LaTeXML::REVERT_RAWB= ($LaTeXML::DUAL_BRANCH ? $self->{'dual_reversion'}{$LaTeXML::DUAL_BRANCH} : $self->{'reversion'})
ABresult
0X0
100
111
105 && ($LaTeXML::DUAL_BRANCH
106 ? $$self{dual_reversion}{$LaTeXML::DUAL_BRANCH}
107 : $$self{reversion})) {
108 0 return $saved->unlist; }
109 else {
110 0 my $defn = $self->getDefinition;
111 0 ▶ my $spec = ($LaTeXML::REVERT_RAW ? undef : $defn->getReversionSpec);
Branch: 1 branch
BranchTrueFalseTotal
$LaTeXML::REVERT_RAW ? : 0 0 0
112 0 my @tokens = ();
113 0 ▶ if ((defined $spec) && (ref $spec eq 'CODE')) { # If handled by CODE, call it
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec and ref $spec eq 'CODE') { } 0 0 0
Condition0%0/3
defined $spec and ref $spec eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $spec and ref $spec eq "CODE"
defined $spec ref $spec eq "CODE"
Truth table0%0/3
A and B
A= defined $specB= ref $spec eq "CODE"
ABresult
0X0
100
111
114 0 @tokens = &$spec($self, $self->getArgs); }
115 else {
116 0 ▶ if (defined $spec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec) { } 0 0 0
117 0 ▶ @tokens = $spec->substituteParameters(map { Tokens(Revert($_)) } $self->getArgs)->unlist
Branch: 1 branch
BranchTrueFalseTotal
if $spec ne "" 0 0 0
118 if $spec ne ''; }
119 else {
120 0 ▶ my $alias = ($LaTeXML::REVERT_RAW ? undef : $defn->getAlias);
Branch: 1 branch
BranchTrueFalseTotal
$LaTeXML::REVERT_RAW ? : 0 0 0
121 0 ▶ if (defined $alias) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $alias) { } 0 0 0
122 0 ▶ push(@tokens, T_CS($alias)) if $alias ne ''; }
Branch: 1 branch
BranchTrueFalseTotal
if $alias ne "" 0 0 0
123 else {
124 0 push(@tokens, $defn->getCS); }
125 0 ▶ if (my $parameters = $defn->getParameters) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parameters = $defn->getParameters) 0 0 0
126 0 push(@tokens, $parameters->revertArguments($self->getArgs)); } }
127 0 ▶ if (defined(my $body = $self->getBody)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $body = $self->getBody)) 0 0 0
128 0 push(@tokens, Revert($body));
129 0 ▶ if (defined(my $trailer = $self->getTrailer)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $trailer = $self->getTrailer)) 0 0 0
130 0 push(@tokens, Revert($trailer)); } } }
131 # Now cache it, in case it's needed again
132 0 ▶ if ($LaTeXML::REVERT_RAW) { } # don't cache
Branch: 2 branches
BranchTrueFalseTotal
if ($LaTeXML::REVERT_RAW) { } 0 0 0
elsif ($LaTeXML::DUAL_BRANCH) { } 0 0 0
133 elsif ($LaTeXML::DUAL_BRANCH) {
134 0 $$self{dual_reversion}{$LaTeXML::DUAL_BRANCH} = Tokens(@tokens); }
135 else {
136 0 $$self{reversion} = Tokens(@tokens); }
137 0 return @tokens; } }
138  
139 sub toString {
140 0 ▶ my ($self) = @_;
Subroutine toString: not called CC=1 SCAR=6.9
Pod documented
141 0 return ToString(Tokens($self->revert)); } # What else??
142  
143 sub getString {
144 0 ▶ my ($self) = @_;
Subroutine getString: not called CC=1 SCAR=6.9
Pod documented
145 0 return $self->toString; } # Ditto?
146  
147 # Methods for overloaded operators
148 sub stringify {
149 0 ▶ my ($self) = @_;
Subroutine stringify: not called CC=2 SCAR=17.9
Pod documented
150 0 my $hasbody = defined $$self{properties}{body};
151 return "Whatsit[" . join(',', $self->getDefinition->getCS->getCSName,
152 0 ▶ map { Stringify($_) }
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'properties'}{'body'} ? : 0 0 0
153 $self->getArgs,
154 (defined $$self{properties}{body}
155 ? ($$self{properties}{body}, $$self{properties}{trailer})
156 0 : ()))
157 . "]"; }
158  
159 sub equals {
160 0 ▶ my ($a, $b) = @_;
Subroutine equals: not called CC=10 SCAR=47.0
Pod documented
161 0 ▶ return 0 unless (defined $b) && ((ref $a) eq (ref $b));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b and ref $a eq ref $b 0 0 0
Condition0%0/3
defined $b and ref $a eq ref $b
!ll&&!rl&&r
000
MC/DC0%0/2
defined $b and ref $a eq ref $b
defined $b ref $a eq ref $b
Truth table0%0/3
A and B
A= defined $bB= ref $a eq ref $b
ABresult
0X0
100
111
162 0 ▶ return 0 unless $$a{definition} eq $$b{definition}; # I think we want IDENTITY here, not ->equals
Branch: 1 branch
BranchTrueFalseTotal
unless $a->{"definition"} eq $b->{"definition"} 0 0 0
163 0 ▶ my @a = @{ $$a{args} }; push(@a, $$a{properties}{body}) if $$a{properties}{body};
Branch: 1 branch
BranchTrueFalseTotal
if $a->{"properties"}{"body"} 0 0 0
164 0 ▶ my @b = @{ $$b{args} }; push(@b, $$b{properties}{body}) if $$b{properties}{body};
Branch: 1 branch
BranchTrueFalseTotal
if $b->{"properties"}{"body"} 0 0 0
165 0 ▶ while (@a && @b && ($a[0]->equals($b[0]))) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and @b and $a[0]->equals($b[0])) 0 0 0
Condition0%0/6
@a and @b and $a[0]->equals($b[0])
!ll&&!rl&&r
000
@a and @b
!ll&&!rl&&r
000
MC/DC0%0/3
@a and @b and $a[0]->equals($b[0])
@a @b $a[0]->equals($b[0])
Truth table0%0/4
A and B and C
A= @aB= @bC= $a[0]->equals($b[0])
ABCresult
0XX0
10X0
1100
1111
166 0 shift(@a); shift(@b); }
167 0 ▶ return !(@a || @b); }
Condition0%0/3
@a || @b
l!l&&r!l&&!r
000
MC/DC0%0/2
@a || @b
@a @b
Truth table0%0/3
A || B
A= @aB= @b
ABresult
1X1
011
000
168  
169 sub beAbsorbed {
170 0 ▶ my ($self, $document) = @_;
Subroutine beAbsorbed: not called CC=4 SCAR=30.0
Pod documented
171 # Significant time is consumed here, and associated with a specific CS,
172 # so we should be profiling as well!
173 # Hopefully the csname is the same that was charged in the digestioned phase!
174 0 my $defn = $self->getDefinition;
175 0 ▶ my $profiled = $STATE->lookupValue('PROFILING') && $defn->getCS;
Condition0%0/3
$LaTeXML::Core::Whatsit::STATE->lookupValue('PROFILING') && $defn->getCS
!ll&&!rl&&r
000
MC/DC0%0/2
$LaTeXML::Core::Whatsit::STATE->lookupValue('PROFILING') && $defn->getCS
$LaTeXML::Core::Whatsit::STATE->lookupValue('PROFILING') $defn->getCS
Truth table0%0/3
A && B
A= $LaTeXML::Core::Whatsit::STATE->lookupValue('PROFILING')B= $defn->getCS
ABresult
0X0
100
111
176 0 ▶ LaTeXML::Core::Definition::startProfiling($profiled, 'absorb') if $profiled;
Branch: 1 branch
BranchTrueFalseTotal
if $profiled 0 0 0
177 0 my @result = $defn->doAbsorbtion($document, $self);
178 0 ▶ LaTeXML::Core::Definition::stopProfiling($profiled, 'absorb') if $profiled;
Branch: 1 branch
BranchTrueFalseTotal
if $profiled 0 0 0
179 0 return @result; }
180  
181 # See discussion in Box.pm
182 sub computeSize {
183 0 ▶ my ($self, %options) = @_;
Subroutine computeSize: not called CC=19 SCAR=59.4
Pod undocumented
184 # Use #body, if any, else ALL args !?!?!
185 # Eventually, possibly options like sizeFrom, or computeSize or....
186 0 my $defn = $self->getDefinition;
187 0 my $props = $self->getPropertiesRef;
188 0 my $sizer = $defn->getSizer;
189 0 my ($width, $height, $depth);
190 # If sizer is a function, call it
191 0 ▶ if (ref $sizer) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sizer) { } 0 0 0
192 0 ($width, $height, $depth) = &$sizer($self); }
193 else {
194 0 my @boxes = ();
195 0 ▶ if (!defined $sizer) { # Nothing specified? use #body if any, else sum all box args
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $sizer) { } 0 0 0
elsif ($sizer eq '0' or $sizer eq '') { } 0 0 0
elsif ($sizer =~ /^(#\w+)*$/) { } 0 0 0
196 @boxes = ($$self{properties}{body}
197 ? ($$self{properties}{body})
198 0 ▶ : (map { ((ref $_) && ($_->isaBox) ? $_->unlist : ()) } @{ $$self{args} })); }
Branch: 2 branches
BranchTrueFalseTotal
$self->{'properties'}{'body'} ? : 0 0 0
ref $_ && $_->isaBox ? : 0 0 0
Condition0%0/3
ref $_ and $_->isaBox
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ and $_->isaBox
ref $_ $_->isaBox
Truth table0%0/3
A and B
A= ref $_B= $_->isaBox
ABresult
0X0
100
111
199 ▶ elsif (($sizer eq '0') || ($sizer eq '')) { } # 0 size!
Condition0%0/3
$sizer eq 0 or $sizer eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
$sizer eq 0 or $sizer eq ""
$sizer eq 0 $sizer eq ""
Truth table0%0/3
A or B
A= $sizer eq 0B= $sizer eq ""
ABresult
1X1
011
000
200 elsif ($sizer =~ /^(#\w+)*$/) { # Else if of form '#digit' or '#prop', combine sizes
201 0 ▶ while ($sizer =~ s/^#(\w+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sizer =~ s/^#(\w+)//) 0 0 0
202 0 my $arg = $1;
203 0 ▶ push(@boxes, ($arg =~ /^\d+$/ ? $self->getArg($arg) : $$props{$arg})); } }
Branch: 1 branch
BranchTrueFalseTotal
$arg =~ /^\d+$/ ? : 0 0 0
204 else {
205 0 Warn('unexpected', $sizer, undef,
206 "Expected sizer to be a function, or arg or property specification, not '$sizer'"); }
207 0 my $font = $$props{font};
208 0 ▶ $options{width} = $$props{width} if $$props{width};
Branch: 1 branch
BranchTrueFalseTotal
if $props->{"width"} 0 0 0
209 0 ▶ $options{height} = $$props{height} if $$props{height};
Branch: 1 branch
BranchTrueFalseTotal
if $props->{"height"} 0 0 0
210 0 ▶ $options{depth} = $$props{depth} if $$props{depth};
Branch: 1 branch
BranchTrueFalseTotal
if $props->{"depth"} 0 0 0
211 0 ▶ $options{vattach} = $$props{vattach} if $$props{vattach};
Branch: 1 branch
BranchTrueFalseTotal
if $props->{"vattach"} 0 0 0
212 0 ▶ $options{layout} = $$props{layout} if $$props{layout};
Branch: 1 branch
BranchTrueFalseTotal
if $props->{"layout"} 0 0 0
213 0 ($width, $height, $depth) = $font->computeBoxesSize([@boxes], %options); }
214 # Now, only set the dimensions that weren't already set.
215 0 ▶ $$props{cwidth} = $width unless defined $$props{width};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $props->{"width"} 0 0 0
216 0 ▶ $$props{cheight} = $height unless defined $$props{height};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $props->{"height"} 0 0 0
217 0 ▶ $$props{cdepth} = $depth unless defined $$props{depth};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $props->{"depth"} 0 0 0
218 0 return; }
219  
220 #======================================================================
221 4 1;
222  
223 __END__
« lib/LaTeXML/Post/MathML/Linebreaker.pm ↑ Summary lib/LaTeXML/Common/Object.pm »