blib/lib/Pod/PseudoPod/LaTeX.pm

filter: Statementstmt 69.9% 244 / 349 Branchbran 64.8% 48 / 74 Conditioncond 45.0% 9 / 20 MC/DCmcdc 25.0% 3 / 12 Subroutinesub 78.0% 57 / 73 Podpod 2.4% 1 / 41 totaltotal 63.6% 362 / 569 CC 51 SCAR 13.6
CC
51
Cov
68%
end_table
20.0
end_A
12.0
start_table
12.0
CRAP 3.9
↑ Summary
1 package Pod::PseudoPod::LaTeX;
2 7 $Pod::PseudoPod::LaTeX::VERSION = '1.20160626';
3 7 ▶use Pod::PseudoPod 0.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 ▶use base 'Pod::PseudoPod';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use 5.008006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12  
13 sub new
14 {
15 10 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=5 SCAR=16.1
Pod documented
16 10 my $self = $class->SUPER::new(%args);
17  
18 10 ▶ $self->{keep_ligatures} = exists($args{keep_ligatures}) ? $args{keep_ligatures} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'keep_ligatures'} ? : 1 9 10
19 10 ▶ $self->{captions_below} = exists($args{captions_below}) ? $args{captions_below} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'captions_below'} ? : 1 9 10
20 10 ▶ $self->{full} = exists($args{full}) ? $args{full} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'full'} ? : 3 7 10
21  
22 # These have their contents parsed
23 10 $self->accept_targets_as_text(
24 qw( sidebar blockquote programlisting screen figure table
25 PASM PIR PIR_FRAGMENT PASM_FRAGMENT PIR_FRAGMENT_INVALID )
26 );
27  
28 # These do not. Content is not touched.
29 10 $self->accept_target('latex');
30  
31 10 ▶ $self->{scratch} ||= '';
Condition50%1/2
$self->{"scratch"} ||= ""
l!l
010
MC/DC0%0/1
$self->{"scratch"} ||= ""
$self->{"scratch"}
Truth table50%1/2
A
A= $self->{"scratch"}
Aresult
11
00
32 10 $self->{stack} = [];
33 10 $self->{labels} = { screen => 'Program output' };
34  
35 10 return $self;
36 }
37  
38 sub emit_environments
39 {
40 2 ▶ my ( $self, %env ) = @_;
Subroutine emit_environments: called CC=2 SCAR=6.9
Pod undocumented
41 2 for ( keys %env )
42 {
43 2 $self->{emit_environment}->{$_} = $env{$_};
44 }
45 }
46  
47 sub start_Document
48 {
49 8 ▶ my $self = shift;
Subroutine start_Document: called CC=2 SCAR=6.9
Pod undocumented
50 8 ▶ if ($self->{full}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"full"}) 1 7 8
51 1 $self->{scratch} .= "\\documentclass[12pt,a4paper]{book}\n"
52 . "\\usepackage{fancyvrb}\n"
53 . "\\usepackage{url}\n"
54 . "\\usepackage{titleref}\n"
55 . "\\usepackage[T1]{fontenc}\n"
56 . "\\usepackage{textcomp}\n"
57 . "\\begin{document}\n";
58 }
59 }
60  
61 sub end_Document
62 {
63 8 ▶ my $self = shift;
Subroutine end_Document: called CC=2 SCAR=6.9
Pod undocumented
64 8 ▶ $self->{scratch} .= "\\end{document}\n" if $self->{full};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"full"} 1 7 8
65 8 $self->emit();
66 }
67  
68 sub emit
69 {
70 465 ▶ my $self = shift;
Subroutine emit: called CC=2 SCAR=6.9
Pod undocumented
71 465 ▶ return unless defined $self->{scratch};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"scratch"} 7 458 465
72 458 print { $self->{output_fh} } delete $self->{scratch};
73 }
74  
75 sub handle_text
76 {
77 745 ▶ my ( $self, $text ) = @_;
Subroutine handle_text: called CC=1 SCAR=0.0
Pod undocumented
78 745 $self->{scratch} .= $self->encode_text($text);
79 }
80  
81 sub encode_text
82 {
83 753 ▶ my ( $self, $text ) = @_;
Subroutine encode_text: called CC=8 SCAR=20.8
Pod undocumented
84  
85 753 my $resolve = 1;
86 753 eval {
87 7 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
88 753 ▶ if (exists($self->{curr_open}[-1][-1]{'~resolve'}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"curr_open"}[-1][-1]{"~resolve"} and $self->{"curr_open"}[-1][-1]{"~resolve"} == 0) 9 232 241
Condition100%3/3
exists $self->{"curr_open"}[-1][-1]{"~resolve"} and $self->{"curr_open"}[-1][-1]{"~resolve"} == 0
!ll&&!rl&&r
184489
MC/DC100%2/2
exists $self->{"curr_open"}[-1][-1]{"~resolve"} and $self->{"curr_open"}[-1][-1]{"~resolve"} == 0
exists $self->{"curr_open"}[-1][-1]{"~resolve"} $self->{"curr_open"}[-1][-1]{"~resolve"} == 0
Truth table100%3/3
A and B
A= exists $self->{"curr_open"}[-1][-1]{"~resolve"}B= $self->{"curr_open"}[-1][-1]{"~resolve"} == 0
ABresult
0X0
100
111
89 $self->{curr_open}[-1][-1]{'~resolve'} == 0)
90 {
91 9 $resolve = 0;
92 }
93 };
94 753 ▶ return $text unless $resolve;
Branch: 1 branch
BranchTrueFalseTotal
unless $resolve 9 744 753
95  
96 744 ▶ return $self->encode_verbatim_text($text) if $self->{flags}{in_verbatim};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"flags"}{"in_verbatim"} 24 720 744
97 720 ▶ return $text if $self->{flags}{in_xref};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"flags"}{"in_xref"} 0 720 720
98 720 ▶ return $text if $self->{flags}{in_figure};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"flags"}{"in_figure"} 8 712 720
99  
100 # Escape LaTeX-specific characters
101 712 $text =~ s/\\/\\backslash/g; # backslashes are special
102 712 $text =~ s/([#\$&%_{}])/\\$1/g;
103 712 $text =~ s/(\^)/\\char94{}/g; # carets are special
104 712 $text =~ s/</\\textless{}/g;
105 712 $text =~ s/>/\\textgreater{}/g;
106  
107 712 $text =~ s/(\\backslash)/\$$1\$/g; # add unescaped dollars
108  
109 # use the right beginning quotes
110 712 $text =~ s/(^|\s)"/$1``/g;
111  
112 # and the right ending quotes
113 712 $text =~ s/"(\W|$)/''$1/g;
114  
115 # fix the ellipses
116 712 $text =~ s/\.{3}\s*/\\ldots /g;
117  
118 # fix the ligatures
119 712 ▶ $text =~ s/f([fil])/f\\mbox{}$1/g unless $self->{keep_ligatures};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"keep_ligatures"} 712 0 712
120  
121 # fix emdashes
122 712 $text =~ s/\s--\s/---/g;
123  
124 # fix tildes
125 712 $text =~ s/~/\$\\sim\$/g;
126  
127 # suggest hyphenation points for module names
128 712 $text =~ s/::/::\\-/g;
129  
130 712 return $text;
131 }
132  
133 # in verbatim mode, some things still need escaping - otherwise markup
134 # wouldn't work when the codes_in_verbatim option is enabled.
135 sub encode_verbatim_text {
136 24 ▶ my ($self, $text) = @_;
Subroutine encode_verbatim_text: called CC=1 SCAR=0.0
Pod undocumented
137  
138 24 $text =~ s/([{}])/\\$1/g;
139 24 $text =~ s/\\(?![{}])/\\textbackslash{}/g;
140  
141 24 return $text;
142 }
143  
144 sub start_head0
145 {
146 8 ▶ my $self = shift;
Subroutine start_head0: called CC=1 SCAR=0.0
Pod undocumented
147 8 $self->{scratch} .= '\\chapter{';
148 }
149  
150 sub end_head0
151 {
152 8 ▶ my $self = shift;
Subroutine end_head0: called CC=1 SCAR=0.0
Pod undocumented
153 8 $self->{scratch} .= "}\n\n";
154 8 $self->emit();
155 }
156  
157 sub end_Para
158 {
159 224 ▶ my $self = shift;
Subroutine end_Para: called CC=1 SCAR=0.0
Pod undocumented
160 224 $self->{scratch} .= "\n\n";
161 224 $self->emit();
162 }
163  
164 BEGIN
165 {
166 7 ▶ for my $level ( 1 .. 5 )
Subroutine BEGIN: called CC=2 SCAR=6.9
167 {
168 35 my $prefix = '\\' . ( 'sub' x ( $level - 1 ) ) . 'section*{';
169 my $start_sub = sub {
170 32 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
171 32 $self->{scratch} .= $prefix;
172 35 };
173  
174 my $end_sub = sub {
175 32 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
176 32 $self->{scratch} .= "}\n\n";
177 32 $self->emit();
178 35 };
179  
180 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
181 35 *{ 'start_head' . $level } = $start_sub;
182 35 *{ 'end_head' . $level } = $end_sub;
183 }
184 }
185  
186 sub start_E
187 {
188 48 ▶ my $self = shift;
Subroutine start_E: called CC=1 SCAR=0.0
Pod undocumented
189 48 push @{ $self->{stack} }, delete $self->{scratch};
190 48 $self->{scratch} = '';
191 }
192  
193 my %characters = (
194 8 ▶ acute => sub { qq|\\'| . shift },
Subroutine __ANON__: called CC=1 SCAR=0.0
195 8 ▶ grave => sub { qq|\\`| . shift },
Subroutine __ANON__: called CC=1 SCAR=0.0
196 8 ▶ uml => sub { qq|\\"| . shift },
Subroutine __ANON__: called CC=1 SCAR=0.0
197 8 ▶ cedilla => sub { '\c{c}' }, # ccedilla
Subroutine __ANON__: called CC=1 SCAR=0.0
198 8 ▶ opy => sub { '\copyright' }, # copy
Subroutine __ANON__: called CC=1 SCAR=0.0
199 0 ▶ dash => sub { '---' }, # mdash
Subroutine __ANON__: not called CC=1 SCAR=6.9
200 8 ▶ lusmn => sub { '\ensuremath{\pm}' }, # plusmn
Subroutine __ANON__: called CC=1 SCAR=0.0
201 0 ▶ mp => sub { '\&' }, # amp
Subroutine __ANON__: not called CC=1 SCAR=6.9
202 7 );
203  
204 sub end_E
205 {
206 48 ▶ my $self = shift;
Subroutine end_E: called CC=3 SCAR=11.7
Pod undocumented
207 48 my $clean_entity;
208  
209 # XXX - error checking here
210 48 my $entity = delete $self->{scratch};
211 48 $entity =~ /(\w)(\w+)/;
212  
213 48 ▶ if ( exists $characters{$2} )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $characters{$2}) { } 48 0 48
elsif ($clean_entity = Pod::Escapes::e2char($entity)) { } 0 0 0
214 {
215 48 $clean_entity = $characters{$2}->($1);
216 }
217 elsif ( $clean_entity = Pod::Escapes::e2char($entity) )
218 {
219 }
220 else
221 {
222 0 die "Unrecognized character '$entity'\n";
223 }
224  
225 48 $self->{scratch} = pop @{ $self->{stack} };
226 48 $self->{scratch} .= $clean_entity;
227 }
228  
229 ▶sub _treat_Es { }
Subroutine _treat_Es: called CC=1 SCAR=0.0
230  
231 sub start_X
232 {
233 48 ▶ my $self = shift;
Subroutine start_X: called CC=1 SCAR=0.0
Pod undocumented
234 48 push @{ $self->{stack} }, delete $self->{scratch};
235 48 $self->{scratch} = '';
236 }
237  
238 sub end_X
239 {
240 48 ▶ my $self = shift;
Subroutine end_X: called CC=2 SCAR=6.9
Pod undocumented
241 48 my $terms_text = delete $self->{scratch};
242 48 my @terms;
243 48 for my $t (split ',', $terms_text) {
244 56 $t =~ s/^\s+|\s+$//g;
245 56 $t =~ s/"/""/g;
246 56 $t =~ s/([!|@])/"$1/g;
247 56 push @terms, $t;
248 }
249 {
250 7 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
251 48 $self->{scratch} = pop(@{ $self->{stack} })
252 . '\\index{' . join('!', @terms) . '}';
253 }
254 }
255  
256 sub start_Z
257 {
258 0 ▶ my $self = shift;
Subroutine start_Z: not called CC=1 SCAR=6.9
Pod undocumented
259 0 push @{ $self->{stack} }, delete $self->{scratch};
260 0 $self->{scratch} = '';
261 0 $self->{flags}{in_xref}++;
262 }
263  
264 sub end_Z
265 {
266 0 ▶ my $self = shift;
Subroutine end_Z: not called CC=1 SCAR=2.9
Pod undocumented
267 0 my $clean_xref = delete $self->{scratch};
268  
269 # sanitize crossreference names
270 0 $clean_xref =~ s/[^\w:]/-/g;
271  
272 {
273 7 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.2
274 0 $self->{scratch} = pop( @{ $self->{stack} } )
275 . '\\label{' . $clean_xref . '}';
276 }
277 0 $self->{flags}{in_xref}--;
278 }
279  
280 sub start_A
281 {
282 0 ▶ my $self = shift;
Subroutine start_A: not called CC=1 SCAR=6.9
Pod undocumented
283 0 push @{ $self->{stack} }, delete $self->{scratch};
284  
285 0 $self->{scratch} = '';
286 0 $self->{flags}{in_xref}++;
287 }
288  
289 sub end_A
290 {
291 0 ▶ my $self = shift;
Subroutine end_A: not called CC=3 SCAR=24.8
Pod undocumented
292 0 my $clean_xref = delete $self->{scratch};
293  
294 # sanitize crossreference names
295 0 $clean_xref =~ s/[^\w:]/-/g;
296 0 $self->{scratch} = pop @{ $self->{stack} };
297  
298 # Figures have a different xref format
299 0 ▶ if ( $clean_xref =~ /^fig:/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($clean_xref =~ /^fig:/) { } 0 0 0
elsif ($clean_xref =~ /^table:/) { } 0 0 0
300 {
301 0 $self->{scratch} .= 'Figure \\ref{' . $clean_xref . '} ';
302 }
303 # Tables have a different xref format
304 elsif ( $clean_xref =~ /^table:/ )
305 {
306 0 $self->{scratch} .= 'Table \\ref{' . $clean_xref . '} ';
307 }
308 else
309 {
310 0 $self->{scratch} .= '\\emph{\\titleref{' . $clean_xref . '}}';
311 }
312  
313 0 $self->{scratch} .= ' on page~'
314 . '\\pageref{' . $clean_xref . '}';
315  
316 0 $self->{flags}{in_xref}--;
317 }
318  
319 sub start_F
320 {
321 8 ▶ my $self = shift;
Subroutine start_F: called CC=2 SCAR=9.2
Pod undocumented
322  
323 8 ▶ if ( $self->{flags}{in_figure} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'flags'}{'in_figure'}) { } 0 8 8
324 {
325 0 push @{ $self->{stack} }, delete $self->{scratch};
326 0 $self->{scratch} = '';
327 }
328 else
329 {
330 8 $self->{scratch} .= '\\emph{';
331 }
332 }
333  
334 sub end_F
335 {
336 8 ▶ my $self = shift;
Subroutine end_F: called CC=2 SCAR=10.5
Pod undocumented
337  
338 8 ▶ if ( $self->{flags}{in_figure} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'flags'}{'in_figure'}) { } 0 8 8
339 {
340 0 my $raw_filename = delete $self->{scratch};
341 0 $self->{scratch} = pop @{ $self->{stack} };
342  
343 # extract bare image filename
344 0 $raw_filename =~ /(\w+)\.\w+$/;
345 0 $self->{scratch} .= "\n\\includegraphics{" . $1 . '}';
346 }
347 else
348 {
349 8 $self->{scratch} .= '}';
350 }
351 }
352  
353 sub start_for
354 {
355 33 ▶ my ( $self, $flags ) = @_;
Subroutine start_for: called CC=6 SCAR=18.6
Pod undocumented
356  
357 33 ▶ if ($flags->{target} =~ /^latex$/i) { # support latex, LaTeX, et al
Branch: 2 branches
BranchTrueFalseTotal
if ($flags->{'target'} =~ /^latex$/i) { } 8 25 33
elsif (exists $flags->{'~really'} and $flags->{'~really'} eq '=begin' and exists $self->{'emit_environment'}{$flags->{'target'}}) { } 1 24 25
358 8 $self->{scratch} .= "\n\n";
359 ▶ } elsif (exists($flags->{'~really'}) &&
Condition50%3/6
exists $flags->{"~really"} and $flags->{"~really"} eq "=begin" and exists $self->{"emit_environment"}{$flags->{"target"}}
!ll&&!rl&&r
0241
exists $flags->{"~really"} and $flags->{"~really"} eq "=begin"
!ll&&!rl&&r
0025
MC/DC33%1/3
exists $flags->{"~really"} and $flags->{"~really"} eq "=begin" and exists $self->{"emit_environment"}{$flags->{"target"}}
exists $flags->{"~really"} $flags->{"~really"} eq "=begin" exists $self->{"emit_environment"}{$flags->{"target"}}
Truth table50%2/4
A and B and C
A= exists $flags->{"~really"}B= $flags->{"~really"} eq "=begin"C= exists $self->{"emit_environment"}{$flags->{"target"}}
ABCresult
0XX0
10X0
1100
1111
360 $flags->{'~really'} eq "=begin" &&
361 exists($self->{emit_environment}{$flags->{target}})) {
362 1 my $title = "";
363 1 ▶ $title = "{".$flags->{title}."}" if exists $flags->{title};
Branch: 1 branch
BranchTrueFalseTotal
if exists $flags->{"title"} 1 0 1
364 $self->{scratch} .= sprintf("\n\\begin{%s}%s\n",
365 $self->{emit_environment}{$flags->{target}},
366 1 $title);
367 }
368 }
369  
370 sub end_for
371 {
372 33 ▶ my ( $self, $flags ) = @_;
Subroutine end_for: called CC=3 SCAR=11.0
Pod undocumented
373  
374 33 ▶ if ($flags->{target} =~ /^latex$/i) { # support latex, LaTeX, et al
Branch: 2 branches
BranchTrueFalseTotal
if ($flags->{'target'} =~ /^latex$/i) { } 8 25 33
elsif (exists $self->{'emit_environment'}{$flags->{'target'}}) { } 1 24 25
375 8 $self->{scratch} .= "\n\n";
376 8 $self->emit;
377 } elsif (exists($self->{emit_environment}{$flags->{target}})) {
378 $self->{scratch} .= sprintf("\\end{%s}\n\n",
379 1 $self->{emit_environment}{$flags->{target}});
380 1 $self->emit;
381 }
382 }
383  
384 sub start_Verbatim
385 {
386 24 ▶ my $self = shift;
Subroutine start_Verbatim: called CC=3 SCAR=11.0
Pod undocumented
387  
388 24 my $verb_options = "commandchars=\\\\\\{\\}";
389 24 eval {
390 7 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
391 24 ▶ if ($self->{curr_open}[-1][-1]{target} eq 'screen') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"curr_open"}[-1][-1]{"target"} eq "screen") 8 8 16
392 8 ▶ my $label = $self->{curr_open}[-1][-1]{title} || $self->{labels}{screen};
Condition33%1/3
$self->{'curr_open'}[-1][-1]{'title'} || $self->{'labels'}{'screen'}
l!l&&r!l&&!r
080
MC/DC0%0/2
$self->{'curr_open'}[-1][-1]{'title'} || $self->{'labels'}{'screen'}
$self->{'curr_open'}[-1][-1]{'title'} $self->{'labels'}{'screen'}
Truth table33%1/3
A || B
A= $self->{'curr_open'}[-1][-1]{'title'}B= $self->{'labels'}{'screen'}
ABresult
1X1
011
000
393 8 $verb_options .= ",frame=single,label=$label";
394 }
395 };
396  
397 24 $self->{scratch} .= "\\vspace{-6pt}\n"
398 . "\\scriptsize\n"
399 . "\\begin{Verbatim}[$verb_options]\n";
400 24 $self->{flags}{in_verbatim}++;
401 }
402  
403 sub end_Verbatim
404 {
405 24 ▶ my $self = shift;
Subroutine end_Verbatim: called CC=1 SCAR=0.0
Pod undocumented
406  
407 24 $self->{scratch} .= "\n\\end{Verbatim}\n"
408 . "\\vspace{-6pt}\n";
409  
410 # $self->{scratch} .= "\\addtolength{\\parskip}{5pt}\n";
411 24 $self->{scratch} .= "\\normalsize\n";
412 24 $self->{flags}{in_verbatim}--;
413 24 $self->emit();
414 }
415  
416 sub end_screen
417 {
418 0 ▶ my $self = shift;
Subroutine end_screen: not called CC=1 SCAR=6.9
Pod undocumented
419 0 $self->{scratch} .= "\n\\end{Verbatim}\n"
420 . "\\vspace{-6pt}\n";
421  
422 # $self->{scratch} .= "\\addtolength{\\parskip}{5pt}\n";
423 0 $self->{scratch} .= "\\normalsize\n";
424 0 $self->{flags}{in_verbatim}--;
425 0 $self->emit();
426 }
427  
428 sub start_figure
429 {
430 8 ▶ my ( $self, $flags ) = @_;
Subroutine start_figure: called CC=3 SCAR=11.2
Pod undocumented
431  
432 8 $self->{scratch} .= "\\begin{figure}[!h]\n";
433  
434 8 $self->{_dangling_title} = undef; # just in case; Do not think it is worth a stack.
435 8 ▶ if ( $flags->{title} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags->{"title"}) 8 0 8
436 8 ▶ if ($self->{captions_below}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'captions_below'}) { } 0 8 8
437 0 $self->{_dangling_title} = $flags->{title};
438 }
439 else {
440 8 my $title = $self->encode_text( $flags->{title} );
441 8 $title =~ s/^graphic\s*//;
442 8 $self->{scratch} .= "\\caption{" . $title . "}\n";
443 }
444 }
445  
446 8 $self->{scratch} .= "\\begin{center}\n";
447 8 $self->{flags}{in_figure}++;
448 }
449  
450 sub end_figure
451 {
452 8 ▶ my $self = shift;
Subroutine end_figure: called CC=3 SCAR=13.6
Pod undocumented
453 8 $self->{scratch} .= "\\end{center}\n";
454  
455 8 ▶ if ($self->{captions_below} && $self->{_dangling_title})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"captions_below"} and $self->{"_dangling_title"}) 0 8 8
Condition33%1/3
$self->{"captions_below"} and $self->{"_dangling_title"}
!ll&&!rl&&r
800
MC/DC0%0/2
$self->{"captions_below"} and $self->{"_dangling_title"}
$self->{"captions_below"} $self->{"_dangling_title"}
Truth table33%1/3
A and B
A= $self->{"captions_below"}B= $self->{"_dangling_title"}
ABresult
0X0
100
111
456 {
457 0 my $title = $self->encode_text( $self->{_dangling_title} );
458 0 $title =~ s/^graphic\s*//;
459 0 $self->{scratch} .= "\\caption{" . $title . "}\n";
460 0 $self->{_dangling_title} = undef; # clear it
461 }
462  
463 8 $self->{scratch} .= "\\end{figure}\n";
464 8 $self->{flags}{in_figure}--;
465 8 $self->emit();
466 }
467  
468 sub start_table
469 {
470 0 ▶ my ( $self, $flags) = @_;
Subroutine start_table: not called CC=3 SCAR=24.8
Pod undocumented
471  
472 # Open the table
473 0 $self->{scratch} .= "\\begin{table}[!h]\n";
474  
475 0 $self->{_dangling_title} = undef; # just in case; Do not think it is worth a stack.
476 0 ▶ if ( $flags->{title} )
Branch: 1 branch
BranchTrueFalseTotal
if ($flags->{"title"}) 0 0 0
477 {
478 0 ▶ if ($self->{captions_below}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'captions_below'}) { } 0 0 0
479 0 $self->{_dangling_title} = $flags->{title};
480 }
481 else {
482 0 my $title = $self->encode_text( $flags->{title} );
483 0 $title =~ s/^graphic\s*//;
484 0 $self->{scratch} .= "\\caption{" . $title . "}\n";
485 }
486 }
487 0 $self->{scratch} .= "\\begin{center}\n";
488  
489 0 $self->{flags}{in_table}++;
490 0 delete $self->{table_rows};
491 }
492  
493 sub end_table
494 {
495 0 ▶ my $self = shift;
Subroutine end_table: not called CC=4 SCAR=30.0
Pod undocumented
496  
497 # Format the table body
498 0 my $column_count = @{ $self->{table_rows}[0] };
499 0 my $format_spec = '|' . ( 'l|' x $column_count );
500  
501 # first row is gray
502 0 $self->{scratch} .= "\\begin{tabular}{$format_spec}\n"
503 . "\\hline\n"
504 . "\\rowcolor[gray]{.9}\n";
505  
506 # Format each row
507 0 my $row;
508 0 for $row ( @{ $self->{table_rows} } )
509 {
510 0 $self->{scratch} .= join( ' & ', @$row )
511 . "\\\\ \\hline\n";
512 }
513  
514 # Close the table
515 0 $self->{scratch} .= "\\end{tabular}\n"
516 . "\\end{center}\n";
517  
518  
519 0 ▶ if ($self->{captions_below} && $self->{_dangling_title})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"captions_below"} and $self->{"_dangling_title"}) 0 0 0
Condition0%0/3
$self->{"captions_below"} and $self->{"_dangling_title"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"captions_below"} and $self->{"_dangling_title"}
$self->{"captions_below"} $self->{"_dangling_title"}
Truth table0%0/3
A and B
A= $self->{"captions_below"}B= $self->{"_dangling_title"}
ABresult
0X0
100
111
520 {
521 0 my $title = $self->encode_text( $self->{_dangling_title} );
522 0 $title =~ s/^graphic\s*//;
523 0 $self->{scratch} .= "\\caption{" . $title . "}\n";
524 0 $self->{_dangling_title} = undef; # clear it
525 }
526  
527 0 $self->{scratch}.= "\\end{table}\n";
528  
529 0 $self->{flags}{in_table}--;
530 0 delete $self->{table_rows};
531  
532 0 $self->emit();
533 }
534  
535 sub start_headrow
536 {
537 0 ▶ my $self = shift;
Subroutine start_headrow: not called CC=1 SCAR=6.9
Pod undocumented
538 0 $self->{in_headrow}++;
539 }
540  
541 sub start_bodyrows
542 {
543 0 ▶ my $self = shift;
Subroutine start_bodyrows: not called CC=1 SCAR=6.9
Pod undocumented
544 0 $self->{in_headrow}--;
545 }
546  
547 sub start_row
548 {
549 0 ▶ my $self = shift;
Subroutine start_row: not called CC=1 SCAR=6.9
Pod undocumented
550 0 delete $self->{table_current_row};
551 }
552  
553 sub end_row
554 {
555 0 ▶ my $self = shift;
Subroutine end_row: not called CC=1 SCAR=6.9
Pod undocumented
556 0 push @{ $self->{table_rows} }, $self->{table_current_row};
557 0 delete $self->{table_current_row};
558 }
559  
560 sub start_cell
561 {
562 0 ▶ my $self = shift;
Subroutine start_cell: not called CC=1 SCAR=6.9
Pod undocumented
563 0 push @{ $self->{stack} }, delete $self->{scratch};
564 0 $self->{scratch} = '';
565 }
566  
567 sub end_cell
568 {
569 0 ▶ my $self = shift;
Subroutine end_cell: not called CC=2 SCAR=17.9
Pod undocumented
570 0 my $cell_contents = delete $self->{scratch};
571  
572 0 ▶ if ( $self->{in_headrow} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"in_headrow"}) 0 0 0
573 {
574 0 $cell_contents = '\\textbf{\\textsf{' . $cell_contents . '}}';
575 }
576  
577 0 push @{ $self->{table_current_row} }, $cell_contents;
578 0 $self->{scratch} = pop @{ $self->{stack} };
579 }
580  
581 BEGIN
582 {
583 7 ▶ for my $listtype (
Subroutine BEGIN: called CC=2 SCAR=6.9
584 [qw( bullet itemize )], [qw( number enumerate )],
585 [qw( text description )], [qw( block description )],
586 )
587 {
588  
589 my $start_sub = sub {
590 40 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
591 40 $self->{scratch} .= "\\vspace{-5pt}\n"
592 . "\n\\begin{$listtype->[1]}\n\n"
593 . "\\setlength{\\topsep}{0pt}\n"
594 . "\\setlength{\\itemsep}{0pt}\n";
595  
596 # $self->{scratch} .= "\\setlength{\\parskip}{0pt}\n";
597 # $self->{scratch} .= "\\setlength{\\parsep}{0pt}\n";
598 28 };
599  
600 my $end_sub = sub {
601 40 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
602 40 $self->{scratch} .= "\\end{$listtype->[1]}\n\n"
603 . "\\vspace{-5pt}\n";
604 40 $self->emit();
605 28 };
606  
607 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
608 28 *{ 'start_over_' . $listtype->[0] } = $start_sub;
609 28 *{ 'end_over_' . $listtype->[0] } = $end_sub;
610 }
611 }
612  
613 sub start_item_bullet
614 {
615 24 ▶ my $self = shift;
Subroutine start_item_bullet: called CC=1 SCAR=0.0
Pod undocumented
616 24 $self->{scratch} .= '\item ';
617 }
618  
619 sub start_item_number
620 {
621 0 ▶ my ( $self, $flags ) = @_;
Subroutine start_item_number: not called CC=1 SCAR=6.9
Pod undocumented
622  
623 # $self->{scratch} .= "\\item[$flags->{number}] ";
624 0 $self->{scratch} .= "\\item "; # LaTeX will auto-number
625 }
626  
627 sub start_item_text
628 {
629 88 ▶ my $self = shift;
Subroutine start_item_text: called CC=1 SCAR=0.0
Pod undocumented
630 88 $self->{scratch} .= '\item[] ';
631 }
632  
633 sub start_sidebar
634 {
635 8 ▶ my ( $self, $flags ) = @_;
Subroutine start_sidebar: called CC=5 SCAR=16.6
Pod undocumented
636  
637 8 my $title;
638 8 ▶ $title = $self->encode_text( $flags->{title} ) if $flags->{title};
Branch: 1 branch
BranchTrueFalseTotal
if $flags->{"title"} 0 8 8
639  
640 8 ▶ if ( $self->{emit_environment}->{sidebar} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'emit_environment'}{'sidebar'}) { } 1 7 8
641 {
642 1 $self->{scratch} .= "\\begin{" . $self->{emit_environment}->{sidebar} . "}";
643 1 ▶ $self->{scratch} .= "[$title]" if $title;
Branch: 1 branch
BranchTrueFalseTotal
if $title 0 1 1
644 1 $self->{scratch} .= "\n";
645 }
646 else
647 {
648 7 $self->{scratch} .= "\\begin{figure}[!h]\n"
649 . "\\begin{center}\n"
650 . "\\framebox{\n"
651 . "\\begin{minipage}{3.5in}\n"
652 . "\\vspace{3pt}\n\n";
653  
654 7 ▶ if ( $title )
Branch: 1 branch
BranchTrueFalseTotal
if ($title) 0 7 7
655 {
656 0 $self->{scratch} .= "\\begin{center}\n"
657 . "\\large{\\bfseries{" . $title . "}}\n"
658 . "\\end{center}\n\n";
659 }
660 }
661 }
662  
663 sub end_sidebar
664 {
665 8 ▶ my $self = shift;
Subroutine end_sidebar: called CC=2 SCAR=6.9
Pod undocumented
666 8 ▶ if ( $self->{emit_environment}->{sidebar} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'emit_environment'}{'sidebar'}) { } 1 7 8
667 {
668 $self->{scratch} .= "\\end{"
669 1 . $self->{emit_environment}->{sidebar} . "}\n\n";
670 }
671 else
672 {
673 7 $self->{scratch} .= "\\vspace{3pt}\n"
674 . "\\end{minipage}\n"
675 # end framebox
676 . "}\n"
677 . "\\end{center}\n"
678 . "\\end{figure}\n";
679 }
680 }
681  
682 BEGIN
683 {
684 7 ▶ for my $end (qw( bullet number text))
Subroutine BEGIN: called CC=3 SCAR=11.0
685 {
686 my $end_sub = sub {
687 112 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
688 112 $self->{scratch} .= "\n\n";
689 112 $self->emit();
690 21 };
691  
692 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
693 21 *{ 'end_item_' . $end } = $end_sub;
694 }
695  
696 7 my %formats = (
697 B => [ '\\textbf', '' ],
698 C => [ '\\texttt', '' ],
699 I => [ '\\emph', '' ],
700 U => [ '\\url', '' ],
701 R => [ '\\emph', '' ],
702 L => [ '\\url', '' ],
703 N => [ '\\footnote', '' ],
704 G => [ '$^', '$' ],
705 H => [ '$_', '$' ],
706 );
707  
708 7 ▶ while ( my ( $code, $fixes ) = each %formats )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %formats) 63 7 70
709 {
710 my $start_sub = sub {
711 80 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
712 80 $self->{scratch} .= $fixes->[0] . '{';
713 63 };
714  
715 my $end_sub = sub {
716 80 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
717 80 $self->{scratch} .= '}' . $fixes->[1];
718 63 };
719  
720 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
721 63 *{ 'start_' . $code } = $start_sub;
722 63 *{ 'end_' . $code } = $end_sub;
723 }
724  
725 }
726  
727 7 1;
728 __END__
↑ Summary