Simple/XHTML.pm

filter: Statementstmt 98.8% 331 / 335 Branchbran 82.8% 106 / 128 Conditioncond 68.4% 39 / 57 MC/DCmcdc 43.7% 14 / 32 Subroutinesub 97.2% 70 / 72 Podpod 13.8% 9 / 65 totaltotal 82.5% 569 / 689 CC 91 SCAR 17.4
CC
91
Cov
92%
decode_entities
16.4
start_Document
13.5
build_index
13.0
CRAP 5.7
« Simple/LinkSection.pm ↑ Summary Simple/Checker.pm »
1 =pod
2  
3 =head1 NAME
4  
5 Pod::Simple::XHTML -- format Pod as validating XHTML
6  
7 =head1 SYNOPSIS
8  
9 use Pod::Simple::XHTML;
10  
11 my $parser = Pod::Simple::XHTML->new();
12  
13 ...
14  
15 $parser->parse_file('path/to/file.pod');
16  
17 =head1 DESCRIPTION
18  
19 This class is a formatter that takes Pod and renders it as XHTML
20 validating HTML.
21  
22 This is a subclass of L<Pod::Simple::Methody> and inherits all its
23 methods. The implementation is entirely different than
24 L<Pod::Simple::HTML>, but it largely preserves the same interface.
25  
26 =head2 Minimal code
27  
28 use Pod::Simple::XHTML;
29 my $psx = Pod::Simple::XHTML->new;
30 $psx->output_string(\my $html);
31 $psx->parse_file('path/to/Module/Name.pm');
32 open my $out, '>', 'out.html' or die "Cannot open 'out.html': $!\n";
33 print $out $html;
34  
35 You can also control the character encoding and entities. For example, if
36 you're sure that the POD is properly encoded (using the C<=encoding> command),
37 you can prevent high-bit characters from being encoded as HTML entities and
38 declare the output character set as UTF-8 before parsing, like so:
39  
40 $psx->html_charset('UTF-8');
41 use warnings;
42 $psx->html_encode_chars(q{&<>'"});
43  
44 =cut
45  
46 package Pod::Simple::XHTML;
47 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 13 our $VERSION = '3.48';
49 13 ▶use Pod::Simple::Methody ();
Subroutine BEGIN: called CC=1 SCAR=0.0
50 13 our @ISA = ('Pod::Simple::Methody');
51  
52 13 our $HAS_HTML_ENTITIES;
53 13 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
54 13 $HAS_HTML_ENTITIES = eval "require HTML::Entities; 1";
55 }
56  
57 13 my %entities = (
58 q{>} => 'gt',
59 q{<} => 'lt',
60 q{'} => '#39',
61 q{"} => 'quot',
62 q{&} => 'amp',
63 );
64  
65 581 ▶sub encode_entities {
Subroutine encode_entities: called CC=4 SCAR=13.9
Pod undocumented
66 581 my $self = shift;
67 581 my $ents = $self->html_encode_chars;
68 581 ▶ return HTML::Entities::encode_entities( $_[0], $ents ) if $HAS_HTML_ENTITIES;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Simple::XHTML::HAS_HTML_ENTITIES 508 73 581
69 73 ▶ if (defined $ents) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ents) { } 1 72 73
70 1 $ents =~ s,(?<!\\)([]/]),\\$1,g;
71 1 $ents =~ s,(?<!\\)\\\z,\\\\,;
72 } else {
73 # the same set of characters as in HTML::Entities
74 72 $ents = '^\n\r\t !\#\$%\(-;=?-~';
75 }
76 73 my $str = $_[0];
77 73 ▶ $str =~ s/([$ents])/'&' . ($entities{$1} || sprintf '#x%X', unpack('U', $1)) . ';'/ge;
Condition66%2/3
$entities{$1} || sprintf('#x%X', unpack('U', $1))
l!l&&r!l&&!r
40200
MC/DC0%0/2
$entities{$1} || sprintf('#x%X', unpack('U', $1))
$entities{$1} sprintf('#x%X', unpack('U', $1))
Truth table66%2/3
A || B
A= $entities{$1}B= sprintf('#x%X', unpack('U', $1))
ABresult
1X1
011
000
78 73 return $str;
79 }
80  
81 13 my %entity_to_char = reverse %entities;
82 13 my ($entity_re) = map qr{$_}, join '|', map quotemeta, sort keys %entity_to_char;
83  
84 5 ▶sub decode_entities {
Subroutine decode_entities: called CC=5 SCAR=28.0
Pod undocumented
85 5 my ($self, $string) = @_;
86 5 ▶ return HTML::Entities::decode_entities( $string ) if $HAS_HTML_ENTITIES;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Simple::XHTML::HAS_HTML_ENTITIES 5 0 5
87  
88 0 $string =~ s{&(?:($entity_re)|#x([0123456789abcdefABCDEF]+)|#([0123456789]+));}{
89 0 ▶ defined $1 ? $entity_to_char{$1}
Branch: 3 branches
BranchTrueFalseTotal
defined $1 ? : 0 0 0
defined $2 ? : 0 0 0
defined $3 ? : 0 0 0
90 : defined $2 ? chr(hex($2))
91 : defined $3 ? chr($3)
92 : die;
93 }ge;
94  
95 0 return $string;
96 }
97  
98 sub HAVE_UTF8_ENCODE ();
99 13 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.6
100 13 ▶ *HAVE_UTF8_ENCODE = defined &utf8::encode ? sub () { 1 } : sub () { 0 };
Subroutine BEGIN: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
defined &utf8::encode ? : 13 0 13
101 }
102 13 my %percent_enc = map +( chr($_) => sprintf('%%%02X', $_) ), 0 .. 255;
103  
104 96 ▶sub encode_url {
Subroutine encode_url: called CC=1 SCAR=0.0
Pod undocumented
105 96 my ($self, $string) = @_;
106  
107 96 utf8::encode($string) if HAVE_UTF8_ENCODE;
108 96 $string =~ s{([^-_.!~*()a-zA-Z0-9])}{$percent_enc{$1}}g;
109  
110 96 return $string;
111 }
112  
113 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114  
115 =head1 METHODS
116  
117 Pod::Simple::XHTML offers a number of methods that modify the format of
118 the HTML output. Call these after creating the parser object, but before
119 the call to C<parse_file>:
120  
121 my $parser = Pod::PseudoPod::HTML->new();
122 $parser->set_optional_param("value");
123 $parser->parse_file($file);
124  
125 =head2 perldoc_url_prefix
126  
127 In turning LE<lt>Foo::BarE<gt> into http://whatever/Foo%3a%3aBar, what
128 to put before the "Foo%3a%3aBar". The default value is
129 "https://metacpan.org/pod/".
130  
131 =head2 perldoc_url_postfix
132  
133 What to put after "Foo%3a%3aBar" in the URL. This option is not set by
134 default.
135  
136 =head2 man_url_prefix
137  
138 In turning C<< LE<lt>crontab(5)E<gt> >> into http://whatever/man/1/crontab.1, what
139 to put before the "1/crontab.1". The default value is
140 "https://man7.org/linux/man-pages/man".
141  
142 =head2 man_url_postfix
143  
144 What to put after "1/crontab.1" in the URL.
145 This option is set to ".html" by default.
146  
147 =head2 title_prefix, title_postfix
148  
149 What to put before and after the title in the head. The values should
150 already be &-escaped.
151  
152 =head2 html_css
153  
154 $parser->html_css('path/to/style.css');
155  
156 The URL or relative path of a CSS file to include. This option is not
157 set by default.
158  
159 =head2 html_javascript
160  
161 The URL or relative path of a JavaScript file to pull in. This option is
162 not set by default.
163  
164 =head2 html_doctype
165  
166 A document type tag for the file. This option is not set by default.
167  
168 =head2 html_charset
169  
170 The character set to declare in the Content-Type meta tag created by default
171 for C<html_header_tags>. Note that this option will be ignored if the value of
172 C<html_header_tags> is changed. Defaults to "ISO-8859-1".
173  
174 =head2 html_header_tags
175  
176 Additional arbitrary HTML tags for the header of the document. The
177 default value is just a content type header tag:
178  
179 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
180  
181 Add additional meta tags here, or blocks of inline CSS or JavaScript
182 (wrapped in the appropriate tags).
183  
184 =head3 html_encode_chars
185  
186 A string containing all characters that should be encoded as HTML entities,
187 specified using the regular expression character class syntax (what you find
188 within brackets in regular expressions). This value will be passed as the
189 second argument to the C<encode_entities> function of L<HTML::Entities>. If
190 L<HTML::Entities> is not installed, then any characters other than C<&<>"'>
191 will be encoded numerically.
192  
193 =head2 html_h_level
194  
195 This is the level of HTML "Hn" element to which a Pod "head1" corresponds. For
196 example, if C<html_h_level> is set to 2, a head1 will produce an H2, a head2
197 will produce an H3, and so on.
198  
199 =head2 default_title
200  
201 Set a default title for the page if no title can be determined from the
202 content. The value of this string should already be &-escaped.
203  
204 =head2 force_title
205  
206 Force a title for the page (don't try to determine it from the content).
207 The value of this string should already be &-escaped.
208  
209 =head2 html_header, html_footer
210  
211 Set the HTML output at the beginning and end of each file. The default
212 header includes a title, a doctype tag (if C<html_doctype> is set), a
213 content tag (customized by C<html_header_tags>), a tag for a CSS file
214 (if C<html_css> is set), and a tag for a Javascript file (if
215 C<html_javascript> is set). The default footer simply closes the C<html>
216 and C<body> tags.
217  
218 The options listed above customize parts of the default header, but
219 setting C<html_header> or C<html_footer> completely overrides the
220 built-in header or footer. These may be useful if you want to use
221 template tags instead of literal HTML headers and footers or are
222 integrating converted POD pages in a larger website.
223  
224 If you want no headers or footers output in the HTML, set these options
225 to the empty string.
226  
227 =head2 index
228  
229 Whether to add a table-of-contents at the top of each page (called an
230 index for the sake of tradition).
231  
232 =head2 anchor_items
233  
234 Whether to anchor every definition C<=item> directive. This needs to be
235 enabled if you want to be able to link to specific C<=item> directives, which
236 are output as C<< <dt> >> elements. Disabled by default.
237  
238 =head2 backlink
239  
240 Whether to turn every =head1 directive into a link pointing to the top
241 of the page (specifically, the opening body tag).
242  
243 =cut
244  
245 13 __PACKAGE__->_accessorize(
246 'perldoc_url_prefix',
247 'perldoc_url_postfix',
248 'man_url_prefix',
249 'man_url_postfix',
250 'title_prefix', 'title_postfix',
251 'html_css',
252 'html_javascript',
253 'html_doctype',
254 'html_charset',
255 'html_encode_chars',
256 'html_h_level',
257 'title', # Used internally for the title extracted from the content
258 'default_title',
259 'force_title',
260 'html_header',
261 'html_footer',
262 'index',
263 'anchor_items',
264 'backlink',
265 'batch_mode', # whether we're in batch mode
266 'batch_mode_current_level',
267 # When in batch mode, how deep the current module is: 1 for "LWP",
268 # 2 for "LWP::Procotol", 3 for "LWP::Protocol::GHTTP", etc
269 );
270  
271 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
272  
273 =head1 SUBCLASSING
274  
275 If the standard options aren't enough, you may want to subclass
276 Pod::Simple::XHMTL. These are the most likely candidates for methods
277 you'll want to override when subclassing.
278  
279 =cut
280  
281 147 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
282 147 my $self = shift;
283 147 my $new = $self->SUPER::new(@_);
284 147 ▶ $new->{'output_fh'} ||= *STDOUT{IO};
Condition50%1/2
$new->{"output_fh"} ||= *STDOUT{"IO"}
l!l
0147
MC/DC0%0/1
$new->{"output_fh"} ||= *STDOUT{"IO"}
$new->{"output_fh"}
Truth table50%1/2
A
A= $new->{"output_fh"}
Aresult
11
00
285 147 $new->perldoc_url_prefix('https://metacpan.org/pod/');
286 147 $new->man_url_prefix('https://man7.org/linux/man-pages/man');
287 147 $new->man_url_postfix('.html');
288 147 $new->html_charset('ISO-8859-1');
289 147 $new->nix_X_codes(1);
290 147 $new->{'scratch'} = '';
291 147 $new->{'to_index'} = [];
292 147 $new->{'output'} = [];
293 147 $new->{'saved'} = [];
294 147 $new->{'ids'} = { '_podtop_' => 1 }; # used in <body>
295 147 $new->{'in_li'} = [];
296  
297 147 $new->{'__region_targets'} = [];
298 147 $new->{'__literal_targets'} = {};
299 147 $new->accept_targets_as_html( 'html', 'HTML' );
300  
301 147 return $new;
302 }
303  
304 20 ▶sub html_header_tags {
Subroutine html_header_tags: called CC=3 SCAR=11.7
Pod documented
305 20 my $self = shift;
306 20 ▶ return $self->{html_header_tags} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 20 20
307 return $self->{html_header_tags}
308 20 ▶ ||= '<meta http-equiv="Content-Type" content="text/html; charset='
Condition50%1/2
$self->{"html_header_tags"} ||= '<meta http-equiv="Content-Type" content="text/html; charset=' . $self->html_charset . '" />'
l!l
020
MC/DC0%0/1
$self->{"html_header_tags"} ||= '<meta http-equiv="Content-Type" content="text/html; charset=' . $self->html_charset . '" />'
$self->{"html_header_tags"}
Truth table50%1/2
A
A= $self->{"html_header_tags"}
Aresult
11
00
309 . $self->html_charset . '" />';
310 }
311  
312 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
313  
314 =head2 handle_text
315  
316 This method handles the body of text within any element: it's the body
317 of a paragraph, or everything between a "=begin" tag and the
318 corresponding "=end" tag, or the text within an L entity, etc. You would
319 want to override this if you are adding a custom element type that does
320 more than just display formatted text. Perhaps adding a way to generate
321 HTML tables from an extended version of POD.
322  
323 So, let's say you want to add a custom element called 'foo'. In your
324 subclass's C<new> method, after calling C<SUPER::new> you'd call:
325  
326 $new->accept_targets_as_text( 'foo' );
327  
328 Then override the C<start_for> method in the subclass to check for when
329 "$flags->{'target'}" is equal to 'foo' and set a flag that marks that
330 you're in a foo block (maybe "$self->{'in_foo'} = 1"). Then override the
331 C<handle_text> method to check for the flag, and pass $text to your
332 custom subroutine to construct the HTML output for 'foo' elements,
333 something like:
334  
335 sub handle_text {
336 my ($self, $text) = @_;
337 if ($self->{'in_foo'}) {
338 $self->{'scratch'} .= build_foo_html($text);
339 return;
340 }
341 $self->SUPER::handle_text($text);
342 }
343  
344 =head2 handle_code
345  
346 This method handles the body of text that is marked up to be code.
347 You might for instance override this to plug in a syntax highlighter.
348 The base implementation just escapes the text.
349  
350 The callback methods C<start_code> and C<end_code> emits the C<code> tags
351 before and after C<handle_code> is invoked, so you might want to override these
352 together with C<handle_code> if this wrapping isn't suitable.
353  
354 Note that the code might be broken into multiple segments if there are
355 nested formatting codes inside a C<< CE<lt>...> >> sequence. In between the
356 calls to C<handle_code> other markup tags might have been emitted in that
357 case. The same is true for verbatim sections if the C<codes_in_verbatim>
358 option is turned on.
359  
360 =head2 accept_targets_as_html
361  
362 This method behaves like C<accept_targets_as_text>, but also marks the region
363 as one whose content should be emitted literally, without HTML entity escaping
364 or wrapping in a C<div> element.
365  
366 =cut
367  
368 333 ▶sub __in_literal_xhtml_region {
Subroutine __in_literal_xhtml_region: called CC=2 SCAR=6.9
369 333 ▶ return unless @{ $_[0]{__region_targets} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_[0]{"__region_targets"};} 303 30 333
370 30 my $target = $_[0]{__region_targets}[-1];
371 30 return $_[0]{__literal_targets}{ $target };
372 }
373  
374 147 ▶sub accept_targets_as_html {
Subroutine accept_targets_as_html: called CC=2 SCAR=6.9
Pod documented
375 147 my ($self, @targets) = @_;
376 147 $self->accept_targets(@targets);
377 147 $self->{__literal_targets}{$_} = 1 for @targets;
378 }
379  
380 312 ▶sub handle_text {
Subroutine handle_text: called CC=11 SCAR=24.0
Pod documented
381 # escape special characters in HTML (<, >, &, etc)
382 312 my $text = $_[1];
383 312 my $html;
384 312 ▶ if ($_[0]->__in_literal_xhtml_region) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->__in_literal_xhtml_region) { } 5 307 312
385 5 $html = $text;
386 5 $text =~ s{<[^>]+?>}{}g;
387 5 $text = $_[0]->decode_entities($text);
388 }
389 else {
390 307 $html = $_[0]->encode_entities($text);
391 }
392  
393 312 ▶ if ($_[0]{'in_code'} && @{$_[0]{'in_code'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{'in_code'} and @{$_[0]{'in_code'};}) { } 43 269 312
Condition100%3/3
$_[0]{"in_code"} and @{$_[0]{"in_code"};}
!ll&&!rl&&r
2571243
MC/DC100%2/2
$_[0]{"in_code"} and @{$_[0]{"in_code"};}
$_[0]{"in_code"} @{$_[0]{"in_code"};}
Truth table100%3/3
A and B
A= $_[0]{"in_code"}B= @{$_[0]{"in_code"};}
ABresult
0X0
100
111
394 # Intentionally use the raw text in $_[1], even if we're not in a
395 # literal xhtml region, since handle_code calls encode_entities.
396 43 $_[0]->handle_code( $_[1], $_[0]{'in_code'}[-1] );
397 } else {
398 269 ▶ if ($_[0]->{in_for}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{'in_for'}) { } 9 260 269
399 9 ▶ my $newlines = $_[0]->__in_literal_xhtml_region ? "\n\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->__in_literal_xhtml_region ? : 5 4 9
400 9 ▶ if ($_[0]->{started_for}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{'started_for'}) { } 6 3 9
401 6 ▶ if ($html =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html =~ /\S/) 6 0 6
402 6 delete $_[0]->{started_for};
403 6 $_[0]{'scratch'} .= $html . $newlines;
404 }
405 # Otherwise, append nothing until we have something to append.
406 } else {
407 # The parser sometimes preserves newlines and sometimes doesn't!
408 3 $html =~ s/\n\z//;
409 3 $_[0]{'scratch'} .= $html . $newlines;
410 }
411 } else {
412 # Just plain text.
413 260 $_[0]{'scratch'} .= $html;
414 }
415 }
416  
417 312 ▶ $_[0]{hhtml} .= $html if $_[0]{'in_head'};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"in_head"} 106 206 312
418 312 ▶ $_[0]{htext} .= $text if $_[0]{'in_head'};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"in_head"} 106 206 312
419 312 ▶ $_[0]{itext} .= $text if $_[0]{'in_item_text'};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"in_item_text"} 33 279 312
420 }
421  
422 32 ▶sub start_code {
Subroutine start_code: called CC=1 SCAR=0.0
Pod undocumented
423 32 $_[0]{'scratch'} .= '<code>';
424 }
425  
426 32 ▶sub end_code {
Subroutine end_code: called CC=1 SCAR=0.0
Pod undocumented
427 32 $_[0]{'scratch'} .= '</code>';
428 }
429  
430 43 ▶sub handle_code {
Subroutine handle_code: called CC=1 SCAR=0.0
Pod documented
431 43 $_[0]{'scratch'} .= $_[0]->encode_entities( $_[1] );
432 }
433  
434 93 ▶sub start_Para {
Subroutine start_Para: called CC=1 SCAR=0.0
Pod undocumented
435 93 $_[0]{'scratch'} .= '<p>';
436 }
437  
438 26 ▶sub start_Verbatim {
Subroutine start_Verbatim: called CC=1 SCAR=0.0
Pod undocumented
439 26 $_[0]{'scratch'} = '<pre>';
440 26 push(@{$_[0]{'in_code'}}, 'Verbatim');
441 26 $_[0]->start_code($_[0]{'in_code'}[-1]);
442 }
443  
444 66 ▶sub start_head1 { $_[0]{'in_head'} = 1; $_[0]{htext} = $_[0]{hhtml} = ''; }
Subroutine start_head1: called CC=1 SCAR=0.0
Pod undocumented
445 15 ▶sub start_head2 { $_[0]{'in_head'} = 2; $_[0]{htext} = $_[0]{hhtml} = ''; }
Subroutine start_head2: called CC=1 SCAR=0.0
Pod undocumented
446 8 ▶sub start_head3 { $_[0]{'in_head'} = 3; $_[0]{htext} = $_[0]{hhtml} = ''; }
Subroutine start_head3: called CC=1 SCAR=0.0
Pod undocumented
447 9 ▶sub start_head4 { $_[0]{'in_head'} = 4; $_[0]{htext} = $_[0]{hhtml} = ''; }
Subroutine start_head4: called CC=1 SCAR=0.0
Pod undocumented
448 2 ▶sub start_head5 { $_[0]{'in_head'} = 5; $_[0]{htext} = $_[0]{hhtml} = ''; }
Subroutine start_head5: called CC=1 SCAR=0.0
Pod undocumented
449 2 ▶sub start_head6 { $_[0]{'in_head'} = 6; $_[0]{htext} = $_[0]{hhtml} = ''; }
Subroutine start_head6: called CC=1 SCAR=0.0
Pod undocumented
450  
451 8 ▶sub start_item_number {
Subroutine start_item_number: called CC=3 SCAR=11.0
Pod undocumented
452 8 ▶ $_[0]{'scratch'} = "</li>\n" if ($_[0]{'in_li'}->[-1] && pop @{$_[0]{'in_li'}});
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"in_li"}[-1] and pop @{$_[0]{"in_li"};} 3 5 8
Condition66%2/3
$_[0]{"in_li"}[-1] and pop @{$_[0]{"in_li"};}
!ll&&!rl&&r
503
MC/DC50%1/2
$_[0]{"in_li"}[-1] and pop @{$_[0]{"in_li"};}
$_[0]{"in_li"}[-1] pop @{$_[0]{"in_li"};}
Truth table66%2/3
A and B
A= $_[0]{"in_li"}[-1]B= pop @{$_[0]{"in_li"};}
ABresult
0X0
100
111
453 8 $_[0]{'scratch'} .= '<li><p>';
454 8 push @{$_[0]{'in_li'}}, 1;
455 }
456  
457 12 ▶sub start_item_bullet {
Subroutine start_item_bullet: called CC=3 SCAR=11.0
Pod undocumented
458 12 ▶ $_[0]{'scratch'} = "</li>\n" if ($_[0]{'in_li'}->[-1] && pop @{$_[0]{'in_li'}});
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"in_li"}[-1] and pop @{$_[0]{"in_li"};} 5 7 12
Condition66%2/3
$_[0]{"in_li"}[-1] and pop @{$_[0]{"in_li"};}
!ll&&!rl&&r
705
MC/DC50%1/2
$_[0]{"in_li"}[-1] and pop @{$_[0]{"in_li"};}
$_[0]{"in_li"}[-1] pop @{$_[0]{"in_li"};}
Truth table66%2/3
A and B
A= $_[0]{"in_li"}[-1]B= pop @{$_[0]{"in_li"};}
ABresult
0X0
100
111
459 12 $_[0]{'scratch'} .= '<li><p>';
460 12 push @{$_[0]{'in_li'}}, 1;
461 }
462  
463 20 ▶sub start_item_text {
Subroutine start_item_text: called CC=1 SCAR=0.0
Pod undocumented
464 20 $_[0]{'in_item_text'} = 1; $_[0]{itext} = '';
465 # see end_item_text
466 }
467  
468 7 ▶sub start_over_bullet { $_[0]{'scratch'} = '<ul>'; push @{$_[0]{'in_li'}}, 0; $_[0]->emit }
Subroutine start_over_bullet: called CC=1 SCAR=0.0
Pod undocumented
469 1 ▶sub start_over_block { $_[0]{'scratch'} = '<blockquote>'; $_[0]->emit }
Subroutine start_over_block: called CC=1 SCAR=0.0
Pod undocumented
470 5 ▶sub start_over_number { $_[0]{'scratch'} = '<ol>'; push @{$_[0]{'in_li'}}, 0; $_[0]->emit }
Subroutine start_over_number: called CC=1 SCAR=0.0
Pod undocumented
471 14 ▶sub start_over_text {
Subroutine start_over_text: called CC=2 SCAR=6.9
Pod undocumented
472 14 $_[0]{'scratch'} = '<dl>';
473 14 $_[0]{'dl_level'}++;
474 14 ▶ $_[0]{'in_dd'} ||= [];
Condition100%2/2
$_[0]{"in_dd"} ||= []
l!l
212
MC/DC100%1/1
$_[0]{"in_dd"} ||= []
$_[0]{"in_dd"}
Truth table100%2/2
A
A= $_[0]{"in_dd"}
Aresult
11
00
475 14 $_[0]->emit
476 }
477  
478 1 ▶sub end_over_block { $_[0]{'scratch'} .= '</blockquote>'; $_[0]->emit }
Subroutine end_over_block: called CC=1 SCAR=0.0
Pod undocumented
479  
480 5 ▶sub end_over_number {
Subroutine end_over_number: called CC=2 SCAR=7.0
Pod undocumented
481 5 ▶ $_[0]{'scratch'} = "</li>\n" if ( pop @{$_[0]{'in_li'}} );
Branch: 1 branch
BranchTrueFalseTotal
if pop @{$_[0]{"in_li"};} 5 0 5
482 5 $_[0]{'scratch'} .= '</ol>';
483 5 pop @{$_[0]{'in_li'}};
484 5 $_[0]->emit;
485 }
486  
487 7 ▶sub end_over_bullet {
Subroutine end_over_bullet: called CC=2 SCAR=7.0
Pod undocumented
488 7 ▶ $_[0]{'scratch'} = "</li>\n" if ( pop @{$_[0]{'in_li'}} );
Branch: 1 branch
BranchTrueFalseTotal
if pop @{$_[0]{"in_li"};} 7 0 7
489 7 $_[0]{'scratch'} .= '</ul>';
490 7 pop @{$_[0]{'in_li'}};
491 7 $_[0]->emit;
492 }
493  
494 14 ▶sub end_over_text {
Subroutine end_over_text: called CC=2 SCAR=7.0
Pod undocumented
495 14 ▶ if ($_[0]{'in_dd'}[ $_[0]{'dl_level'} ]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"in_dd"}[$_[0]{"dl_level"}]) 14 0 14
496 14 $_[0]{'scratch'} = "</dd>\n";
497 14 $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 0;
498 }
499 14 $_[0]{'scratch'} .= '</dl>';
500 14 $_[0]{'dl_level'}--;
501 14 $_[0]->emit;
502 }
503  
504 # . . . . . Now the actual formatters:
505  
506 93 ▶sub end_Para { $_[0]{'scratch'} .= '</p>'; $_[0]->emit }
Subroutine end_Para: called CC=1 SCAR=0.0
Pod undocumented
507 26 ▶sub end_Verbatim {
Subroutine end_Verbatim: called CC=1 SCAR=0.0
Pod undocumented
508 26 $_[0]->end_code(pop(@{$_[0]->{'in_code'}}));
509 26 $_[0]{'scratch'} .= '</pre>';
510 26 $_[0]->emit;
511 }
512  
513 102 ▶sub _end_head {
Subroutine _end_head: called CC=4 SCAR=13.9
514 102 my $h = delete $_[0]{in_head};
515  
516 102 my $add = $_[0]->html_h_level;
517 102 ▶ $add = 1 unless defined $add;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $add 99 3 102
518 102 $h += $add - 1;
519  
520 102 my $id = $_[0]->idify(delete $_[0]{htext});
521 102 my $text = $_[0]{scratch};
522 102 my $head = qq{<h$h id="} . $_[0]->encode_entities($id) . qq{">$text</h$h>};
523 102 ▶ $_[0]{'scratch'} = $_[0]->backlink && ($h - $add == 0)
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->backlink && $h - $add == 0 ? : 7 95 102
Condition100%3/3
$_[0]->backlink and $h - $add == 0
!ll&&!rl&&r
9417
MC/DC100%2/2
$_[0]->backlink and $h - $add == 0
$_[0]->backlink $h - $add == 0
Truth table100%3/3
A and B
A= $_[0]->backlinkB= $h - $add == 0
ABresult
0X0
100
111
524 # backlinks enabled && =head1
525 ? qq{<a href="#_podtop_">$head</a>}
526 : $head;
527 102 $_[0]->emit;
528 102 push @{ $_[0]{'to_index'} }, [$h, $id, delete $_[0]{'hhtml'}];
529 }
530  
531 66 ▶sub end_head1 { shift->_end_head(@_); }
Subroutine end_head1: called CC=1 SCAR=0.0
Pod undocumented
532 15 ▶sub end_head2 { shift->_end_head(@_); }
Subroutine end_head2: called CC=1 SCAR=0.0
Pod undocumented
533 8 ▶sub end_head3 { shift->_end_head(@_); }
Subroutine end_head3: called CC=1 SCAR=0.0
Pod undocumented
534 9 ▶sub end_head4 { shift->_end_head(@_); }
Subroutine end_head4: called CC=1 SCAR=0.0
Pod undocumented
535 2 ▶sub end_head5 { shift->_end_head(@_); }
Subroutine end_head5: called CC=1 SCAR=0.0
Pod undocumented
536 2 ▶sub end_head6 { shift->_end_head(@_); }
Subroutine end_head6: called CC=1 SCAR=0.0
Pod undocumented
537  
538 12 ▶sub end_item_bullet { $_[0]{'scratch'} .= '</p>'; $_[0]->emit }
Subroutine end_item_bullet: called CC=1 SCAR=0.0
Pod undocumented
539 8 ▶sub end_item_number { $_[0]{'scratch'} .= '</p>'; $_[0]->emit }
Subroutine end_item_number: called CC=1 SCAR=0.0
Pod undocumented
540  
541 20 ▶sub end_item_text {
Subroutine end_item_text: called CC=3 SCAR=11.0
Pod undocumented
542 # idify and anchor =item content if wanted
543 my $dt_id = $_[0]{'anchor_items'}
544 20 ▶ ? ' id="'. $_[0]->encode_entities($_[0]->idify($_[0]{'itext'})) .'"'
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'anchor_items'} ? : 9 11 20
545 : '';
546  
547 # reset scratch
548 20 my $text = $_[0]{scratch};
549 20 $_[0]{'scratch'} = '';
550  
551 20 ▶ if ($_[0]{'in_dd'}[ $_[0]{'dl_level'} ]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"in_dd"}[$_[0]{"dl_level"}]) 6 14 20
552 6 $_[0]{'scratch'} = "</dd>\n";
553 6 $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 0;
554 }
555  
556 20 $_[0]{'scratch'} .= qq{<dt$dt_id>$text</dt>\n<dd>};
557 20 $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 1;
558 20 $_[0]->emit;
559 }
560  
561 # This handles =begin and =for blocks of all kinds.
562 6 ▶sub start_for {
Subroutine start_for: called CC=3 SCAR=11.0
Pod undocumented
563 6 my ($self, $flags) = @_;
564  
565 6 push @{ $self->{__region_targets} }, $flags->{target_matching};
566 6 $self->{started_for} = 1;
567 6 $self->{in_for} = 1;
568  
569 6 ▶ unless ($self->__in_literal_xhtml_region) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->__in_literal_xhtml_region) 4 2 6
570 4 $self->{scratch} .= '<div';
571 4 ▶ $self->{scratch} .= qq( class="$flags->{target}") if $flags->{target};
Branch: 1 branch
BranchTrueFalseTotal
if $flags->{"target"} 4 0 4
572 4 $self->{scratch} .= ">\n\n";
573 }
574 }
575  
576 6 ▶sub end_for {
Subroutine end_for: called CC=2 SCAR=6.9
Pod undocumented
577 6 my ($self) = @_;
578 6 delete $self->{started_for};
579 6 delete $self->{in_for};
580  
581 6 ▶ if ($self->__in_literal_xhtml_region) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__in_literal_xhtml_region) { } 2 4 6
582 # Remove trailine newlines.
583 2 $self->{'scratch'} =~ s/\s+\z//s;
584 } else {
585 4 $self->{'scratch'} .= '</div>';
586 }
587  
588 6 pop @{ $self->{__region_targets} };
589 6 $self->emit;
590 }
591  
592 142 ▶sub start_Document {
Subroutine start_Document: called CC=12 SCAR=26.0
Pod undocumented
593 142 my ($self) = @_;
594 142 ▶ if (defined $self->html_header) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->html_header) { } 122 20 142
595 122 $self->{'scratch'} .= $self->html_header;
596 122 ▶ $self->emit unless $self->html_header eq "";
Branch: 1 branch
BranchTrueFalseTotal
unless $self->html_header eq "" 1 121 122
597 } else {
598 20 my ($doctype, $title, $metatags, $bodyid);
599 20 ▶ $doctype = $self->html_doctype || '';
Condition50%1/2
$self->html_doctype || ''
l!l
020
MC/DC0%0/1
$self->html_doctype || ''
$self->html_doctype
Truth table50%1/2
A
A= $self->html_doctype
Aresult
11
00
600 20 ▶ $title = $self->force_title || $self->title || $self->default_title || '';
Condition37%3/8
$self->force_title || $self->title || $self->default_title || ''
l!l
020
$self->force_title or $self->title or $self->default_title
l!l&&r!l&&!r
0020
$self->force_title or $self->title
l!l&&r!l&&!r
0020
MC/DC0%0/3
$self->force_title || $self->title || $self->default_title || ''
$self->force_title $self->title $self->default_title
Truth table25%1/4
A or B or C
A= $self->force_titleB= $self->titleC= $self->default_title
ABCresult
1XX1
01X1
0011
0000
601 20 ▶ $metatags = $self->html_header_tags || '';
Condition50%1/2
$self->html_header_tags || ''
l!l
200
MC/DC0%0/1
$self->html_header_tags || ''
$self->html_header_tags
Truth table50%1/2
A
A= $self->html_header_tags
Aresult
11
00
602 20 ▶ if (my $css = $self->html_css) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $css = $self->html_css) 3 17 20
603 3 ▶ if ($css !~ /<link/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $css =~ /<link/) { } 2 1 3
604 # this is required to be compatible with Pod::Simple::BatchHTML
605 2 $metatags .= '<link rel="stylesheet" href="'
606 . $self->encode_entities($css) . '" type="text/css" />';
607 } else {
608 1 $metatags .= $css;
609 }
610 }
611 20 ▶ if ($self->html_javascript) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->html_javascript) 0 20 20
612 0 $metatags .= qq{\n<script type="text/javascript" src="} .
613 $self->html_javascript . '"></script>';
614 }
615 20 ▶ $bodyid = $self->backlink ? ' id="_podtop_"' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->backlink ? : 4 16 20
616 20 $self->{'scratch'} .= <<"HTML";
617 $doctype
618 <html>
619 <head>
620 <title>$title</title>
621 $metatags
622 </head>
623 <body$bodyid>
624 HTML
625 20 $self->emit;
626 }
627 }
628  
629 33 ▶sub build_index {
Subroutine build_index: called CC=13 SCAR=25.7
Pod undocumented
630 33 my ($self, $to_index) = @_;
631  
632 33 my @out;
633 33 my $level = 0;
634 33 my $indent = -1;
635 33 my $space = '';
636 33 my $id = ' id="index"';
637  
638 33 for my $h (@{ $to_index }, [0]) {
639 102 my $target_level = $h->[0];
640 # Get to target_level by opening or closing ULs
641 102 ▶ if ($level == $target_level) {
Branch: 2 branches
BranchTrueFalseTotal
if ($level == $target_level) { } 9 93 102
elsif ($level > $target_level) { } 39 54 93
642 9 $out[-1] .= '</li>';
643 } elsif ($level > $target_level) {
644 39 ▶ $out[-1] .= '</li>' if $out[-1] =~ /^\s+<li>/;
Branch: 1 branch
BranchTrueFalseTotal
if $out[-1] =~ /^\s+<li>/ 39 0 39
645 39 ▶ while ($level > $target_level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level > $target_level) 68 39 107
646 68 --$level;
647 68 ▶ push @out, (' ' x --$indent) . '</li>' if @out && $out[-1] =~ m{^\s+<\/ul};
Branch: 1 branch
BranchTrueFalseTotal
if @out and $out[-1] =~ m[^\s+<\/ul] 29 39 68
Condition66%2/3
@out and $out[-1] =~ m[^\s+<\/ul]
!ll&&!rl&&r
03929
MC/DC50%1/2
@out and $out[-1] =~ m[^\s+<\/ul]
@out $out[-1] =~ m[^\s+<\/ul]
Truth table66%2/3
A and B
A= @outB= $out[-1] =~ m[^\s+<\/ul]
ABresult
0X0
100
111
648 68 push @out, (' ' x --$indent) . '</ul>';
649 }
650 39 ▶ push @out, (' ' x --$indent) . '</li>' if $level;
Branch: 1 branch
BranchTrueFalseTotal
if $level 6 33 39
651 } else {
652 54 ▶ while ($level < $target_level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level < $target_level) 68 54 122
653 68 ++$level;
654 68 ▶ push @out, (' ' x ++$indent) . '<li>' if @out && $out[-1]=~ /^\s*<ul/;
Branch: 1 branch
BranchTrueFalseTotal
if @out and $out[-1] =~ /^\s*<ul/ 14 54 68
Condition100%3/3
@out and $out[-1] =~ /^\s*<ul/
!ll&&!rl&&r
332114
MC/DC100%2/2
@out and $out[-1] =~ /^\s*<ul/
@out $out[-1] =~ /^\s*<ul/
Truth table100%3/3
A and B
A= @outB= $out[-1] =~ /^\s*<ul/
ABresult
0X0
100
111
655 68 push @out, (' ' x ++$indent) . "<ul$id>";
656 68 $id = '';
657 }
658 54 ++$indent;
659 }
660  
661 102 ▶ next unless $level;
Branch: 1 branch
BranchTrueFalseTotal
unless $level 33 69 102
662 69 $space = ' ' x $indent;
663 69 my $fragment = $self->encode_entities($self->encode_url($h->[1]));
664 69 push @out, sprintf '%s<li><a href="#%s">%s</a>',
665 $space, $fragment, $h->[2];
666 }
667  
668 33 return join "\n", @out;
669 }
670  
671 142 ▶sub end_Document {
Subroutine end_Document: called CC=8 SCAR=20.8
Pod undocumented
672 142 my ($self) = @_;
673 142 my $to_index = $self->{'to_index'};
674 142 ▶ if ($self->index && @{ $to_index } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->index and @{$to_index;}) 33 109 142
Condition100%3/3
$self->index and @{$to_index;}
!ll&&!rl&&r
102733
MC/DC100%2/2
$self->index and @{$to_index;}
$self->index @{$to_index;}
Truth table100%3/3
A and B
A= $self->indexB= @{$to_index;}
ABresult
0X0
100
111
675 33 my $index = $self->build_index($to_index);
676  
677 # Splice the index in between the HTML headers and the first element.
678 33 ▶ my $offset = defined $self->html_header ? $self->html_header eq '' ? 0 : 1 : 1;
Branch: 2 branches
BranchTrueFalseTotal
defined $self->html_header ? : 26 7 33
$self->html_header eq '' ? : 26 0 26
679 33 splice @{ $self->{'output'} }, $offset, 0, $index;
680 }
681  
682 142 ▶ if (defined $self->html_footer) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->html_footer) { } 122 20 142
683 122 $self->{'scratch'} .= $self->html_footer;
684 122 ▶ $self->emit unless $self->html_footer eq "";
Branch: 1 branch
BranchTrueFalseTotal
unless $self->html_footer eq "" 1 121 122
685 } else {
686 20 $self->{'scratch'} .= "</body>\n</html>";
687 20 $self->emit;
688 }
689  
690 142 ▶ if ($self->index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->index) 40 102 142
691 40 print {$self->{'output_fh'}} join ("\n\n", @{ $self->{'output'} }), "\n\n";
692 40 @{$self->{'output'}} = ();
693 }
694  
695 }
696  
697 # Handling code tags
698 7 ▶sub start_B { $_[0]{'scratch'} .= '<b>' }
Subroutine start_B: called CC=1 SCAR=0.0
Pod undocumented
699 7 ▶sub end_B { $_[0]{'scratch'} .= '</b>' }
Subroutine end_B: called CC=1 SCAR=0.0
Pod undocumented
700  
701 10 ▶sub start_C { push(@{$_[0]{'in_code'}}, 'C'); $_[0]->start_code($_[0]{'in_code'}[-1]); }
Subroutine start_C: called CC=1 SCAR=0.0
Pod undocumented
702 10 ▶sub end_C { $_[0]->end_code(pop(@{$_[0]{'in_code'}})); }
Subroutine end_C: called CC=1 SCAR=0.0
Pod undocumented
703  
704 1 ▶sub start_F { $_[0]{'scratch'} .= '<i>' }
Subroutine start_F: called CC=1 SCAR=0.0
Pod undocumented
705 1 ▶sub end_F { $_[0]{'scratch'} .= '</i>' }
Subroutine end_F: called CC=1 SCAR=0.0
Pod undocumented
706  
707 1 ▶sub start_I { $_[0]{'scratch'} .= '<i>' }
Subroutine start_I: called CC=1 SCAR=0.0
Pod undocumented
708 1 ▶sub end_I { $_[0]{'scratch'} .= '</i>' }
Subroutine end_I: called CC=1 SCAR=0.0
Pod undocumented
709  
710 1 ▶sub start_U { $_[0]{'scratch'} .= '<u>' }
Subroutine start_U: called CC=1 SCAR=0.0
Pod undocumented
711 1 ▶sub end_U { $_[0]{'scratch'} .= '</u>' }
Subroutine end_U: called CC=1 SCAR=0.0
Pod undocumented
712  
713 36 ▶sub start_L {
Subroutine start_L: called CC=5 SCAR=16.3
Pod undocumented
714 36 my ($self, $flags) = @_;
715 36 my ($type, $to, $section) = @{$flags}{'type', 'to', 'section'};
716 36 ▶ my $url = $self->encode_entities(
Branch: 3 branches
BranchTrueFalseTotal
$type eq 'url' ? : 12 24 36
$type eq 'pod' ? : 21 3 24
$type eq 'man' ? : 3 0 3
717 $type eq 'url' ? $to
718 : $type eq 'pod' ? $self->resolve_pod_page_link($to, $section)
719 : $type eq 'man' ? $self->resolve_man_page_link($to, $section)
720 : undef
721 );
722  
723 # If it's an unknown type, use an attribute-less <a> like HTML.pm.
724 36 ▶ $self->{'scratch'} .= '<a' . ($url ? ' href="'. $url . '">' : '>');
Branch: 1 branch
BranchTrueFalseTotal
$url ? : 36 0 36
725 }
726  
727 36 ▶sub end_L { $_[0]{'scratch'} .= '</a>' }
Subroutine end_L: called CC=1 SCAR=0.0
Pod undocumented
728  
729 1 ▶sub start_S { $_[0]{'scratch'} .= '<span style="white-space: nowrap;">' }
Subroutine start_S: called CC=1 SCAR=0.0
Pod undocumented
730 1 ▶sub end_S { $_[0]{'scratch'} .= '</span>' }
Subroutine end_S: called CC=1 SCAR=0.0
Pod undocumented
731  
732 363 ▶sub emit {
Subroutine emit: called CC=2 SCAR=6.9
Pod undocumented
733 363 my($self) = @_;
734 363 ▶ if ($self->index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->index) { } 135 228 363
735 135 push @{ $self->{'output'} }, $self->{'scratch'};
736 } else {
737 228 print {$self->{'output_fh'}} $self->{'scratch'}, "\n\n";
738 }
739 363 $self->{'scratch'} = '';
740 363 return;
741 }
742  
743 =head2 resolve_pod_page_link
744  
745 my $url = $pod->resolve_pod_page_link('Net::Ping', 'INSTALL');
746 my $url = $pod->resolve_pod_page_link('perlpodspec');
747 my $url = $pod->resolve_pod_page_link(undef, 'SYNOPSIS');
748  
749 Resolves a POD link target (typically a module or POD file name) and section
750 name to a URL. The resulting link will be returned for the above examples as:
751  
752 https://metacpan.org/pod/Net::Ping#INSTALL
753 https://metacpan.org/pod/perlpodspec
754 #SYNOPSIS
755  
756 Note that when there is only a section argument the URL will simply be a link
757 to a section in the current document.
758  
759 =cut
760  
761 26 ▶sub resolve_pod_page_link {
Subroutine resolve_pod_page_link: called CC=7 SCAR=19.9
Pod documented
762 26 my ($self, $to, $section) = @_;
763 26 ▶ return undef unless defined $to || defined $section;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to or defined $section 0 26 26
Condition66%2/3
defined $to or defined $section
l!l&&r!l&&!r
13130
MC/DC0%0/2
defined $to or defined $section
defined $to defined $section
Truth table66%2/3
A or B
A= defined $toB= defined $section
ABresult
1X1
011
000
764 26 ▶ if (defined $section) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $section) { } 18 8 26
765 18 my $id = $self->idify($section, 1);
766 18 $section = '#' . $self->encode_url($id);
767 18 ▶ return $section unless defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to 13 5 18
768 } else {
769 8 $section = ''
770 }
771  
772 13 ▶ return ($self->perldoc_url_prefix || '')
Condition50%2/4
$self->perldoc_url_prefix || ''
l!l
130
$self->perldoc_url_postfix || ''
l!l
013
MC/DC0%0/1
$self->perldoc_url_prefix || ''
$self->perldoc_url_prefix
MC/DC0%0/1
$self->perldoc_url_postfix || ''
$self->perldoc_url_postfix
Truth table50%1/2
A
A= $self->perldoc_url_prefix
Aresult
11
00
Truth table50%1/2
A
A= $self->perldoc_url_postfix
Aresult
11
00
773 . $to . $section
774 . ($self->perldoc_url_postfix || '');
775 }
776  
777 =head2 resolve_man_page_link
778  
779 my $url = $pod->resolve_man_page_link('crontab(5)', 'EXAMPLE CRON FILE');
780 my $url = $pod->resolve_man_page_link('crontab');
781  
782 Resolves a man page link target and numeric section to a URL. The resulting
783 link will be returned for the above examples as:
784  
785 https://man7.org/linux/man-pages/man5/crontab.5.html
786 https://man7.org/linux/man-pages/man1/crontab.1.html
787  
788 Note that the first argument is required. The section number will be parsed
789 from it, and if it's missing will default to 1. The second argument is
790 currently ignored. Subclass to link to a different man page HTTP server.
791  
792 =cut
793  
794 6 ▶sub resolve_man_page_link {
Subroutine resolve_man_page_link: called CC=8 SCAR=21.2
Pod documented
795 6 my ($self, $to, $section) = @_;
796 6 ▶ return undef unless defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to 0 6 6
797  
798 6 my ($page, $part) = $to =~ /^([^(]+)(?:[(](\d+)[)])?$/;
799 6 ▶ return undef unless $page;
Branch: 1 branch
BranchTrueFalseTotal
unless $page 0 6 6
800  
801 6 ▶ if (defined $section) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $section) { } 2 4 6
802 2 $section =~ s/\s+/_/g;
803 2 my $id = $self->idify($section, 1);
804 2 $section = '#' . $self->encode_url($id);
805 } else {
806 4 $section = ''
807 }
808  
809 6 ▶ return ($self->man_url_prefix || '')
Condition75%6/8
$self->man_url_prefix || ''
l!l
60
$part || 1
l!l
51
$part || 1
l!l
51
$self->man_url_postfix || ''
l!l
60
MC/DC0%0/1
$self->man_url_prefix || ''
$self->man_url_prefix
MC/DC100%1/1
$part || 1
$part
MC/DC100%1/1
$part || 1
$part
MC/DC0%0/1
$self->man_url_postfix || ''
$self->man_url_postfix
Truth table50%1/2
A
A= $self->man_url_prefix
Aresult
11
00
Truth table100%2/2
A
A= $part
Aresult
11
00
Truth table100%2/2
A
A= $part
Aresult
11
00
Truth table50%1/2
A
A= $self->man_url_postfix
Aresult
11
00
810 . ($part || 1) . "/" . $self->encode_entities($page)
811 . "." . ($part || 1) . ($self->man_url_postfix || '')
812 . $section;
813 }
814  
815 =head2 idify
816  
817 my $id = $pod->idify($text);
818 my $hash = $pod->idify($text, 1);
819  
820 This method turns an arbitrary string into a valid XHTML ID attribute value.
821 The rules enforced, following
822 L<http://webdesign.about.com/od/htmltags/a/aa031707.htm>, are:
823  
824 =over
825  
826 =item *
827  
828 The id must start with a letter (a-z or A-Z)
829  
830 =item *
831  
832 All subsequent characters can be letters, numbers (0-9), hyphens (-),
833 underscores (_), colons (:), and periods (.).
834  
835 =item *
836  
837 The final character can't be a hyphen, colon, or period. URLs ending with these
838 characters, while allowed by XHTML, can be awkward to extract from plain text.
839  
840 =item *
841  
842 Each id must be unique within the document.
843  
844 =back
845  
846 In addition, the returned value will be unique within the context of the
847 Pod::Simple::XHTML object unless a second argument is passed a true value. ID
848 attributes should always be unique within a single XHTML document, but pass
849 the true value if you are creating not an ID but a URL hash to point to
850 an ID (i.e., if you need to put the "#foo" in C<< <a href="#foo">foo</a> >>.
851  
852 =cut
853  
854 122 ▶sub idify {
Subroutine idify: called CC=4 SCAR=13.9
Pod documented
855 122 my ($self, $t, $not_unique) = @_;
856 122 for ($t) {
857 122 s/[<>&'"]//g; # Strip HTML special characters
858 122 s/^\s+//; s/\s+$//; # Strip white space.
859 122 s/^([^a-zA-Z]+)$/pod$1/; # Prepend "pod" if no valid chars.
860 122 s/^[^a-zA-Z]+//; # First char must be a letter.
861 122 s/[^-a-zA-Z0-9_:.]+/-/g; # All other chars must be valid.
862 122 s/[-:.]+$//; # Strip trailing punctuation.
863 }
864 122 ▶ return $t if $not_unique;
Branch: 1 branch
BranchTrueFalseTotal
if $not_unique 19 103 122
865 103 my $i = '';
866 103 ▶ $i++ while $self->{ids}{"$t$i"}++;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"ids"}{"$t$i"}++ and do { ++$i } 1 103 104
867 103 return "$t$i";
868 }
869  
870 =head2 batch_mode_page_object_init
871  
872 $pod->batch_mode_page_object_init($batchconvobj, $module, $infile, $outfile, $depth);
873  
874 Called by L<Pod::Simple::HTMLBatch> so that the class has a chance to
875 initialize the converter. Internally it sets the C<batch_mode> property to
876 true and sets C<batch_mode_current_level()>, but Pod::Simple::XHTML does not
877 currently use those features. Subclasses might, though.
878  
879 =cut
880  
881 1 ▶sub batch_mode_page_object_init {
Subroutine batch_mode_page_object_init: called CC=1 SCAR=0.0
Pod documented
882 1 my ($self, $batchconvobj, $module, $infile, $outfile, $depth) = @_;
883 1 $self->batch_mode(1);
884 1 $self->batch_mode_current_level($depth);
885 1 return $self;
886 }
887  
888 0 ▶sub html_header_after_title {
Subroutine html_header_after_title: not called CC=1 SCAR=0.0
Pod undocumented
889 }
890  
891  
892 13 1;
893  
894 __END__
« Simple/LinkSection.pm ↑ Summary Simple/Checker.pm »