lib/LaTeXML/Core/Definition/CharDef.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 74 CC 2 SCAR 9.3
CC
2
Cov
0%
invoke
6.0
new
2.0
valueOf
2.0
CRAP 2.5
1 # /=====================================================================\ #
2 # | LaTeXML::Core::Definition::CharDef | #
3 # | Representation of definitions of 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 package LaTeXML::Core::Definition::CharDef;
13 use strict;
14 use warnings;
15 use LaTeXML::Global;
16 use LaTeXML::Common::Object;
17 use LaTeXML::Common::Error;
18 use LaTeXML::Core::Token;
19 use LaTeXML::Core::Tokens;
20 use LaTeXML::Core::Box;
21 use base qw(LaTeXML::Core::Definition::Register);
22  
23 # A CharDef is a specialized register;
24 # You can't assign it; when you invoke the control sequence, it returns
25 # the result of evaluating the character (more like a regular primitive).
26 # When $mathglyph is provided, it is the unicode corresponding to the \mathchar of $value
27 sub new {
28 my ($class, $cs, $value, $mathglyph, %traits) = @_;
29 return bless { cs => $cs, parameters => undef,
30 value => $value, mathglyph => $mathglyph,
31 registerType => 'Number', readonly => 1,
32 locator => $STATE->getStomach->getGullet->getMouth->getLocator,
33 %traits }, $class; }
34  
35 sub valueOf {
36 my ($self) = @_;
37 return $$self{value}; }
38  
39 sub setValue {
40 my ($self, $value, $scope) = @_;
41 Error('unexpected', $self, undef, "Can't assign to chardef " . $self->getCSName);
42 return; }
43  
44 sub invoke {
45 my ($self, $stomach) = @_;
46 my $value = $$self{value};
47 my $mathglyph = $$self{mathglyph};
48 # A dilemma: If the \chardef were in a style file, you're prefer to revert to the $cs
49 # but if defined in the document source, better to use \char ###\relax, so it still "works"
50 if (defined $mathglyph) { # Must be a math char
51 return Box($mathglyph, undef, undef,
52 Tokens(T_CS('\mathchar'), $value->revert, T_CS('\relax')),
53 role => $$self{role}); }
54 else { # else text; but note defered font/encoding till digestion!
55 return Box(LaTeXML::Package::FontDecode($value->valueOf), undef, undef,
56 Tokens(T_CS('\char'), $value->revert, T_CS('\relax'))); } }
57  
58 sub equals {
59 my ($self, $other) = @_;
60 return (defined $other)
61 && ((ref $self) eq (ref $other))
62 && ($$self{value}->valueOf == $$other{value}->valueOf); }
63 #===============================================================================
64 1;
65  
66 __END__