lib/LaTeXML/Core/List.pm

filter: Statementstmt 33.7% 29 / 86 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 32 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 50.0% 9 / 18 Podpod 66.6% 6 / 9 totaltotal 22.8% 44 / 193 CC 27 SCAR 37.9
CC
27
Cov
20%
new
72.0
computeSize
72.0
List
56.0
CRAP 44.4
« lib/LaTeXML/Post/XSLT.pm ↑ Summary lib/LaTeXML/Post/OpenMath.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Core::List | #
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 package LaTeXML::Core::List;
13 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use LaTeXML::Common::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use LaTeXML::Common::Dimension;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use List::Util qw(min max);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use base qw(Exporter LaTeXML::Core::Box);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 our @EXPORT = (qw(&List));
22  
23 # Tricky; don't really want a separate constructor for a Math List,
24 # but you really have to specify it in the arguments
25 # BUT you can't infer the mode from the current state ($STATE may have already switched
26 # back to text) or from the modes of the boxes (may be mixed)
27 # So, it has to be specified along with the boxes;
28 # Here we simply allow
29 # List($box,.... mode=>'math')
30 # Also, if there's only 1 box, we just return it!
31 sub List {
32 0 ▶ my (@boxes) = @_;
Subroutine List: not called CC=7 SCAR=40.3
Pod undocumented
33 0 my $mode = 'text';
34 # Hacky special case!!!
35 0 ▶ if ((scalar(@boxes) >= 2) && ($boxes[-2] eq 'mode')
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @boxes >= 2 and $boxes[-2] eq "mode" and $boxes[-1] eq "math" || $boxes[-1] eq "text") 0 0 0
Condition0%0/9
scalar @boxes >= 2 and $boxes[-2] eq "mode" and $boxes[-1] eq "math" || $boxes[-1] eq "text"
!ll&&!rl&&r
000
scalar @boxes >= 2 and $boxes[-2] eq "mode"
!ll&&!rl&&r
000
$boxes[-1] eq "math" or $boxes[-1] eq "text"
l!l&&r!l&&!r
000
MC/DC0%0/4
scalar @boxes >= 2 and $boxes[-2] eq "mode" and $boxes[-1] eq "math" || $boxes[-1] eq "text"
scalar @boxes >= 2 $boxes[-2] eq "mode" $boxes[-1] eq "math" $boxes[-1] eq "text"
Truth table0%0/5
A and B and C or D
A= scalar @boxes >= 2B= $boxes[-2] eq "mode"C= $boxes[-1] eq "math"D= $boxes[-1] eq "text"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
36 && (($boxes[-1] eq 'math') || ($boxes[-1] eq 'text'))) {
37 0 $mode = pop(@boxes); pop(@boxes); }
38 0 @boxes = grep { defined $_ } @boxes; # strip out undefs
39 0 ▶ if (scalar(@boxes) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @boxes == 1) { } 0 0 0
40 0 return $boxes[0]; } # Simplify!
41 else {
42 0 my $list = LaTeXML::Core::List->new(@boxes);
43 0 ▶ $list->setProperty(mode => $mode) if $mode eq 'math';
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "math" 0 0 0
44 0 return $list; } }
45  
46 sub new {
47 0 ▶ my ($class, @boxes) = @_;
Subroutine new: not called CC=8 SCAR=42.8
Pod undocumented
48 0 my ($bx, $font, $locator);
49 0 my @bxs = @boxes;
50 0 ▶ while (defined($bx = shift(@bxs)) && (!defined $locator)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($bx = shift @bxs) and not defined $locator) 0 0 0
Condition0%0/3
defined($bx = shift @bxs) and not defined $locator
!ll&&!rl&&r
000
MC/DC0%0/2
defined($bx = shift @bxs) and not defined $locator
defined($bx = shift @bxs) not defined $locator
Truth table0%0/3
A and not(B)
A= defined($bx = shift @bxs)B= not defined $locator
ABresult
0X0
100
111
51 0 ▶ $locator = $bx->getLocator unless defined $locator; }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $locator 0 0 0
52 0 @bxs = @boxes;
53 # Maybe the most representative font for a List is the font of the LAST box (that _has_ a font!) ???
54 0 ▶ while (defined($bx = pop(@bxs)) && (!defined $font)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($bx = pop @bxs) and not defined $font) 0 0 0
Condition0%0/3
defined($bx = pop @bxs) and not defined $font
!ll&&!rl&&r
000
MC/DC0%0/2
defined($bx = pop @bxs) and not defined $font
defined($bx = pop @bxs) not defined $font
Truth table0%0/3
A and not(B)
A= defined($bx = pop @bxs)B= not defined $font
ABresult
0X0
100
111
55 0 ▶ $font = $bx->getFont unless defined $font; }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $font 0 0 0
56 #return bless [[@boxes], $font, $locator || '', undef, {}], $class; }
57 0 ▶ return bless { boxes => [@boxes],
Condition0%0/2
$locator || undef
l!l
00
MC/DC0%0/1
$locator || undef
$locator
Truth table0%0/2
A
A= $locator
Aresult
11
00
58 properties => { font => $font, locator => $locator || undef, }
59 }, $class; }
60  
61 sub unlist {
62 0 ▶ my ($self) = @_;
Subroutine unlist: not called CC=1 SCAR=6.9
Pod documented
63 0 return @{ $$self{boxes} }; }
64  
65 sub revert {
66 0 ▶ my ($self) = @_;
Subroutine revert: not called CC=1 SCAR=6.9
Pod documented
67 0 return map { $_->revert } $self->unlist; }
68  
69 sub toString {
70 0 ▶ my ($self) = @_;
Subroutine toString: not called CC=1 SCAR=6.9
Pod documented
71 0 return join('', grep { defined $_ } map { $_->toString } $self->unlist); }
72  
73 # Methods for overloaded operators
74 sub stringify {
75 0 ▶ my ($self) = @_;
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
76 0 my $type = ref $self;
77 0 $type =~ s/^LaTeXML:://;
78 0 return $type . '[' . join(',', map { Stringify($_) } $self->unlist) . ']'; } # Not ideal, but....
79  
80 sub equals {
81 0 ▶ my ($a, $b) = @_;
Subroutine equals: not called CC=7 SCAR=40.3
Pod documented
82 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
83 0 my @a = $a->unlist;
84 0 my @b = $b->unlist;
85 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
86 0 shift(@a); shift(@b); }
87 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
88  
89 # NOTE: No longer used; Document->absorb bypasses this for stack efficiency.
90 sub beAbsorbed {
91 0 ▶ my ($self, $document) = @_;
Subroutine beAbsorbed: not called CC=1 SCAR=1.2
Pod documented
92 4 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
93 0 return map { $document->absorb($_) } $self->unlist; }
94  
95 sub computeSize {
96 0 ▶ my ($self, %options) = @_;
Subroutine computeSize: not called CC=8 SCAR=42.8
Pod undocumented
97 0 my $props = $self->getPropertiesRef;
98 0 ▶ $options{width} = $$props{width} if $$props{width};
Branch: 1 branch
BranchTrueFalseTotal
if $props->{"width"} 0 0 0
99 0 ▶ $options{height} = $$props{height} if $$props{height};
Branch: 1 branch
BranchTrueFalseTotal
if $props->{"height"} 0 0 0
100 0 ▶ $options{depth} = $$props{depth} if $$props{depth};
Branch: 1 branch
BranchTrueFalseTotal
if $props->{"depth"} 0 0 0
101 my ($w, $h, $d) = ($$props{font} || LaTeXML::Common::Font->textDefault)
102 0 ▶ ->computeBoxesSize($$self{boxes}, %options);
Condition0%0/3
$props->{'font'} || 'LaTeXML::Common::Font'->textDefault
l!l&&r!l&&!r
000
MC/DC0%0/2
$props->{'font'} || 'LaTeXML::Common::Font'->textDefault
$props->{'font'} 'LaTeXML::Common::Font'->textDefault
Truth table0%0/3
A || B
A= $props->{'font'}B= 'LaTeXML::Common::Font'->textDefault
ABresult
1X1
011
000
103 0 ▶ $$props{width} = $w unless defined $$props{width};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $props->{"width"} 0 0 0
104 0 ▶ $$props{height} = $h unless defined $$props{height};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $props->{"height"} 0 0 0
105 0 ▶ $$props{depth} = $d unless defined $$props{depth};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $props->{"depth"} 0 0 0
106 0 return; }
107  
108 #======================================================================
109 4 1;
110  
111 __END__
« lib/LaTeXML/Post/XSLT.pm ↑ Summary lib/LaTeXML/Post/OpenMath.pm »