lib/LaTeXML/Core/Array.pm untested

filter: Statementstmt 0.0% 0 / 59 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 111 CC 11 SCAR 27.9
CC
11
Cov
0%
revert
42.0
toString
20.0
beDigested
12.0
CRAP 16.2
1 # /=====================================================================\ #
2 # | LaTeXML::Core::Array | #
3 # | Support for Lists or Arrays of digestable stuff for LaTeXML | #
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::Array;
13 use strict;
14 use warnings;
15 use LaTeXML::Global;
16 use LaTeXML::Common::Object;
17 use LaTeXML::Core::Parameter;
18 use base qw(LaTeXML::Common::Object);
19  
20 # This class represents (potentially) delimited lists of things;
21 # currently it does not cover the actual parameter type/parser, just the result,
22 # since there are a variety of syntaxes, commas or not, etc.
23  
24 # The following tokens (individual Token's or Tokens') describe how to revert the Array
25 # open,close and separator are the outermost delimiter and separator between items
26 # itemopen,itemclose are delimiters for each item -- If any
27 sub new {
28 my ($class, %options) = @_;
29 return bless { type => $options{type},
30 open => $options{open}, close => $options{close}, separator => $options{separator},
31 itemopen => $options{itemopen}, itemclose => $options{itemclose},
32 values => $options{values} }, $class; }
33  
34 sub getValue {
35 my ($self, $n) = @_;
36 return $$self{values}[$n]; }
37  
38 sub setValue {
39 my ($self, $n, $value) = @_;
40 return $$self{values}[$n] = $value; }
41  
42 sub getValues {
43 my ($self) = @_;
44 return @{ $$self{values} }; }
45  
46 sub beDigested {
47 my ($self, $stomach) = @_;
48 my @v = ();
49 my $type = $$self{type};
50 foreach my $item (@{ $$self{values} }) {
51 push(@v, ($type ? $type->digest($stomach, $item, undef) : ($item ? $item->beDigested($stomach) : $item))); }
52 return (ref $self)->new(open => $$self{open}, close => $$self{close}, separator => $$self{separator},
53 itemopen => $$self{itemopen}, itemclose => $$self{itemclose},
54 type => $$self{type}, values => [@v]); }
55  
56 sub revert {
57 my ($self) = @_;
58 my @tokens = ();
59 foreach my $item (@{ $$self{values} }) {
60 push(@tokens, $$self{separator}->unlist) if $$self{separator} && @tokens;
61 push(@tokens, $$self{itemopen}->unlist) if $$self{itemopen};
62 push(@tokens, Revert($item));
63 push(@tokens, $$self{itemclose}->unlist) if $$self{itemclose}; }
64 unshift(@tokens, $$self{open}->unlist) if $$self{open};
65 push(@tokens, $$self{close}->unlist) if $$self{close};
66 return @tokens; }
67  
68 sub unlist {
69 my ($self) = @_;
70 return @{ $$self{values} }; } # ????
71  
72 sub toString {
73 my ($self) = @_;
74 my $string = '';
75 $string = ToString($$self{open}) if $$self{open};
76 foreach my $item (@{ $$self{values} }) {
77 $string .= ToString($$self{separator}) if $string && $$self{separator};
78 $string .= ToString($item); }
79 $string .= ToString($$self{close}) if $$self{close};
80 return $string; }
81  
82 #======================================================================
83 1;
84  
85 __END__