lib/LaTeXML/Common/Error.pm

filter: Statementstmt 12.0% 35 / 290 Branchbran 0.0% 0 / 174 Conditioncond 0.0% 0 / 161 MC/DCmcdc 0.0% 0 / 86 Subroutinesub 21.2% 7 / 33 Podpod 34.6% 9 / 26 totaltotal 6.6% 51 / 770 CC 148 SCAR 53.7
CC
148
Cov
6%
generateMessage
756.0
Fatal
342.0
objectStack
240.0
CRAP 215.5
« lib/LaTeXML/Post/LaTeXImages.pm ↑ Summary lib/LaTeXML/Post/CrossRef.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Common::Error | #
3 # | Error handler | #
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::Common::Error;
13 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 29 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 29 ▶use LaTeXML::Common::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 29 ▶use Time::HiRes;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 29 ▶use Term::ANSIColor 2.01 qw(colored colorstrip);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 29 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 29 our @EXPORT = (
22 # Error Reporting
23 qw(&Fatal &Error &Warn &Info),
24 # Progress reporting
25 qw(&NoteProgress &NoteProgressDetailed &NoteBegin &NoteEnd),
26 # Colored-logging related functions
27 qw(&colorizeString),
28 # Status management
29 qw(&MergeStatus),
30 );
31  
32 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 # Color setup
34 29 $Term::ANSIColor::AUTORESET = 1;
35 29 our $COLORIZED_LOGGING = -t STDERR;
36  
37 29 our %color_scheme = (
38 details => 'bold',
39 success => 'green',
40 info => 'bright_blue', # bright only recently defined
41 warning => 'yellow',
42 error => 'bold red',
43 fatal => 'bold red underline',
44 );
45  
46 sub colorizeString {
47 0 ▶ my ($string, $alias) = @_;
Subroutine colorizeString: not called CC=3 SCAR=24.8
Pod undocumented
48 return ($COLORIZED_LOGGING && $color_scheme{$alias}
49 0 ▶ ? colored($string, $color_scheme{$alias})
Branch: 1 branch
BranchTrueFalseTotal
$LaTeXML::Common::Error::COLORIZED_LOGGING && $LaTeXML::Common::Error::color_scheme{$alias} ? : 0 0 0
Condition0%0/3
$LaTeXML::Common::Error::COLORIZED_LOGGING and $LaTeXML::Common::Error::color_scheme{$alias}
!ll&&!rl&&r
000
MC/DC0%0/2
$LaTeXML::Common::Error::COLORIZED_LOGGING and $LaTeXML::Common::Error::color_scheme{$alias}
$LaTeXML::Common::Error::COLORIZED_LOGGING $LaTeXML::Common::Error::color_scheme{$alias}
Truth table0%0/3
A and B
A= $LaTeXML::Common::Error::COLORIZED_LOGGINGB= $LaTeXML::Common::Error::color_scheme{$alias}
ABresult
0X0
100
111
50 : $string); }
51 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 # Error reporting
53 # Public API
54  
55 sub Fatal {
56 0 ▶ my ($category, $object, $where, $message, @details) = @_;
Subroutine Fatal: not called CC=18 SCAR=58.3
Pod documented
57  
58 # Check if this is a known unsafe fatal and flag it if so (so that we reinitialize in daemon contexts)
59 0 ▶ if ((($category eq 'internal') && ($object eq '<recursion>')) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($category eq "internal" and $object eq "<recursion>" or $category eq "too_many_errors") 0 0 0
Condition0%0/6
$category eq "internal" and $object eq "<recursion>" or $category eq "too_many_errors"
l!l&&r!l&&!r
000
$category eq "internal" and $object eq "<recursion>"
!ll&&!rl&&r
000
MC/DC0%0/3
$category eq "internal" and $object eq "<recursion>" or $category eq "too_many_errors"
$category eq "internal" $object eq "<recursion>" $category eq "too_many_errors"
Truth table0%0/5
A and B or C
A= $category eq "internal"B= $object eq "<recursion>"C= $category eq "too_many_errors"
ABCresult
11X1
0X11
1011
0X00
1000
60 ($category eq 'too_many_errors')) {
61 0 $LaTeXML::UNSAFE_FATAL = 1; }
62  
63 # We'll assume that if the DIE handler is bound (presumably to this function)
64 # we're in the outermost call to Fatal; we'll clear the handler so that we don't nest calls.
65 die $message if $LaTeXML::IGNORE_ERRORS # Short circuit, w/no formatting, if in probing eval
66 0 ▶ || (($SIG{__DIE__} eq 'DEFAULT') && $^S); # Also missing class when parsing bindings(?!?!)
Branch: 1 branch
BranchTrueFalseTotal
if $LaTeXML::IGNORE_ERRORS or $SIG{"__DIE__"} eq "DEFAULT" and $^S 0 0 0
Condition0%0/6
$LaTeXML::IGNORE_ERRORS or $SIG{"__DIE__"} eq "DEFAULT" and $^S
l!l&&r!l&&!r
000
$SIG{"__DIE__"} eq "DEFAULT" and $^S
!ll&&!rl&&r
000
MC/DC0%0/3
$LaTeXML::IGNORE_ERRORS or $SIG{"__DIE__"} eq "DEFAULT" and $^S
$LaTeXML::IGNORE_ERRORS $SIG{"__DIE__"} eq "DEFAULT" $^S
Truth table0%0/4
A or B and C
A= $LaTeXML::IGNORE_ERRORSB= $SIG{"__DIE__"} eq "DEFAULT"C= $^S
ABCresult
1XX1
0111
00X0
0100
67  
68 # print STDERR "\nHANDLING FATAL:"
69 # ." ignore=".($LaTeXML::IGNORE_ERRORS || '<no>')
70 # ." handler=".($SIG{__DIE__}||'<none>')
71 # ." parsing=".($^S||'<no>')
72 # ."\n";
73 0 my $inhandler = !$SIG{__DIE__};
74 0 my $ineval = 0; # whether we're in an eval should no longer matter!
75  
76 # This seemingly should be "local", but that doesn't seem to help with timeout/alarm/term?
77 # It should be safe so long as the caller has bound it and rebinds it if necessary.
78 0 local $SIG{__DIE__} = 'DEFAULT'; # Avoid recursion while preparing the message.
79 0 my $state = $STATE;
80 0 ▶ my $verbosity = $state && $state->lookupValue('VERBOSITY') || 0;
Condition0%0/5
$state && $state->lookupValue('VERBOSITY') || 0
l!l
00
$state and $state->lookupValue("VERBOSITY")
!ll&&!rl&&r
000
MC/DC0%0/2
$state && $state->lookupValue('VERBOSITY') || 0
$state $state->lookupValue("VERBOSITY")
Truth table0%0/3
A and B
A= $stateB= $state->lookupValue("VERBOSITY")
ABresult
111
0X0
100
81  
82 0 ▶ if (!$inhandler) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $inhandler) { } 0 0 0
83 0 local $LaTeXML::BAILOUT = $LaTeXML::BAILOUT;
84 0 ▶ if (checkRecursiveError()) {
Branch: 1 branch
BranchTrueFalseTotal
if (checkRecursiveError()) 0 0 0
85 0 $LaTeXML::BAILOUT = 1;
86 0 push(@details, "Recursive Error!"); }
87 0 ▶ $state->noteStatus('fatal') if $state && !$ineval;
Branch: 1 branch
BranchTrueFalseTotal
if $state and not $ineval 0 0 0
Condition0%0/3
$state and not $ineval
!ll&&!rl&&r
000
MC/DC0%0/2
$state and not $ineval
$state not $ineval
Truth table0%0/3
A and not(B)
A= $stateB= not $ineval
ABresult
0X0
100
111
88 0 ▶ my $detail_level = (($verbosity <= 1) && ($category =~ /^(?:timeout|too_many_errors)$/)) ? 0 : 2;
Branch: 1 branch
BranchTrueFalseTotal
$verbosity <= 1 && $category =~ /^(?:timeout|too_many_errors)$/ ? : 0 0 0
Condition0%0/3
$verbosity <= 1 and $category =~ /^(?:timeout|too_many_errors)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$verbosity <= 1 and $category =~ /^(?:timeout|too_many_errors)$/
$verbosity <= 1 $category =~ /^(?:timeout|too_many_errors)$/
Truth table0%0/3
A and B
A= $verbosity <= 1B= $category =~ /^(?:timeout|too_many_errors)$/
ABresult
0X0
100
111
89 0 $message
90 = generateMessage(colorizeString("Fatal:" . $category . ":" . ToString($object), 'fatal'),
91 $where, $message, $detail_level, @details);
92 # If we're about to (really) DIE, we'll bypass the usual status message, so add it here.
93 # This really should be handled by the top-level program,
94 # after doing all processing within an eval
95 # BIZARRE: Note that die adds the "at <file> <line>" stuff IFF the message doesn't end w/ CR!
96 0 ▶ $message .= $state->getStatusMessage . "\n" if $state && !$ineval;
Branch: 1 branch
BranchTrueFalseTotal
if $state and not $ineval 0 0 0
Condition0%0/3
$state and not $ineval
!ll&&!rl&&r
000
MC/DC0%0/2
$state and not $ineval
$state not $ineval
Truth table0%0/3
A and not(B)
A= $stateB= not $ineval
ABresult
0X0
100
111
97 }
98 else { # If we ARE in a recursive call, the actual message is $details[0]
99 0 ▶ $message = $details[0] if $details[0]; }
Branch: 1 branch
BranchTrueFalseTotal
if $details[0] 0 0 0
100 # If inside an eval, this won't actually die, but WILL set $@ for caller's use.
101 0 die $message; }
102  
103 sub checkRecursiveError {
104 0 ▶ my @caller;
Subroutine checkRecursiveError: not called CC=3 SCAR=24.8
Pod undocumented
105 0 ▶ for (my $frame = 2 ; @caller = caller($frame) ; $frame++) {
Branch: 1 branch
BranchTrueFalseTotal
if (@caller = caller $frame) 0 0 0
106 0 ▶ if ($caller[3] =~ /^LaTeXML::(Global::ToString|Global::Stringify)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller[3] =~ /^LaTeXML::(Global::ToString|Global::Stringify)$/) 0 0 0
107 # print STDERR "RECURSED ON $caller[3]\n";
108 0 return 1; } }
109 0 return; }
110  
111 # Should be fatal if strict is set, else warn.
112 sub Error {
113 0 ▶ my ($category, $object, $where, $message, @details) = @_;
Subroutine Error: not called CC=12 SCAR=50.5
Pod documented
114 0 my $state = $STATE;
115 0 ▶ my $verbosity = $state && $state->lookupValue('VERBOSITY') || 0;
Condition0%0/5
$state && $state->lookupValue('VERBOSITY') || 0
l!l
00
$state and $state->lookupValue("VERBOSITY")
!ll&&!rl&&r
000
MC/DC0%0/2
$state && $state->lookupValue('VERBOSITY') || 0
$state $state->lookupValue("VERBOSITY")
Truth table0%0/3
A and B
A= $stateB= $state->lookupValue("VERBOSITY")
ABresult
111
0X0
100
116 0 ▶ if ($state && $state->lookupValue('STRICT')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state and $state->lookupValue('STRICT')) { } 0 0 0
Condition0%0/3
$state and $state->lookupValue("STRICT")
!ll&&!rl&&r
000
MC/DC0%0/2
$state and $state->lookupValue("STRICT")
$state $state->lookupValue("STRICT")
Truth table0%0/3
A and B
A= $stateB= $state->lookupValue("STRICT")
ABresult
0X0
100
111
117 0 Fatal($category, $object, $where, $message, @details); }
118 else {
119 0 ▶ $state && $state->noteStatus('error');
Branch: 1 branch
BranchTrueFalseTotal
$state and $state->noteStatus("error") 0 0 0
120 0 ▶ print STDERR generateMessage(colorizeString("Error:" . $category . ":" . ToString($object), 'error'),
Branch: 1 branch
BranchTrueFalseTotal
if $verbosity >= -2 0 0 0
121 $where, $message, 1, @details)
122 if $verbosity >= -2; }
123 # Note that "100" is hardwired into TeX, The Program!!!
124 0 ▶ my $maxerrors = ($state ? $state->lookupValue('MAX_ERRORS') : 100);
Branch: 1 branch
BranchTrueFalseTotal
$state ? : 0 0 0
125 0 ▶ if ($state && (defined $maxerrors) && (($state->getStatus('error') || 0) > $maxerrors)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state and defined $maxerrors and ($state->getStatus("error") || 0) > $maxerrors) 0 0 0
Condition0%0/8
$state and defined $maxerrors and ($state->getStatus("error") || 0) > $maxerrors
!ll&&!rl&&r
000
$state and defined $maxerrors
!ll&&!rl&&r
000
$state->getStatus('error') || 0
l!l
00
MC/DC0%0/3
$state and defined $maxerrors and ($state->getStatus("error") || 0) > $maxerrors
$state defined $maxerrors $state->getStatus('error')
Truth table0%0/4
A and B and C
A= $stateB= defined $maxerrorsC= $state->getStatus('error')
ABCresult
0XX0
10X0
1100
1111
126 0 Fatal('too_many_errors', $maxerrors, $where, "Too many errors (> $maxerrors)!"); }
127 0 return; }
128  
129 # Warning message; results may be OK, but somewhat unlikely
130 sub Warn {
131 0 ▶ my ($category, $object, $where, $message, @details) = @_;
Subroutine Warn: not called CC=5 SCAR=34.0
Pod documented
132 0 my $state = $STATE;
133 0 ▶ my $verbosity = $state && $state->lookupValue('VERBOSITY') || 0;
Condition0%0/5
$state && $state->lookupValue('VERBOSITY') || 0
l!l
00
$state and $state->lookupValue("VERBOSITY")
!ll&&!rl&&r
000
MC/DC0%0/2
$state && $state->lookupValue('VERBOSITY') || 0
$state $state->lookupValue("VERBOSITY")
Truth table0%0/3
A and B
A= $stateB= $state->lookupValue("VERBOSITY")
ABresult
111
0X0
100
134 0 ▶ $state && $state->noteStatus('warning');
Branch: 1 branch
BranchTrueFalseTotal
$state and $state->noteStatus("warning") 0 0 0
135 0 ▶ print STDERR generateMessage(colorizeString("Warning:" . $category . ":" . ToString($object), 'warning'),
Branch: 1 branch
BranchTrueFalseTotal
if $verbosity >= -1 0 0 0
136 $where, $message, 0, @details)
137 if $verbosity >= -1;
138 0 return; }
139  
140 # Informational message; results likely unaffected
141 # but the message may give clues about subsequent warnings or errors
142 sub Info {
143 0 ▶ my ($category, $object, $where, $message, @details) = @_;
Subroutine Info: not called CC=5 SCAR=34.0
Pod documented
144 0 my $state = $STATE;
145 0 ▶ my $verbosity = $state && $state->lookupValue('VERBOSITY') || 0;
Condition0%0/5
$state && $state->lookupValue('VERBOSITY') || 0
l!l
00
$state and $state->lookupValue("VERBOSITY")
!ll&&!rl&&r
000
MC/DC0%0/2
$state && $state->lookupValue('VERBOSITY') || 0
$state $state->lookupValue("VERBOSITY")
Truth table0%0/3
A and B
A= $stateB= $state->lookupValue("VERBOSITY")
ABresult
111
0X0
100
146 0 ▶ $state && $state->noteStatus('info');
Branch: 1 branch
BranchTrueFalseTotal
$state and $state->noteStatus("info") 0 0 0
147 0 ▶ print STDERR generateMessage(colorizeString("Info:" . $category . ":" . ToString($object), 'info'),
Branch: 1 branch
BranchTrueFalseTotal
if $verbosity >= 0 0 0 0
148 $where, $message, -1, @details)
149 if $verbosity >= 0;
150 0 return; }
151  
152 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 # Progress Reporting
154 #**********************************************************************
155 # Progress reporting.
156  
157 sub NoteProgress {
158 0 ▶ my (@stuff) = @_;
Subroutine NoteProgress: not called CC=4 SCAR=30.0
Pod documented
159 0 my $state = $STATE;
160 0 ▶ my $verbosity = $state && $state->lookupValue('VERBOSITY') || 0;
Condition0%0/5
$state && $state->lookupValue('VERBOSITY') || 0
l!l
00
$state and $state->lookupValue("VERBOSITY")
!ll&&!rl&&r
000
MC/DC0%0/2
$state && $state->lookupValue('VERBOSITY') || 0
$state $state->lookupValue("VERBOSITY")
Truth table0%0/3
A and B
A= $stateB= $state->lookupValue("VERBOSITY")
ABresult
111
0X0
100
161 0 ▶ print STDERR @stuff if $verbosity >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $verbosity >= 0 0 0 0
162 0 return; }
163  
164 sub NoteProgressDetailed {
165 0 ▶ my (@stuff) = @_;
Subroutine NoteProgressDetailed: not called CC=4 SCAR=30.0
Pod documented
166 0 my $state = $STATE;
167 0 ▶ my $verbosity = $state && $state->lookupValue('VERBOSITY') || 0;
Condition0%0/5
$state && $state->lookupValue('VERBOSITY') || 0
l!l
00
$state and $state->lookupValue("VERBOSITY")
!ll&&!rl&&r
000
MC/DC0%0/2
$state && $state->lookupValue('VERBOSITY') || 0
$state $state->lookupValue("VERBOSITY")
Truth table0%0/3
A and B
A= $stateB= $state->lookupValue("VERBOSITY")
ABresult
111
0X0
100
168 0 ▶ print STDERR @stuff if $verbosity >= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $verbosity >= 1 0 0 0
169 0 return; }
170  
171 sub NoteBegin {
172 0 ▶ my ($stage) = @_;
Subroutine NoteBegin: not called CC=5 SCAR=34.0
Pod undocumented
173 0 my $state = $STATE;
174 0 ▶ my $verbosity = $state && $state->lookupValue('VERBOSITY') || 0;
Condition0%0/5
$state && $state->lookupValue('VERBOSITY') || 0
l!l
00
$state and $state->lookupValue("VERBOSITY")
!ll&&!rl&&r
000
MC/DC0%0/2
$state && $state->lookupValue('VERBOSITY') || 0
$state $state->lookupValue("VERBOSITY")
Truth table0%0/3
A and B
A= $stateB= $state->lookupValue("VERBOSITY")
ABresult
111
0X0
100
175 0 ▶ if ($state && ($verbosity >= 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state and $verbosity >= 0) 0 0 0
Condition0%0/3
$state and $verbosity >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$state and $verbosity >= 0
$state $verbosity >= 0
Truth table0%0/3
A and B
A= $stateB= $verbosity >= 0
ABresult
0X0
100
111
176 0 $state->assignMapping('NOTE_TIMERS', $stage, [Time::HiRes::gettimeofday]);
177 0 print STDERR "\n($stage..."; }
178 0 return; }
179  
180 sub NoteEnd {
181 0 ▶ my ($stage) = @_;
Subroutine NoteEnd: not called CC=6 SCAR=37.4
Pod undocumented
182 0 my $state = $STATE;
183 0 ▶ my $verbosity = $state && $state->lookupValue('VERBOSITY') || 0;
Condition0%0/5
$state && $state->lookupValue('VERBOSITY') || 0
l!l
00
$state and $state->lookupValue("VERBOSITY")
!ll&&!rl&&r
000
MC/DC0%0/2
$state && $state->lookupValue('VERBOSITY') || 0
$state $state->lookupValue("VERBOSITY")
Truth table0%0/3
A and B
A= $stateB= $state->lookupValue("VERBOSITY")
ABresult
111
0X0
100
184 0 ▶ if (my $start = $state && $state->lookupMapping('NOTE_TIMERS', $stage)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $start = $state && $state->lookupMapping("NOTE_TIMERS", $stage)) 0 0 0
Condition0%0/3
$state && $state->lookupMapping('NOTE_TIMERS', $stage)
!ll&&!rl&&r
000
MC/DC0%0/2
$state && $state->lookupMapping('NOTE_TIMERS', $stage)
$state $state->lookupMapping('NOTE_TIMERS', $stage)
Truth table0%0/3
A && B
A= $stateB= $state->lookupMapping('NOTE_TIMERS', $stage)
ABresult
0X0
100
111
185 0 $state->assignMapping('NOTE_TIMERS', $stage, undef);
186 0 ▶ if ($verbosity >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbosity >= 0) 0 0 0
187 0 my $elapsed = Time::HiRes::tv_interval($start, [Time::HiRes::gettimeofday]);
188 0 print STDERR sprintf(" %.2f sec)", $elapsed); } }
189 0 return; }
190  
191 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 # Handlers for perl's die & warn
193 # We'll try to decode some common errors to make them more usable
194 # for build systems.
195  
196 29 my $quoted_re = qr/\"([^\"]*)\"/; # [CONSTANT]
197 29 my $cantcall_re = qr/Can't call method/; # [CONSTANT]
198 29 my $cantlocate_re = qr/Can't locate object method/; # [CONSTANT]
199 29 my $undef_re = qr/Undefined subroutine/; # [CONSTANT]
200 29 my $noself_re = qr/on an undefined value|without a package or object reference/; # [CONSTANT]
201 29 my $via_re = qr/via package/; # [CONSTANT]
202 29 my $at_re = qr/(at .*)/; # [CONSTANT]
203  
204 sub perl_die_handler {
205 0 ▶ my (@line) = @_;
Subroutine perl_die_handler: not called CC=9 SCAR=45.0
Pod undocumented
206 0 ▶ if ($LaTeXML::IGNORE_ERRORS # Just get out now, if we're ignoring errors within an eval.
Branch: 1 branch
BranchTrueFalseTotal
if ($LaTeXML::IGNORE_ERRORS or colorstrip($line[0]) =~ /^\s*Fatal:/) 0 0 0
Condition0%0/3
$LaTeXML::IGNORE_ERRORS or colorstrip($line[0]) =~ /^\s*Fatal:/
l!l&&r!l&&!r
000
MC/DC0%0/2
$LaTeXML::IGNORE_ERRORS or colorstrip($line[0]) =~ /^\s*Fatal:/
$LaTeXML::IGNORE_ERRORS colorstrip($line[0]) =~ /^\s*Fatal:/
Truth table0%0/3
A or B
A= $LaTeXML::IGNORE_ERRORSB= colorstrip($line[0]) =~ /^\s*Fatal:/
ABresult
1X1
011
000
207 || (colorstrip($line[0]) =~ /^\s*Fatal:/)) { # Or, we've already been through here.
208 0 local $SIG{__DIE__} = undef;
209 0 die @line; }
210 # We try to find a meaningful name for where the error occurred;
211 # That's the thing that is "misdefined", after all.
212 # Not completely sure we're looking in the right place up the stack, though.
213 0 ▶ if ($line[0] =~ /^$cantcall_re\s+$quoted_re\s+($noself_re)\s+$at_re$/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($line[0] =~ /^$cantcall_re\s+$quoted_re\s+($noself_re)\s+$at_re$/) { } 0 0 0
elsif ($line[0] =~ /^$undef_re\s+(\S+)\s+called $at_re$/) { } 0 0 0
elsif ($line[0] =~ /^$cantlocate_re\s+$quoted_re\s+$via_re\s+$quoted_re\s+\(.*\)\s+$at_re/) { } 0 0 0
elsif ($line[0] =~ /^Can't locate \S* in \@INC \(you may need to install the (\S*) module\) \(\@INC contains: ([^\)]*)\) $at_re$/) { } 0 0 0
elsif ($line[0] =~ /^Can't use\s+(\w*)\s+\([^\)]*\) as (.*?) ref(?:\s+while "strict refs" in use)? at (.*)$/) { } 0 0 0
elsif ($line[0] =~ /^File (.*?) had an error:/) { } 0 0 0
214 0 my ($method, $kind, $where) = ($1, $2, $3);
215 0 Fatal('misdefined', callerName(1), $where,
216 "Can't call method '$method' $kind", @line[1 .. $#line]); }
217 elsif ($line[0] =~ /^$undef_re\s+(\S+)\s+called $at_re$/) {
218 0 my ($function, $where) = ($1, $2);
219 0 Fatal('misdefined', callerName(1), $where,
220 "Undefined subroutine '$function' called", @line[1 .. $#line]); }
221 elsif ($line[0] =~ /^$cantlocate_re\s+$quoted_re\s+$via_re\s+$quoted_re\s+\(.*\)\s+$at_re/) {
222 0 my ($method, $class, $where) = ($1, $2, $3);
223 0 Fatal('misdefined', callerName(1), $where,
224 "Can't locate method '$method' via '$class'", @line[1 .. $#line]); }
225 elsif ($line[0] =~ /^Can't locate \S* in \@INC \(you may need to install the (\S*) module\) \(\@INC contains: ([^\)]*)\) $at_re$/) {
226 0 my ($class, $inc, $where) = ($1, $2);
227 0 Fatal('misdefined', callerName(1), $where,
228 "Can't locate class '$class' (not installed or misspelled?)", @line[1 .. $#line]); }
229 elsif ($line[0] =~ /^Can't use\s+(\w*)\s+\([^\)]*\) as (.*?) ref(?:\s+while "strict refs" in use)? at (.*)$/) {
230 0 my ($gottype, $wanttype, $where) = ($1, $2, $3);
231 0 Fatal('misdefined', callerName(1), $where,
232 "Can't use $gottype as $wanttype reference", @line[1 .. $#line]); }
233 elsif ($line[0] =~ /^File (.*?) had an error:/) {
234 0 my ($file) = ($1);
235 0 Fatal('misdefined', $file, undef, @line); }
236 else {
237 0 Fatal('perl', 'die', undef, "Perl died", @line); }
238 0 return; }
239  
240 sub perl_warn_handler {
241 0 ▶ my (@line) = @_;
Subroutine perl_warn_handler: not called CC=5 SCAR=34.0
Pod undocumented
242 0 ▶ return if $LaTeXML::IGNORE_ERRORS;
Branch: 1 branch
BranchTrueFalseTotal
if $LaTeXML::IGNORE_ERRORS 0 0 0
243 0 ▶ if ($line[0] =~ /^Use of uninitialized value (.*?)(\s?+in .*?)\s+(at\s+.*?\s+line\s+\d+)\.$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line[0] =~ /^Use of uninitialized value (.*?)(\s?+in .*?)\s+(at\s+.*?\s+line\s+\d+)\.$/) { } 0 0 0
elsif ($line[0] =~ /^(.*?)\s+(at\s+.*?\s+line\s+\d+)\.$/) { } 0 0 0
244 0 ▶ my ($what, $how, $where) = ($1 || 'value', $2, $3);
Condition0%0/2
$1 || 'value'
l!l
00
MC/DC0%0/1
$1 || 'value'
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
245 0 Warn('uninitialized', $what, $where, "Use of uninitialized value $what $how", @line[1 .. $#line]); }
246 elsif ($line[0] =~ /^(.*?)\s+(at\s+.*?\s+line\s+\d+)\.$/) {
247 0 my ($warning, $where) = ($1, $2);
248 0 Warn('perl', 'warn', undef, $warning, $where, @line[1 .. $#line]); }
249 else {
250 0 Warn('perl', 'warn', undef, "Perl warning", @line); }
251 0 return; }
252  
253 # The following handlers SHOULD report the problem,
254 # even when within a "safe" eval that's ignoring errors.
255 # Moreover, we'd really like to be able to throw all the way to
256 # the top-level containing eval. How to do that?
257 sub perl_interrupt_handler {
258 0 ▶ my (@line) = @_;
Subroutine perl_interrupt_handler: not called CC=1 SCAR=6.9
Pod undocumented
259 0 $LaTeXML::IGNORE_ERRORS = 0; # NOT ignored
260 0 $LaTeXML::UNSAFE_FATAL = 1;
261 0 Fatal('interrupt', 'interrupted', undef, "LaTeXML was interrupted", @line);
262 0 return; }
263  
264 sub perl_timeout_handler {
265 0 ▶ my (@line) = @_;
Subroutine perl_timeout_handler: not called CC=1 SCAR=6.9
Pod undocumented
266 0 $LaTeXML::IGNORE_ERRORS = 0; # NOT ignored
267 0 $LaTeXML::UNSAFE_FATAL = 1;
268 0 Fatal('timeout', 'timedout', undef, "Conversion timed out", @line);
269 0 return; }
270  
271 sub perl_terminate_handler {
272 0 ▶ my (@line) = @_;
Subroutine perl_terminate_handler: not called CC=1 SCAR=6.9
Pod undocumented
273 0 $LaTeXML::IGNORE_ERRORS = 0; # NOT ignored
274 0 $LaTeXML::UNSAFE_FATAL = 1;
275 0 Fatal('terminate', 'terminated', undef, "Conversion was terminated", @line);
276 0 return; }
277 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 # Internals
279 # Synthesize an error message describing what happened, and where.
280 # $detail specifies the level of detail
281 # $detail == -1 : no context or stack
282 # $detail == 0 : context, no stack
283 # $detail == +1 : context & stack
284 # including a level requesting full stack trace?
285  
286 sub generateMessage {
287 0 ▶ my ($errorcode, $where, $message, $detail, @extra) = @_;
Subroutine generateMessage: not called CC=27 SCAR=66.3
Pod documented
288 #----------------------------------------
289 # Generate location information; basic and for stack trace.
290 # If we've been given an object $where, where the error occurred, use it.
291 0 my $docloc = getLocation($where);
292 0 ▶ $docloc = defined $docloc ? ToString($docloc) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $docloc ? : 0 0 0
293  
294 # $message and each of @extra should be single lines
295 0 @extra = grep { $_ ne '' } map { split("\n", $_) } grep { defined $_ } $message, @extra;
296 # make 1st line be 1st line of message
297 0 $message = shift(@extra);
298 # $message =~ s/\n.*//g;
299 # The initial portion of the message will consist of:
300 0 ▶ $message = '' unless defined $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 0 0
301 0 ▶ my @lines = (
Branch: 1 branch
BranchTrueFalseTotal
$docloc ? : 0 0 0
302 # Start with the error code & primary error message
303 $errorcode . ' ' . $message,
304 # Followed by single line location of where the message occurred (if we know)
305 ($docloc ? ('at ' . $docloc) : ()),
306 # and then any additional message lines supplied
307 @extra);
308  
309 #----------------------------------------
310 # Now add some additional context
311 # NOTE: Should skip this for INFO
312 # NOTE: Need to pass more of this onto the objects themselves....
313 # What should it be called?
314 # showErrorContext() ?????
315 0 ▶ $detail = 0 unless defined $detail;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $detail 0 0 0
316 # Increment $detail if $verbosity > 0, unless $detail = -1,
317 0 ▶ my $verbosity = ($STATE && $STATE->lookupValue('VERBOSITY')) || 0;
Condition0%0/5
$LaTeXML::Common::Error::STATE && $LaTeXML::Common::Error::STATE->lookupValue('VERBOSITY') || 0
l!l
00
$LaTeXML::Common::Error::STATE and $LaTeXML::Common::Error::STATE->lookupValue("VERBOSITY")
!ll&&!rl&&r
000
MC/DC0%0/2
$LaTeXML::Common::Error::STATE && $LaTeXML::Common::Error::STATE->lookupValue('VERBOSITY') || 0
$LaTeXML::Common::Error::STATE $LaTeXML::Common::Error::STATE->lookupValue("VERBOSITY")
Truth table0%0/3
A and B
A= $LaTeXML::Common::Error::STATEB= $LaTeXML::Common::Error::STATE->lookupValue("VERBOSITY")
ABresult
111
0X0
100
318 0 ▶ if (($detail > -1) && ($verbosity > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail > -1 and $verbosity > 0) 0 0 0
Condition0%0/3
$detail > -1 and $verbosity > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$detail > -1 and $verbosity > 0
$detail > -1 $verbosity > 0
Truth table0%0/3
A and B
A= $detail > -1B= $verbosity > 0
ABresult
0X0
100
111
319 0 ▶ $detail = 0 if defined $verbosity && $verbosity < -1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $verbosity and $verbosity < -1 0 0 0
Condition0%0/3
defined $verbosity and $verbosity < -1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $verbosity and $verbosity < -1
defined $verbosity $verbosity < -1
Truth table0%0/3
A and B
A= defined $verbosityB= $verbosity < -1
ABresult
0X0
100
111
320 0 ▶ $detail++ if defined $verbosity && $verbosity > +1; }
Branch: 1 branch
BranchTrueFalseTotal
if defined $verbosity and $verbosity > 1 0 0 0
Condition0%0/3
defined $verbosity and $verbosity > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $verbosity and $verbosity > 1
defined $verbosity $verbosity > 1
Truth table0%0/3
A and B
A= defined $verbosityB= $verbosity > 1
ABresult
0X0
100
111
321  
322 # FIRST line of stack trace information ought to look at the $where
323 0 my $wheretype = ref $where;
324 0 ▶ if ($detail <= 0) { } # No extra context
Branch: 4 branches
BranchTrueFalseTotal
if ($detail <= 0) { } 0 0 0
elsif ($wheretype =~ /^XML::LibXML/) { } 0 0 0
elsif ($wheretype =~ /LaTeXML::Core::Gullet/) { } 0 0 0
elsif ($wheretype =~ /LaTeXML::Core::Stomach/) { } 0 0 0
325 elsif ($wheretype =~ /^XML::LibXML/) {
326 0 push(@lines, "Node is " . Stringify($where)); }
327 ## Hmm... if we're being verbose or level is high, we might do this:
328 ### "Currently in ".$doc->getInsertionContext); }
329 elsif ($wheretype =~ 'LaTeXML::Core::Gullet') {
330 0 push(@lines, $where->showUnexpected); } # Or better?
331 elsif ($wheretype =~ 'LaTeXML::Core::Stomach') {
332 push(@lines,
333 0 ▶ "Recently digested: " . join(' ', map { Stringify($_) } @LaTeXML::LIST))
Branch: 1 branch
BranchTrueFalseTotal
if $verbosity > 1 0 0 0
334 if $verbosity > 1; }
335  
336 #----------------------------------------
337 # Add Stack Trace, if that seems worthwhile.
338 0 ▶ if (($detail > 1) && ($verbosity > 0)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($detail > 1 and $verbosity > 0) { } 0 0 0
elsif ($detail > -1) { } 0 0 0
Condition0%0/3
$detail > 1 and $verbosity > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$detail > 1 and $verbosity > 0
$detail > 1 $verbosity > 0
Truth table0%0/3
A and B
A= $detail > 1B= $verbosity > 0
ABresult
0X0
100
111
339 0 push(@lines, "Stack Trace:", stacktrace()); }
340 elsif ($detail > -1) {
341 0 ▶ my $nstack = ($detail > 1 ? undef : ($detail > 0 ? 4 : 1));
Branch: 2 branches
BranchTrueFalseTotal
$detail > 1 ? : 0 0 0
$detail > 0 ? : 0 0 0
342 0 ▶ if (my @objects = objectStack($nstack)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@objects) = objectStack($nstack)) 0 0 0
343 0 my $top = shift(@objects);
344 0 push(@lines, "In " . trim(Stringify($$top[0])) . ' ' . Stringify($$top[1]));
345 0 ▶ push(@objects, ['...']) if @objects && defined $nstack;
Branch: 1 branch
BranchTrueFalseTotal
if @objects and defined $nstack 0 0 0
Condition0%0/3
@objects and defined $nstack
!ll&&!rl&&r
000
MC/DC0%0/2
@objects and defined $nstack
@objects defined $nstack
Truth table0%0/3
A and B
A= @objectsB= defined $nstack
ABresult
0X0
100
111
346 0 ▶ push(@lines, join('', (map { ' <= ' . trim(Stringify($$_[0])) } @objects))) if @objects;
Branch: 1 branch
BranchTrueFalseTotal
if @objects 0 0 0
347 } }
348  
349 # finally, join the result into a block of lines, indenting all but the 1st line.
350 0 return "\n" . join("\n\t", @lines) . "\n"; }
351  
352 sub MergeStatus {
353 0 ▶ my ($external_state) = @_;
Subroutine MergeStatus: not called CC=7 SCAR=40.3
Pod undocumented
354 0 my $state = $STATE;
355 0 ▶ return unless $state && $external_state;
Branch: 1 branch
BranchTrueFalseTotal
unless $state and $external_state 0 0 0
Condition0%0/3
$state and $external_state
!ll&&!rl&&r
000
MC/DC0%0/2
$state and $external_state
$state $external_state
Truth table0%0/3
A and B
A= $stateB= $external_state
ABresult
0X0
100
111
356 0 my $status = $$state{status};
357 0 my $external_status = $$external_state{status};
358 # Should this be a state method? I suspect XS-ive conflicts later on...
359 0 foreach my $type (keys %$external_status) {
360 0 ▶ if ($type eq 'undefined' or $type eq 'missing') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'undefined' or $type eq 'missing') { } 0 0 0
Condition0%0/3
$type eq "undefined" or $type eq "missing"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "undefined" or $type eq "missing"
$type eq "undefined" $type eq "missing"
Truth table0%0/3
A or B
A= $type eq "undefined"B= $type eq "missing"
ABresult
1X1
011
000
361 0 my $table = $$external_status{$type};
362 0 foreach my $subtype (keys %$table) {
363 0 $$status{$type}{$subtype} += $$table{$subtype};
364 }
365 } else {
366 0 $$status{$type} += $$external_status{$type};
367 }
368 }
369 0 return; }
370  
371 # returns the locator of an object, or undef
372 sub Locator {
373 0 ▶ my ($object) = @_;
Subroutine Locator: not called CC=3 SCAR=24.8
Pod undocumented
374 0 ▶ return ($object && $object->can('getLocator') ? $object->getLocator : undef); }
Branch: 1 branch
BranchTrueFalseTotal
$object && $object->can('getLocator') ? : 0 0 0
Condition0%0/3
$object and $object->can("getLocator")
!ll&&!rl&&r
000
MC/DC0%0/2
$object and $object->can("getLocator")
$object $object->can("getLocator")
Truth table0%0/3
A and B
A= $objectB= $object->can("getLocator")
ABresult
0X0
100
111
375  
376 # A more organized abstraction along there likes of $where->whereAreYou
377 # might be useful?
378 sub getLocation {
379 0 ▶ my ($where) = @_;
Subroutine getLocation: not called CC=13 SCAR=52.0
Pod undocumented
380 0 my $wheretype = ref $where;
381 0 ▶ if ($wheretype && ($wheretype =~ /^XML::LibXML/)) {
Branch: 4 branches
BranchTrueFalseTotal
if ($wheretype and $wheretype =~ /^XML::LibXML/) { } 0 0 0
elsif ($wheretype and $where->can('getLocator')) { } 0 0 0
elsif (defined $where) { } 0 0 0
elsif ($LaTeXML::DOCUMENT) { } 0 0 0
Condition0%0/3
$wheretype and $wheretype =~ /^XML::LibXML/
!ll&&!rl&&r
000
MC/DC0%0/2
$wheretype and $wheretype =~ /^XML::LibXML/
$wheretype $wheretype =~ /^XML::LibXML/
Truth table0%0/3
A and B
A= $wheretypeB= $wheretype =~ /^XML::LibXML/
ABresult
0X0
100
111
382 0 ▶ my $box = $LaTeXML::DOCUMENT && $LaTeXML::DOCUMENT->getNodeBox($where);
Condition0%0/3
$LaTeXML::DOCUMENT && $LaTeXML::DOCUMENT->getNodeBox($where)
!ll&&!rl&&r
000
MC/DC0%0/2
$LaTeXML::DOCUMENT && $LaTeXML::DOCUMENT->getNodeBox($where)
$LaTeXML::DOCUMENT $LaTeXML::DOCUMENT->getNodeBox($where)
Truth table0%0/3
A && B
A= $LaTeXML::DOCUMENTB= $LaTeXML::DOCUMENT->getNodeBox($where)
ABresult
0X0
100
111
383 0 ▶ return Locator($box) if $box; }
Branch: 1 branch
BranchTrueFalseTotal
if $box 0 0 0
384 ▶ elsif ($wheretype && $where->can('getLocator')) {
Condition0%0/3
$wheretype and $where->can("getLocator")
!ll&&!rl&&r
000
MC/DC0%0/2
$wheretype and $where->can("getLocator")
$wheretype $where->can("getLocator")
Truth table0%0/3
A and B
A= $wheretypeB= $where->can("getLocator")
ABresult
0X0
100
111
385 0 return $where->getLocator; }
386 elsif (defined $where) {
387 0 return $where; }
388 # Otherwise, try to guess where the error came from!
389 elsif ($LaTeXML::DOCUMENT) { # During construction?
390 0 my $node = $LaTeXML::DOCUMENT->getNode;
391 0 my $box = $LaTeXML::DOCUMENT->getNodeBox($node);
392 0 ▶ return Locator($box) if $box; }
Branch: 1 branch
BranchTrueFalseTotal
if $box 0 0 0
393 0 ▶ if ($LaTeXML::BOX) { # In constructor?
Branch: 1 branch
BranchTrueFalseTotal
if ($LaTeXML::BOX) 0 0 0
394 0 return Locator($LaTeXML::BOX); }
395 0 ▶ if ($STATE && $STATE->getStomach) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LaTeXML::Common::Error::STATE and $LaTeXML::Common::Error::STATE->getStomach) 0 0 0
Condition0%0/3
$LaTeXML::Common::Error::STATE and $LaTeXML::Common::Error::STATE->getStomach
!ll&&!rl&&r
000
MC/DC0%0/2
$LaTeXML::Common::Error::STATE and $LaTeXML::Common::Error::STATE->getStomach
$LaTeXML::Common::Error::STATE $LaTeXML::Common::Error::STATE->getStomach
Truth table0%0/3
A and B
A= $LaTeXML::Common::Error::STATEB= $LaTeXML::Common::Error::STATE->getStomach
ABresult
0X0
100
111
396 0 my $gullet = $STATE->getStomach->getGullet;
397 # NOTE: Problems here.
398 # (1) With obsoleting Tokens as a Mouth, we can get pointless "Anonymous String" locators!
399 # (2) If gullet is the source, we probably want to include next token, etc or
400 0 return Locator($gullet); }
401 # # If in postprocessing
402 # if($LaTeXML::Post::PROCESSOR && $LaTeXML::Post::DOCUMENT){
403 # return 'in '. $LaTeXML::Post::PROCESSOR->getName
404 # . ' on '. $LaTeXML::Post::DOCUMENT->siteRelativeDestination; }
405 0 return; }
406  
407 sub callerName {
408 0 ▶ my ($frame) = @_;
Subroutine callerName: not called CC=2 SCAR=17.9
Pod undocumented
409 0 ▶ my %info = caller_info(($frame || 0) + 2);
Condition0%0/2
$frame || 0
l!l
00
MC/DC0%0/1
$frame || 0
$frame
Truth table0%0/2
A
A= $frame
Aresult
11
00
410 0 return $info{sub}; }
411  
412 sub callerInfo {
413 0 ▶ my ($frame) = @_;
Subroutine callerInfo: not called CC=2 SCAR=17.9
Pod undocumented
414 0 ▶ my %info = caller_info(($frame || 0) + 2);
Condition0%0/2
$frame || 0
l!l
00
MC/DC0%0/1
$frame || 0
$frame
Truth table0%0/2
A
A= $frame
Aresult
11
00
415 0 return "$info{call} @ $info{file} line $info{line}"; }
416  
417 #======================================================================
418 # This portion adapted from Carp; simplified (but hopefully still correct),
419 # allow stringify overload, handle methods, make more concise!
420 #======================================================================
421 29 my $MAXARGS = 8; # [CONSTANT]
422 29 my $MAXLEN = 40; # Or more? [CONSTANT]
423  
424 sub trim {
425 0 ▶ my ($string) = @_;
Subroutine trim: not called CC=3 SCAR=24.8
Pod undocumented
426 0 ▶ return $string unless defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 0 0
427 0 ▶ $string = substr($string, 0, $MAXLEN - 3) . "..." if (length($string) > $MAXLEN);
Branch: 1 branch
BranchTrueFalseTotal
if length $string > $MAXLEN 0 0 0
428 0 $string =~ s/\n/\x{240D}/gs; # symbol for CR
429 0 return $string; }
430  
431 sub caller_info {
432 0 ▶ my ($i) = @_;
Subroutine caller_info: not called CC=12 SCAR=50.5
Pod undocumented
433  
434 0 my (%info, @args);
435 0 { package DB;
436 0 @info{qw(package file line sub has_args wantarray evaltext is_require)}
437 = caller($i);
438 0 @args = @DB::args; }
439 0 ▶ return () unless defined $info{package};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info{"package"} 0 0 0
440 # Work out the effective sub name, or eval, or method ...
441 0 my $call = '';
442 0 ▶ if (defined $info{evaltext}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $info{'evaltext'}) { } 0 0 0
elsif ($info{'sub'} eq '(eval)') { } 0 0 0
443 0 my $eval = $info{evaltext};
444 0 ▶ if ($info{is_require}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info{'is_require'}) { } 0 0 0
445 0 $call = "require $eval"; }
446 else {
447 0 $eval =~ s/([\\\'])/\\$1/g;
448 0 $call = "eval '" . trim($eval) . "'"; } }
449 elsif ($info{sub} eq '(eval)') {
450 0 $call = "eval {...}"; }
451 else {
452 0 $call = $info{sub};
453 0 my $method = $call;
454 0 $method =~ s/^.*:://;
455 # If $arg[0] is blessed, and `can' do $method, then we'll guess it's a method call?
456 0 ▶ if ($info{has_args} && @args
Branch: 1 branch
BranchTrueFalseTotal
if ($info{"has_args"} and @args and ref $args[0] and not ref($args[0]) =~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/ and $args[0]->can($method)) 0 0 0
Condition0%0/12
$info{"has_args"} and @args and ref $args[0] and not ref($args[0]) =~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/ and $args[0]->can($method)
!ll&&!rl&&r
000
$info{"has_args"} and @args and ref $args[0] and not ref($args[0]) =~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/
!ll&&!rl&&r
000
$info{"has_args"} and @args and ref $args[0]
!ll&&!rl&&r
000
$info{"has_args"} and @args
!ll&&!rl&&r
000
MC/DC0%0/5
$info{"has_args"} and @args and ref $args[0] and not ref($args[0]) =~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/ and $args[0]->can($method)
$info{"has_args"} @args ref $args[0] not ref($args[0]) =~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/ $args[0]->can($method)
Truth table0%0/6
A and B and C and not(D) and E
A= $info{"has_args"}B= @argsC= ref $args[0]D= not ref($args[0]) =~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/E= $args[0]->can($method)
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
457 && ref $args[0] && ((ref $args[0]) !~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/)
458 && $args[0]->can($method)) {
459 0 $call = format_arg(shift(@args)) . "->" . $method; } }
460 # Append arguments, if any.
461 0 ▶ if ($info{has_args}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info{"has_args"}) 0 0 0
462 0 @args = map { format_arg($_) } @args;
463 0 ▶ if (@args > $MAXARGS) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args > $MAXARGS) 0 0 0
464 0 $#args = $MAXARGS; push(@args, '...'); }
465 0 $call .= '(' . join(',', @args) . ')'; }
466 0 $info{call} = $call;
467 0 return %info; }
468  
469 sub format_arg {
470 0 ▶ my ($arg) = @_;
Subroutine format_arg: not called CC=4 SCAR=30.0
Pod undocumented
471 0 ▶ if (not defined $arg) { $arg = 'undef'; }
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $arg) { } 0 0 0
elsif (ref $arg) { } 0 0 0
elsif ($arg =~ /^-?[\d.]+\z/) { } 0 0 0
472 0 elsif (ref $arg) { $arg = Stringify($arg); } # Allow overloaded stringify!
473 elsif ($arg =~ /^-?[\d.]+\z/) { } # Leave numbers alone.
474 else { # Otherwise, string, so quote
475 0 $arg =~ s/'/\\'/g; # Slashify '
476 0 $arg =~ s/([[:cntrl:]])/ "\\".chr(ord($1)+ord('A'))/ge;
477 0 $arg = "'$arg'" }
478 0 return trim($arg); }
479  
480 # Semi-traditional (but reformatted) stack trace
481 sub stacktrace {
482 0 ▶ my $frame = 0;
Subroutine stacktrace: not called CC=3 SCAR=24.8
Pod documented
483 0 my $trace = "";
484 0 ▶ while (my %info = caller_info($frame++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%info) = caller_info($frame++)) 0 0 0
485 0 ▶ next if $info{sub} =~ /^LaTeXML::Common::Error/;
Branch: 1 branch
BranchTrueFalseTotal
if $info{"sub"} =~ /^LaTeXML::Common::Error/ 0 0 0
486 ## $info{call} = '' if $info{sub} =~ /^LaTeXML::Common::Error::(?:Fatal|Error|Warn|Info)/;
487 0 $trace .= "\t$info{call} @ $info{file} line $info{line}\n"; }
488 0 return $trace; }
489  
490 # Extract blessed `interesting' objects on stack.
491 # Get a maximum of $maxdepth objects (if $maxdepth is defined).
492 sub objectStack {
493 0 ▶ my ($maxdepth) = @_;
Subroutine objectStack: not called CC=15 SCAR=54.8
Pod documented
494 0 my $frame = 0;
495 0 my @objects = ();
496 0 while (1) {
497 0 my (%info, @args);
498 0 { package DB;
499 0 @info{qw(package file line sub has_args wantarray evaltext is_require)} = caller($frame++);
500 0 @args = @DB::args; }
501 0 ▶ last unless defined $info{package};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info{"package"} 0 0 0
502 0 ▶ next if ($info{sub} eq '(eval)') || !$info{has_args} || !@args;
Branch: 1 branch
BranchTrueFalseTotal
if $info{"sub"} eq "(eval)" or not $info{"has_args"} or not @args 0 0 0
Condition0%0/6
$info{"sub"} eq "(eval)" or not $info{"has_args"} or not @args
l!l&&r!l&&!r
000
$info{"sub"} eq "(eval)" or not $info{"has_args"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$info{"sub"} eq "(eval)" or not $info{"has_args"} or not @args
$info{"sub"} eq "(eval)" not $info{"has_args"} not @args
Truth table0%0/4
A or not(B) or not(C)
A= $info{"sub"} eq "(eval)"B= not $info{"has_args"}C= not @args
ABCresult
1XX1
01X1
0011
0000
503 0 my $self = $args[0];
504 # If $arg[0] is blessed, and `can' do $method, then we'll guess it's a method call?
505 # We'll collect such objects provided they can ->getLocator
506 0 ▶ if ((ref $self) && ((ref $self) !~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and not ref($self) =~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/) 0 0 0
Condition0%0/3
ref $self and not ref($self) =~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self and not ref($self) =~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/
ref $self not ref($self) =~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/
Truth table0%0/3
A and not(B)
A= ref $selfB= not ref($self) =~ /^(?:SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE)$/
ABresult
0X0
100
111
507 0 my $method = $info{sub};
508 0 $method =~ s/^.*:://;
509 0 ▶ if ($self->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($method)) 0 0 0
510 0 ▶ next if @objects && ($self eq $objects[-1][0]); # but don't duplicate
Branch: 1 branch
BranchTrueFalseTotal
if @objects and $self eq $objects[-1][0] 0 0 0
Condition0%0/3
@objects and $self eq $objects[-1][0]
!ll&&!rl&&r
000
MC/DC0%0/2
@objects and $self eq $objects[-1][0]
@objects $self eq $objects[-1][0]
Truth table0%0/3
A and B
A= @objectsB= $self eq $objects[-1][0]
ABresult
0X0
100
111
511 0 ▶ if ($self->can('getLocator')) { # Digestion object?
Branch: 2 branches
BranchTrueFalseTotal
if ($self->can('getLocator')) { } 0 0 0
elsif ($self->isa('LaTeXML::Post::Processor') or $self->isa('LaTeXML::Post::Document')) { } 0 0 0
512 0 push(@objects, [$self, Locator($self)]); }
513 ▶ elsif ($self->isa('LaTeXML::Post::Processor') || $self->isa('LaTeXML::Post::Document')) {
Condition0%0/3
$self->isa("LaTeXML::Post::Processor") or $self->isa("LaTeXML::Post::Document")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->isa("LaTeXML::Post::Processor") or $self->isa("LaTeXML::Post::Document")
$self->isa("LaTeXML::Post::Processor") $self->isa("LaTeXML::Post::Document")
Truth table0%0/3
A or B
A= $self->isa("LaTeXML::Post::Processor")B= $self->isa("LaTeXML::Post::Document")
ABresult
1X1
011
000
514 0 push(@objects, [$self, '->' . $method]); }
515 0 ▶ last if $maxdepth && (scalar(@objects) >= $maxdepth); } } }
Branch: 1 branch
BranchTrueFalseTotal
if $maxdepth and scalar @objects >= $maxdepth 0 0 0
Condition0%0/3
$maxdepth and scalar @objects >= $maxdepth
!ll&&!rl&&r
000
MC/DC0%0/2
$maxdepth and scalar @objects >= $maxdepth
$maxdepth scalar @objects >= $maxdepth
Truth table0%0/3
A and B
A= $maxdepthB= scalar @objects >= $maxdepth
ABresult
0X0
100
111
516 0 return @objects; }
517  
518 #**********************************************************************
519 29 1;
520  
521 __END__
« lib/LaTeXML/Post/LaTeXImages.pm ↑ Summary lib/LaTeXML/Post/CrossRef.pm »