blib/lib/Pod/PseudoPod/LaTeX.pm

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