lib/LaTeXML/Core/List.pm

filter: Statementstmt 43.1% 38 / 88 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 32 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 57.1% 12 / 21 Podpod 66.6% 6 / 9 totaltotal 30.1% 56 / 186 CC 21 SCAR 35.2
CC
21
Cov
28%
new
72.0
List
56.0
equals
56.0
CRAP 33.8
« lib/LaTeXML/Core/KeyVal.pm ↑ Summary lib/LaTeXML/Common/Color/rgb.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 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use LaTeXML::Common::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use LaTeXML::Common::Dimension;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use List::Util qw(min max);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use base qw(Exporter LaTeXML::Core::Box);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 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 0 ▶sub List {
Subroutine List: not called CC=7 SCAR=40.3
Pod undocumented
32 0 my (@boxes) = @_;
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 0 ▶sub new {
Subroutine new: not called CC=8 SCAR=42.8
Pod undocumented
47 0 my ($class, @boxes) = @_;
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 0 ▶sub unlist {
Subroutine unlist: not called CC=1 SCAR=6.9
Pod documented
62 0 my ($self) = @_;
63 0 return @{ $$self{boxes} }; }
64  
65 0 ▶sub revert {
Subroutine revert: not called CC=1 SCAR=1.2
Pod documented
66 5 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
67 0 my ($self) = @_;
68 0 return map { $_->revert } $self->unlist; }
69  
70 0 ▶sub toString {
Subroutine toString: not called CC=1 SCAR=6.9
Pod documented
71 0 my ($self) = @_;
72 0 return join('', grep { defined $_ } map { $_->toString } $self->unlist); }
73  
74 # Methods for overloaded operators
75 0 ▶sub stringify {
Subroutine stringify: not called CC=1 SCAR=2.2
Pod documented
76 5 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
77 0 my ($self) = @_;
78 0 my $type = ref $self;
79 0 $type =~ s/^LaTeXML:://;
80 0 return $type . '[' . join(',', map { Stringify($_) } $self->unlist) . ']'; } # Not ideal, but....
81  
82 0 ▶sub equals {
Subroutine equals: not called CC=7 SCAR=40.3
Pod documented
83 0 my ($a, $b) = @_;
84 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
85 0 my @a = $a->unlist;
86 0 my @b = $b->unlist;
87 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
88 0 shift(@a); shift(@b); }
89 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
90  
91 # NOTE: No longer used; Document->absorb bypasses this for stack efficiency.
92 0 ▶sub beAbsorbed {
Subroutine beAbsorbed: not called CC=1 SCAR=1.2
Pod documented
93 0 my ($self, $document) = @_;
94 5 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
95 0 return map { $document->absorb($_) } $self->unlist; }
96  
97 0 ▶sub computeSize {
Subroutine computeSize: not called CC=2 SCAR=11.6
Pod undocumented
98 5 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
99 0 my ($self, %options) = @_;
100 0 ▶ my $font = $self->getProperty('font') || LaTeXML::Common::Font->textDefault;
Condition0%0/3
$self->getProperty('font') || 'LaTeXML::Common::Font'->textDefault
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->getProperty('font') || 'LaTeXML::Common::Font'->textDefault
$self->getProperty('font') 'LaTeXML::Common::Font'->textDefault
Truth table0%0/3
A || B
A= $self->getProperty('font')B= 'LaTeXML::Common::Font'->textDefault
ABresult
1X1
011
000
101 0 return $font->computeBoxesSize($$self{boxes}, %options); }
102  
103 #======================================================================
104 5 1;
105  
106 __END__
« lib/LaTeXML/Core/KeyVal.pm ↑ Summary lib/LaTeXML/Common/Color/rgb.pm »