Simple/HTML.pm

filter: Statementstmt 81.7% 318 / 389 Branchbran 68.2% 142 / 208 Conditioncond 55.1% 70 / 127 MC/DCmcdc 25.3% 19 / 75 Subroutinesub 92.3% 36 / 39 Podpod 3.2% 1 / 31 totaltotal 67.4% 586 / 869 CC 144 SCAR 29.9
CC
144
Cov
73%
_do_middle_main_loop
50.7
do_pod_link
31.3
resolve_pod_link_by_table
21.7
CRAP 20.0
« Simple/PullParser.pm ↑ Summary Simple/HTMLBatch.pm »
1 package Pod::Simple::HTML;
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use Pod::Simple::PullParser ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 our @ISA = ('Pod::Simple::PullParser');
6 7 our $VERSION = '3.48';
7 7 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=13.1
8 7 ▶ if(defined &DEBUG) { } # no-op
Branch: 2 branches
BranchTrueFalseTotal
if (defined &Pod::Simple::HTML::DEBUG) { } 0 7 7
elsif (defined &Pod::Simple::DEBUG) { } 7 0 7
9 7 elsif( defined &Pod::Simple::DEBUG ) { *DEBUG = \&Pod::Simple::DEBUG }
10 0 else { *DEBUG = sub () {0}; }
11 }
12  
13 7 ▶our $Doctype_decl ||= ''; # No. Just No. Don't even ask me for it.
Condition50%1/2
our $Doctype_decl ||= ""
l!l
07
MC/DC0%0/1
our $Doctype_decl ||= ""
our $Doctype_decl
Truth table50%1/2
A
A= our $Doctype_decl
Aresult
11
00
14 # qq{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
15 # "http://www.w3.org/TR/html4/loose.dtd">\n};
16  
17 7 ▶our $Content_decl ||=
Condition50%1/2
our $Content_decl ||= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" >"
l!l
07
MC/DC0%0/1
our $Content_decl ||= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" >"
our $Content_decl
Truth table50%1/2
A
A= our $Content_decl
Aresult
11
00
18 q{<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >};
19  
20 7 our $HTML_EXTENSION;
21 7 ▶$HTML_EXTENSION = '.html' unless defined $HTML_EXTENSION;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::Simple::HTML::HTML_EXTENSION 7 0 7
22 7 our $Computerese;
23 7 ▶$Computerese = "" unless defined $Computerese;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::Simple::HTML::Computerese 7 0 7
24 7 our $LamePad;
25 7 ▶$LamePad = '' unless defined $LamePad;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::Simple::HTML::LamePad 7 0 7
26  
27 7 our $Linearization_Limit;
28 7 ▶$Linearization_Limit = 120 unless defined $Linearization_Limit;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::Simple::HTML::Linearization_Limit 7 0 7
29 # headings/items longer than that won't get an <a name="...">
30 7 our $Perldoc_URL_Prefix;
31 7 ▶$Perldoc_URL_Prefix = 'https://metacpan.org/pod/'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::Simple::HTML::Perldoc_URL_Prefix 7 0 7
32 unless defined $Perldoc_URL_Prefix;
33 7 our $Perldoc_URL_Postfix;
34 7 ▶$Perldoc_URL_Postfix = ''
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::Simple::HTML::Perldoc_URL_Postfix 7 0 7
35 unless defined $Perldoc_URL_Postfix;
36  
37  
38 7 our $Man_URL_Prefix = 'https://man7.org/linux/man-pages/man';
39 7 our $Man_URL_Postfix = '.html';
40  
41 7 our $Title_Prefix;
42 7 ▶$Title_Prefix = '' unless defined $Title_Prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::Simple::HTML::Title_Prefix 7 0 7
43 7 our $Title_Postfix;
44 7 ▶$Title_Postfix = '' unless defined $Title_Postfix;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::Simple::HTML::Title_Postfix 7 0 7
45 7 our %ToIndex = map {; $_ => 1 } qw(head1 head2 head3 head4 ); # item-text
46 # 'item-text' stuff in the index doesn't quite work, and may
47 # not be a good idea anyhow.
48  
49  
50 7 __PACKAGE__->_accessorize(
51 'perldoc_url_prefix',
52 # In turning L<Foo::Bar> into http://whatever/Foo%3a%3aBar, what
53 # to put before the "Foo%3a%3aBar".
54 # (for singleton mode only?)
55 'perldoc_url_postfix',
56 # what to put after "Foo%3a%3aBar" in the URL. Normally "".
57  
58 'man_url_prefix',
59 # In turning L<crontab(5)> into http://whatever/man/1/crontab, what
60 # to put before the "1/crontab".
61 'man_url_postfix',
62 # what to put after the "1/crontab" in the URL. Normally ".html".
63  
64 'batch_mode', # whether we're in batch mode
65 'batch_mode_current_level',
66 # When in batch mode, how deep the current module is: 1 for "LWP",
67 # 2 for "LWP::Procotol", 3 for "LWP::Protocol::GHTTP", etc
68  
69 'title_prefix', 'title_postfix',
70 # What to put before and after the title in the head.
71 # Should already be &-escaped
72  
73 'html_h_level',
74  
75 'html_header_before_title',
76 'html_header_after_title',
77 'html_footer',
78 'top_anchor',
79  
80 'index', # whether to add an index at the top of each page
81 # (actually it's a table-of-contents, but we'll call it an index,
82 # out of apparently longstanding habit)
83  
84 'html_css', # URL of CSS file to point to
85 'html_javascript', # URL of Javascript file to point to
86  
87 'force_title', # should already be &-escaped
88 'default_title', # should already be &-escaped
89 );
90  
91 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92 7 my @_to_accept;
93  
94 our %Tagmap = (
95 'Verbatim' => "\n<pre$Computerese>",
96 '/Verbatim' => "</pre>\n",
97 'VerbatimFormatted' => "\n<pre$Computerese>",
98 '/VerbatimFormatted' => "</pre>\n",
99 'VerbatimB' => "<b>",
100 '/VerbatimB' => "</b>",
101 'VerbatimI' => "<i>",
102 '/VerbatimI' => "</i>",
103 'VerbatimBI' => "<b><i>",
104 '/VerbatimBI' => "</i></b>",
105  
106  
107 'Data' => "\n",
108 '/Data' => "\n",
109  
110 'head1' => "\n<h1>", # And also stick in an <a name="...">
111 'head2' => "\n<h2>", # ''
112 'head3' => "\n<h3>", # ''
113 'head4' => "\n<h4>", # ''
114 'head5' => "\n<h5>", # ''
115 'head6' => "\n<h6>", # ''
116 '/head1' => "</a></h1>\n",
117 '/head2' => "</a></h2>\n",
118 '/head3' => "</a></h3>\n",
119 '/head4' => "</a></h4>\n",
120 '/head5' => "</a></h5>\n",
121 '/head6' => "</a></h6>\n",
122  
123 'X' => "<!--\n\tINDEX: ",
124 '/X' => "\n-->",
125  
126 changes(qw(
127 Para=p
128 B=b I=i U=u
129 over-bullet=ul
130 over-number=ol
131 over-text=dl
132 over-block=blockquote
133 item-bullet=li
134 item-number=li
135 item-text=dt
136 )),
137 changes2(
138 7 ▶ map {; m/^([-a-z]+)/s && push @_to_accept, $1; $_ }
Branch: 1 branch
BranchTrueFalseTotal
/^([-a-z]+)/s and push @_to_accept, $1 105 0 105
139 qw[
140 sample=samp
141 definition=dfn
142 keyboard=kbd
143 variable=var
144 citation=cite
145 abbreviation=abbr
146 acronym=acronym
147 subscript=sub
148 superscript=sup
149 big=big
150 small=small
151 underline=u
152 strikethrough=s
153 preformat=pre
154 teletype=tt
155 ] # no point in providing a way to get <q>...</q>, I think
156 ),
157  
158 '/item-bullet' => "</li>$LamePad\n",
159 '/item-number' => "</li>$LamePad\n",
160 '/item-text' => "</a></dt>$LamePad\n",
161 'item-body' => "\n<dd>",
162 '/item-body' => "</dd>\n",
163  
164  
165 'B' => "<b>", '/B' => "</b>",
166 'I' => "<i>", '/I' => "</i>",
167 'U' => "<u>", '/U' => "</u>",
168 'F' => "<em$Computerese>", '/F' => "</em>",
169 'C' => "<code$Computerese>", '/C' => "</code>",
170 'L' => "<a href='YOU_SHOULD_NEVER_SEE_THIS'>", # ideally never used!
171 '/L' => "</a>",
172 );
173  
174 7 ▶sub changes {
Subroutine changes: called CC=2 SCAR=7.2
Pod undocumented
175 7 ▶ return map {; m/^([-_:0-9a-zA-Z]+)=([-_:0-9a-zA-Z]+)$/s
Branch: 1 branch
BranchTrueFalseTotal
/^([-_:0-9a-zA-Z]+)=([-_:0-9a-zA-Z]+)$/s ? : 77 0 77
176 ? ( $1, => "\n<$2>", "/$1", => "</$2>\n" ) : die "Funky $_"
177 } @_;
178 }
179 7 ▶sub changes2 {
Subroutine changes2: called CC=2 SCAR=7.2
Pod undocumented
180 7 ▶ return map {; m/^([-_:0-9a-zA-Z]+)=([-_:0-9a-zA-Z]+)$/s
Branch: 1 branch
BranchTrueFalseTotal
/^([-_:0-9a-zA-Z]+)=([-_:0-9a-zA-Z]+)$/s ? : 105 0 105
181 ? ( $1, => "<$2>", "/$1", => "</$2>" ) : die "Funky $_"
182 } @_;
183 }
184  
185 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186 0 ▶sub go { Pod::Simple::HTML->parse_from_file(@ARGV); exit 0 }
Subroutine go: not called CC=1 SCAR=6.9
Pod undocumented
187 # Just so we can run from the command line. No options.
188 # For that, use perldoc!
189 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190  
191 60 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
192 60 my $new = shift->SUPER::new(@_);
193 #$new->nix_X_codes(1);
194 60 $new->nbsp_for_S(1);
195 60 $new->accept_targets( 'html', 'HTML' );
196 60 $new->accept_codes('VerbatimFormatted');
197 60 $new->accept_codes(@_to_accept);
198 60 DEBUG > 2 and print STDERR "To accept: ", join(' ',@_to_accept), "\n";
199  
200 60 $new->perldoc_url_prefix( $Perldoc_URL_Prefix );
201 60 $new->perldoc_url_postfix( $Perldoc_URL_Postfix );
202 60 $new->man_url_prefix( $Man_URL_Prefix );
203 60 $new->man_url_postfix( $Man_URL_Postfix );
204 60 $new->title_prefix( $Title_Prefix );
205 60 $new->title_postfix( $Title_Postfix );
206  
207 60 $new->html_header_before_title(
208 qq[$Doctype_decl<html><head><title>]
209 );
210 60 $new->html_header_after_title( join "\n" =>
211 "</title>",
212 $Content_decl,
213 "</head>\n<body class='pod'>",
214 $new->version_tag_comment,
215 "<!-- start doc -->\n",
216 );
217 60 $new->html_footer( qq[\n<!-- end doc -->\n\n</body></html>\n] );
218 60 $new->top_anchor( "<a name='___top' class='dummyTopAnchor' ></a>\n" );
219  
220 60 $new->{'Tagmap'} = {%Tagmap};
221  
222 60 return $new;
223 }
224  
225 59 ▶sub __adjust_html_h_levels {
Subroutine __adjust_html_h_levels: called CC=5 SCAR=16.2
226 59 my ($self) = @_;
227 59 my $Tagmap = $self->{'Tagmap'};
228  
229 59 my $add = $self->html_h_level;
230 59 ▶ return unless defined $add;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $add 58 1 59
231 1 ▶ return if ($self->{'Adjusted_html_h_levels'}||0) == $add;
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Adjusted_html_h_levels"} || 0) == $add 0 1 1
Condition50%1/2
$self->{'Adjusted_html_h_levels'} || 0
l!l
01
MC/DC0%0/1
$self->{'Adjusted_html_h_levels'} || 0
$self->{'Adjusted_html_h_levels'}
Truth table50%1/2
A
A= $self->{'Adjusted_html_h_levels'}
Aresult
11
00
232  
233 1 $add -= 1;
234 1 for (1 .. 6) {
235 6 $Tagmap->{"head$_"} =~ s/$_/$_ + $add/e;
236 6 $Tagmap->{"/head$_"} =~ s/$_/$_ + $add/e;
237 }
238 }
239  
240 10 ▶sub batch_mode_page_object_init {
Subroutine batch_mode_page_object_init: called CC=1 SCAR=0.0
Pod undocumented
241 10 my($self, $batchconvobj, $module, $infile, $outfile, $depth) = @_;
242 10 DEBUG and print STDERR "Initting $self\n for $module\n",
243 " in $infile\n out $outfile\n depth $depth\n";
244 10 $self->batch_mode(1);
245 10 $self->batch_mode_current_level($depth);
246 10 return $self;
247 }
248  
249 60 ▶sub run {
Subroutine run: called CC=4 SCAR=13.9
Pod undocumented
250 60 my $self = $_[0];
251 60 ▶ return $self->do_middle if $self->bare_output;
Branch: 1 branch
BranchTrueFalseTotal
if $self->bare_output 42 18 60
252 return
253 18 ▶ $self->do_beginning && $self->do_middle && $self->do_end;
Condition83%5/6
$self->do_beginning && $self->do_middle && $self->do_end
!ll&&!rl&&r
1512
$self->do_beginning and $self->do_middle
!ll&&!rl&&r
1017
MC/DC33%1/3
$self->do_beginning && $self->do_middle && $self->do_end
$self->do_beginning $self->do_middle $self->do_end
Truth table50%2/4
A and B && C
A= $self->do_beginningB= $self->do_middleC= $self->do_end
ABCresult
0XX0
10X0
1100
1111
254 }
255  
256 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
257  
258 18 ▶sub do_beginning {
Subroutine do_beginning: called CC=12 SCAR=25.5
Pod undocumented
259 18 my $self = $_[0];
260  
261 18 my $title;
262  
263 18 ▶ if(defined $self->force_title) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->force_title) { } 0 18 18
264 0 $title = $self->force_title;
265 0 DEBUG and print STDERR "Forcing title to be $title\n";
266 } else {
267 # Actually try looking for the title in the document:
268 18 $title = $self->get_short_title();
269 18 ▶ unless($self->content_seen) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->content_seen) 1 17 18
270 1 DEBUG and print STDERR "No content seen in search for title.\n";
271 1 return;
272 }
273 17 $self->{'Title'} = $title;
274  
275 17 ▶ if(defined $title and $title =~ m/\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $title and $title =~ /\S/) { } 14 3 17
Condition66%2/3
defined $title and $title =~ /\S/
!ll&&!rl&&r
0314
MC/DC50%1/2
defined $title and $title =~ /\S/
defined $title $title =~ /\S/
Truth table66%2/3
A and B
A= defined $titleB= $title =~ /\S/
ABresult
0X0
100
111
276 14 $title = $self->title_prefix . esc($title) . $self->title_postfix;
277 } else {
278 3 $title = $self->default_title;
279 3 ▶ $title = '' unless defined $title;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $title 3 0 3
280 3 DEBUG and print STDERR "Title defaults to $title\n";
281 }
282 }
283  
284  
285 17 ▶ my $after = $self->html_header_after_title || '';
Condition50%1/2
$self->html_header_after_title || ''
l!l
170
MC/DC0%0/1
$self->html_header_after_title || ''
$self->html_header_after_title
Truth table50%1/2
A
A= $self->html_header_after_title
Aresult
11
00
286 17 ▶ if($self->html_css) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->html_css) 10 7 17
287 10 ▶ my $link =
Branch: 1 branch
BranchTrueFalseTotal
$self->html_css =~ /</ ? : 10 0 10
288 $self->html_css =~ m/</
289 ? $self->html_css # It's a big blob of markup, let's drop it in
290 : sprintf( # It's just a URL, so let's wrap it up
291 qq[<link rel="stylesheet" type="text/css" title="pod_stylesheet" href="%s">\n],
292 $self->html_css,
293 );
294 10 $after =~ s{(</head>)}{$link\n$1}i; # otherwise nevermind
295 }
296 17 $self->_add_top_anchor(\$after);
297  
298 17 ▶ if($self->html_javascript) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->html_javascript) 10 7 17
299 10 ▶ my $link =
Branch: 1 branch
BranchTrueFalseTotal
$self->html_javascript =~ /</ ? : 10 0 10
300 $self->html_javascript =~ m/</
301 ? $self->html_javascript # It's a big blob of markup, let's drop it in
302 : sprintf( # It's just a URL, so let's wrap it up
303 qq[<script type="text/javascript" src="%s"></script>\n],
304 $self->html_javascript,
305 );
306 10 $after =~ s{(</head>)}{$link\n$1}i; # otherwise nevermind
307 }
308  
309 17 ▶ print {$self->{'output_fh'}}
Condition50%1/2
$self->html_header_before_title || ''
l!l
170
MC/DC0%0/1
$self->html_header_before_title || ''
$self->html_header_before_title
Truth table50%1/2
A
A= $self->html_header_before_title
Aresult
11
00
310 $self->html_header_before_title || '',
311 $title, # already escaped
312 $after,
313 ;
314  
315 17 DEBUG and print STDERR "Returning from do_beginning...\n";
316 17 return 1;
317 }
318  
319 17 ▶sub _add_top_anchor {
Subroutine _add_top_anchor: called CC=4 SCAR=14.1
320 17 my($self, $text_r) = @_;
321 17 ▶ unless($$text_r and $$text_r =~ m/name=['"]___top['"]/) { # a hack
Branch: 1 branch
BranchTrueFalseTotal
unless ($$text_r and $$text_r =~ /name=['"]___top['"]/) 7 10 17
Condition66%2/3
$$text_r and $$text_r =~ /name=['"]___top['"]/
!ll&&!rl&&r
0710
MC/DC50%1/2
$$text_r and $$text_r =~ /name=['"]___top['"]/
$$text_r $$text_r =~ /name=['"]___top['"]/
Truth table66%2/3
A and B
A= $$text_rB= $$text_r =~ /name=['"]___top['"]/
ABresult
0X0
100
111
322 7 ▶ $$text_r .= $self->top_anchor || '';
Condition50%1/2
$self->top_anchor || ''
l!l
70
MC/DC0%0/1
$self->top_anchor || ''
$self->top_anchor
Truth table50%1/2
A
A= $self->top_anchor
Aresult
11
00
323 }
324 17 return;
325 }
326  
327 60 ▶sub version_tag_comment {
Subroutine version_tag_comment: called CC=2 SCAR=7.2
Pod undocumented
328 60 my $self = shift;
329 return sprintf
330 "<!--\n generated by %s v%s,\n using %s v%s,\n under Perl v%s at %s GMT.\n\n %s\n\n-->\n",
331 esc(
332 ref($self), $self->VERSION(), $ISA[0], $ISA[0]->VERSION(),
333 60 ▶ $], scalar(gmtime($ENV{SOURCE_DATE_EPOCH} || time)),
Condition50%1/2
$ENV{'SOURCE_DATE_EPOCH'} || time
l!l
060
MC/DC0%0/1
$ENV{'SOURCE_DATE_EPOCH'} || time
$ENV{'SOURCE_DATE_EPOCH'}
Truth table50%1/2
A
A= $ENV{'SOURCE_DATE_EPOCH'}
Aresult
11
00
334 ), $self->_modnote(),
335 ;
336 }
337  
338 60 ▶sub _modnote {
Subroutine _modnote: called CC=2 SCAR=8.1
339 60 ▶ my $class = ref($_[0]) || $_[0];
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
6000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
340 60 return join "\n " => grep m/\S/, split "\n",
341  
342 qq{
343 If you want to change this HTML document, you probably shouldn't do that
344 by changing it directly. Instead, see about changing the calling options
345 to $class, and/or subclassing $class,
346 then reconverting this document from the Pod source.
347 When in doubt, email the author of $class for advice.
348 See 'perldoc $class' for more info.
349 };
350  
351 }
352  
353 17 ▶sub do_end {
Subroutine do_end: called CC=2 SCAR=7.0
Pod undocumented
354 17 my $self = $_[0];
355 17 ▶ print {$self->{'output_fh'}} $self->html_footer || '';
Condition50%1/2
$self->html_footer || ''
l!l
170
MC/DC0%0/1
$self->html_footer || ''
$self->html_footer
Truth table50%1/2
A
A= $self->html_footer
Aresult
11
00
356 17 return 1;
357 }
358  
359 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
360 # Normally this would just be a call to _do_middle_main_loop -- but we
361 # have to do some elaborate things to emit all the content and then
362 # summarize it and output it /before/ the content that it's a summary of.
363  
364 59 ▶sub do_middle {
Subroutine do_middle: called CC=5 SCAR=20.3
Pod undocumented
365 59 my $self = $_[0];
366 59 ▶ return $self->_do_middle_main_loop unless $self->index;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->index 49 10 59
367  
368 10 ▶ if( $self->output_string ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->output_string) 0 10 10
369 # An efficiency hack
370 0 my $out = $self->output_string; #it's a reference to it
371 0 my $sneakytag = "\f\f\e\e\b\bIndex Here\e\e\b\b\f\f\n";
372 0 $$out .= $sneakytag;
373 0 $self->_do_middle_main_loop;
374 0 $sneakytag = quotemeta($sneakytag);
375 0 my $index = $self->index_as_html();
376 0 ▶ if( $$out =~ s/$sneakytag/$index/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$out =~ s/$sneakytag/$index/s) { } 0 0 0
377 # Expected case
378 0 DEBUG and print STDERR "Inserted ", length($index), " bytes of index HTML into $out.\n";
379 } else {
380 0 DEBUG and print STDERR "Odd, couldn't find where to insert the index in the output!\n";
381 # I don't think this should ever happen.
382 }
383 0 return 1;
384 }
385  
386 10 ▶ unless( $self->output_fh ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->output_fh) 0 10 10
387 0 require Carp;
388 0 Carp::confess("Parser object \$p doesn't seem to have any output object! I don't know how to deal with that.");
389 }
390  
391 # If we get here, we're outputting to a FH. So we need to do some magic.
392 # Namely, divert all content to a string, which we output after the index.
393 10 my $fh = $self->output_fh;
394 10 my $content = '';
395 {
396 # Our horrible bait and switch:
397 10 $self->output_string( \$content );
398 10 $self->_do_middle_main_loop;
399 10 $self->abandon_output_string();
400 10 $self->output_fh($fh);
401 }
402 10 print $fh $self->index_as_html();
403 10 print $fh $content;
404  
405 10 return 1;
406 }
407  
408 ###########################################################################
409  
410 10 ▶sub index_as_html {
Subroutine index_as_html: called CC=9 SCAR=22.4
Pod undocumented
411 10 my $self = $_[0];
412 # This is meant to be called AFTER the input document has been parsed!
413  
414 10 ▶ my $points = $self->{'PSHTML_index_points'} || [];
Condition50%1/2
$self->{'PSHTML_index_points'} || []
l!l
100
MC/DC0%0/1
$self->{'PSHTML_index_points'} || []
$self->{'PSHTML_index_points'}
Truth table50%1/2
A
A= $self->{'PSHTML_index_points'}
Aresult
11
00
415  
416 10 ▶ @$points > 1 or return qq[<div class='indexgroupEmpty'></div>\n];
Branch: 1 branch
BranchTrueFalseTotal
@$points > 1 or return "<div class='indexgroupEmpty'></div>\n" 8 2 10
417 # There's no point in having a 0-item or 1-item index, I dare say.
418  
419 8 my(@out) = qq{\n<div class='indexgroup'>};
420 8 my $level = 0;
421  
422 8 my( $target_level, $previous_tagname, $tagname, $text, $anchorname, $indent);
423 8 foreach my $p (@$points, ['head0', '(end)']) {
424 26 ($tagname, $text) = @$p;
425 26 $anchorname = $self->section_escape($text);
426 26 ▶ if( $tagname =~ m{^head(\d+)$} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagname =~ /^head(\d+)$/) { } 26 0 26
427 26 $target_level = 0 + $1;
428 } else { # must be some kinda list item
429 0 ▶ if($previous_tagname =~ m{^head\d+$} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($previous_tagname =~ /^head\d+$/) { } 0 0 0
430 0 $target_level = $level + 1;
431 } else {
432 0 $target_level = $level; # no change needed
433 }
434 }
435  
436 # Get to target_level by opening or closing ULs
437 26 ▶ while($level > $target_level)
Branch: 1 branch
BranchTrueFalseTotal
if ($level > $target_level) 9 26 35
438 9 { --$level; push @out, (" " x $level) . "</ul>"; }
439 26 ▶ while($level < $target_level)
Branch: 1 branch
BranchTrueFalseTotal
if ($level < $target_level) 9 26 35
440 9 { ++$level; push @out, (" " x ($level-1))
441 . "<ul class='indexList indexList$level'>"; }
442  
443 26 $previous_tagname = $tagname;
444 26 ▶ next unless $level;
Branch: 1 branch
BranchTrueFalseTotal
unless $level 8 18 26
445  
446 18 $indent = ' ' x $level;
447 18 push @out, sprintf
448 "%s<li class='indexItem indexItem%s'><a href='#%s'>%s</a>",
449 $indent, $level, esc($anchorname), esc($text)
450 ;
451 }
452 8 push @out, "</div>\n";
453 8 return join "\n", @out;
454 }
455  
456 ###########################################################################
457  
458 59 ▶sub _do_middle_main_loop {
Subroutine _do_middle_main_loop: called CC=41 SCAR=39.3
459 59 my $self = $_[0];
460 59 my $fh = $self->{'output_fh'};
461 59 my $tagmap = $self->{'Tagmap'};
462  
463 59 $self->__adjust_html_h_levels;
464  
465 59 my($token, $type, $tagname, $linkto, $linktype);
466 59 my @stack;
467 59 my $dont_wrap = 0;
468  
469 59 ▶ while($token = $self->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $self->get_token) 522 59 581
470  
471 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
472 522 ▶ if( ($type = $token->type) eq 'start' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (($type = $token->type) eq 'start') { } 203 319 522
elsif ($type eq 'end') { } 203 116 319
elsif ($type eq 'text') { } 116 0 116
473 203 ▶ if(($tagname = $token->tagname) eq 'L') {
Branch: 3 branches
BranchTrueFalseTotal
if (($tagname = $token->tagname) eq 'L') { } 22 181 203
elsif ($tagname eq 'item-text' or $tagname =~ /^head\d$/s) { } 37 144 181
elsif ($tagname eq 'Data') { } 4 140 144
474 22 ▶ $linktype = $token->attr('type') || 'insane';
Condition50%1/2
$token->attr('type') || 'insane'
l!l
220
MC/DC0%0/1
$token->attr('type') || 'insane'
$token->attr('type')
Truth table50%1/2
A
A= $token->attr('type')
Aresult
11
00
475  
476 22 $linkto = $self->do_link($token);
477  
478 22 ▶ if(defined $linkto and length $linkto) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $linkto and length $linkto) { } 22 0 22
Condition33%1/3
defined $linkto and length $linkto
!ll&&!rl&&r
0022
MC/DC0%0/2
defined $linkto and length $linkto
defined $linkto length $linkto
Truth table33%1/3
A and B
A= defined $linktoB= length $linkto
ABresult
0X0
100
111
479 22 esc($linkto);
480 # (Yes, SGML-escaping applies on top of %-escaping!
481 # But it's rarely noticeable in practice.)
482 22 print $fh qq{<a href="$linkto" class="podlink$linktype"\n>};
483 } else {
484 0 print $fh "<a>"; # Yes, an 'a' element with no attributes!
485 }
486  
487 ▶ } elsif ($tagname eq 'item-text' or $tagname =~ m/^head\d$/s) {
Condition100%3/3
$tagname eq "item-text" or $tagname =~ /^head\d$/s
l!l&&r!l&&!r
433144
MC/DC100%2/2
$tagname eq "item-text" or $tagname =~ /^head\d$/s
$tagname eq "item-text" $tagname =~ /^head\d$/s
Truth table100%3/3
A or B
A= $tagname eq "item-text"B= $tagname =~ /^head\d$/s
ABresult
1X1
011
000
488 37 ▶ print $fh $tagmap->{$tagname} || next;
Condition50%1/2
$tagmap->{$tagname} || (next)
l!l
370
MC/DC0%0/1
$tagmap->{$tagname} || (next)
$tagmap->{$tagname}
Truth table50%1/2
A
A= $tagmap->{$tagname}
Aresult
11
00
489  
490 37 my @to_unget;
491 37 while(1) {
492 85 push @to_unget, $self->get_token;
493 85 ▶ last if $to_unget[-1]->is_end
Branch: 1 branch
BranchTrueFalseTotal
if $to_unget[-1]->is_end and $to_unget[-1]->tagname eq $tagname 37 48 85
Condition100%3/3
$to_unget[-1]->is_end and $to_unget[-1]->tagname eq $tagname
!ll&&!rl&&r
45337
MC/DC100%2/2
$to_unget[-1]->is_end and $to_unget[-1]->tagname eq $tagname
$to_unget[-1]->is_end $to_unget[-1]->tagname eq $tagname
Truth table100%3/3
A and B
A= $to_unget[-1]->is_endB= $to_unget[-1]->tagname eq $tagname
ABresult
0X0
100
111
494 and $to_unget[-1]->tagname eq $tagname;
495  
496 # TODO: support for X<...>'s found in here? (maybe hack into linearize_tokens)
497 }
498  
499 37 my $name = $self->linearize_tokens(@to_unget);
500 37 ▶ $name = $self->do_section($name, $token) if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 37 0 37
501  
502 37 print $fh "<a ";
503 37 ▶ if ($tagname =~ m/^head\d$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagname =~ /^head\d$/s) 33 4 37
504 33 ▶ print $fh "class='u'", $self->index
Branch: 1 branch
BranchTrueFalseTotal
$self->index ? : 20 13 33
505 ? " href='#___top' title='click to go to top of document'\n"
506 : "\n";
507 }
508  
509 37 ▶ if(defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 37 0 37
510 37 my $esc = esc( $self->section_name_tidy( $name ) );
511 37 print $fh qq[name="$esc"];
512 37 DEBUG and print STDERR "Linearized ", scalar(@to_unget),
513 " tokens as \"$name\".\n";
514 31 push @{ $self->{'PSHTML_index_points'} }, [$tagname, $name]
515 37 ▶ if $ToIndex{ $tagname };
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Simple::HTML::ToIndex{$tagname} 31 6 37
516 # Obviously, this discards all formatting codes (saving
517 # just their content), but ahwell.
518  
519 } else { # ludicrously long, so nevermind
520 0 DEBUG and print STDERR "Linearized ", scalar(@to_unget),
521 " tokens, but it was too long, so nevermind.\n";
522 }
523 37 print $fh "\n>";
524 37 $self->unget_token(@to_unget);
525  
526 } elsif ($tagname eq 'Data') {
527 4 my $next = $self->get_token;
528 4 ▶ next unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 4 4
529 4 ▶ unless( $next->type eq 'text' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next->type eq "text") 0 4 4
530 0 $self->unget_token($next);
531 0 next;
532 }
533 4 DEBUG and print STDERR " raw text ", $next->text, "\n";
534 # The parser sometimes preserves newlines and sometimes doesn't!
535 4 (my $text = $next->text) =~ s/\n\z//;
536 4 print $fh $text, "\n";
537 4 next;
538  
539 } else {
540 140 ▶ if( $tagname =~ m/^over-/s ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagname =~ /^over-/s) { } 3 137 140
elsif ($tagname =~ /^item-/s and @stack and $stack[-1]) { } 0 274 274
541 3 push @stack, '';
542 ▶ } elsif( $tagname =~ m/^item-/s and @stack and $stack[-1] ) {
Condition33%2/6
$tagname =~ /^item-/s and @stack and $stack[-1]
!ll&&!rl&&r
13700
$tagname =~ /^item-/s and @stack
!ll&&!rl&&r
13700
MC/DC0%0/3
$tagname =~ /^item-/s and @stack and $stack[-1]
$tagname =~ /^item-/s @stack $stack[-1]
Truth table25%1/4
A and B and C
A= $tagname =~ /^item-/sB= @stackC= $stack[-1]
ABCresult
0XX0
10X0
1100
1111
543 0 print $fh $stack[-1];
544 0 $stack[-1] = '';
545 }
546 140 ▶ print $fh $tagmap->{$tagname} || next;
Condition100%2/2
$tagmap->{$tagname} || (next)
l!l
8060
MC/DC100%1/1
$tagmap->{$tagname} || (next)
$tagmap->{$tagname}
Truth table100%2/2
A
A= $tagmap->{$tagname}
Aresult
11
00
547 80 ▶ ++$dont_wrap if $tagname eq 'Verbatim' or $tagname eq "VerbatimFormatted"
Branch: 1 branch
BranchTrueFalseTotal
if $tagname eq "Verbatim" or $tagname eq "VerbatimFormatted" or $tagname eq "X" 5 75 80
Condition83%5/6
$tagname eq "Verbatim" or $tagname eq "VerbatimFormatted" or $tagname eq "X"
l!l&&r!l&&!r
2375
$tagname eq "Verbatim" or $tagname eq "VerbatimFormatted"
l!l&&r!l&&!r
0278
MC/DC66%2/3
$tagname eq "Verbatim" or $tagname eq "VerbatimFormatted" or $tagname eq "X"
$tagname eq "Verbatim" $tagname eq "VerbatimFormatted" $tagname eq "X"
Truth table75%3/4
A or B or C
A= $tagname eq "Verbatim"B= $tagname eq "VerbatimFormatted"C= $tagname eq "X"
ABCresult
1XX1
01X1
0011
0000
548 or $tagname eq 'X';
549 }
550  
551 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
552 } elsif( $type eq 'end' ) {
553 203 ▶ if( ($tagname = $token->tagname) =~ m/^over-/s ) {
Branch: 2 branches
BranchTrueFalseTotal
if (($tagname = $token->tagname) =~ /^over-/s) { } 3 200 203
elsif ($tagname =~ /^item-/s and @stack) { } 4 392 396
554 3 ▶ if( my $end = pop @stack ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $end = pop @stack) 3 0 3
555 3 print $fh $end;
556 }
557 ▶ } elsif( $tagname =~ m/^item-/s and @stack) {
Condition66%2/3
$tagname =~ /^item-/s and @stack
!ll&&!rl&&r
19604
MC/DC50%1/2
$tagname =~ /^item-/s and @stack
$tagname =~ /^item-/s @stack
Truth table66%2/3
A and B
A= $tagname =~ /^item-/sB= @stack
ABresult
0X0
100
111
558 4 $stack[-1] = $tagmap->{"/$tagname"};
559 4 ▶ if( $tagname eq 'item-text' and defined(my $next = $self->get_token) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagname eq "item-text" and defined(my $next = $self->get_token)) 4 0 4
Condition33%1/3
$tagname eq "item-text" and defined(my $next = $self->get_token)
!ll&&!rl&&r
004
MC/DC0%0/2
$tagname eq "item-text" and defined(my $next = $self->get_token)
$tagname eq "item-text" defined(my $next = $self->get_token)
Truth table33%1/3
A and B
A= $tagname eq "item-text"B= defined(my $next = $self->get_token)
ABresult
0X0
100
111
560 4 $self->unget_token($next);
561 4 ▶ if( $next->type eq 'start' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next->type eq "start") 3 1 4
562 3 print $fh $tagmap->{"/item-text"},$tagmap->{"item-body"};
563 3 $stack[-1] = $tagmap->{"/item-body"};
564 }
565 }
566 4 next;
567 }
568 199 ▶ print $fh $tagmap->{"/$tagname"} || next;
Condition100%2/2
$$tagmap{"/$tagname"} || (next)
l!l
13960
MC/DC100%1/1
$$tagmap{"/$tagname"} || (next)
$$tagmap{"/$tagname"}
Truth table100%2/2
A
A= $$tagmap{"/$tagname"}
Aresult
11
00
569 139 ▶ --$dont_wrap if $tagname eq 'Verbatim' or $tagname eq 'X';
Branch: 1 branch
BranchTrueFalseTotal
if $tagname eq "Verbatim" or $tagname eq "X" 3 136 139
Condition66%2/3
$tagname eq "Verbatim" or $tagname eq "X"
l!l&&r!l&&!r
03136
MC/DC50%1/2
$tagname eq "Verbatim" or $tagname eq "X"
$tagname eq "Verbatim" $tagname eq "X"
Truth table66%2/3
A or B
A= $tagname eq "Verbatim"B= $tagname eq "X"
ABresult
1X1
011
000
570  
571 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
572 } elsif( $type eq 'text' ) {
573 116 esc($type = $token->text); # reuse $type, why not
574 116 ▶ $type =~ s/([\?\!\"\'\.\,]) /$1\n/g unless $dont_wrap;
Branch: 1 branch
BranchTrueFalseTotal
unless $dont_wrap 105 11 116
575 116 print $fh $type;
576 }
577  
578 }
579 59 return 1;
580 }
581  
582 ###########################################################################
583 #
584  
585 36 ▶sub do_section {
Subroutine do_section: called CC=1 SCAR=0.0
Pod undocumented
586 36 my($self, $name, $token) = @_;
587 36 return $name;
588 }
589  
590 22 ▶sub do_link {
Subroutine do_link: called CC=5 SCAR=17.3
Pod undocumented
591 22 my($self, $token) = @_;
592 22 my $type = $token->attr('type');
593 22 ▶ if(!defined $type) {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $type) { } 0 22 22
elsif ($type eq 'pod') { } 10 12 22
elsif ($type eq 'url') { } 9 3 12
elsif ($type eq 'man') { } 3 0 3
594 0 $self->whine("Typeless L!?", $token->attr('start_line'));
595 10 } elsif( $type eq 'pod') { return $self->do_pod_link($token);
596 9 } elsif( $type eq 'url') { return $self->do_url_link($token);
597 3 } elsif( $type eq 'man') { return $self->do_man_link($token);
598 } else {
599 0 $self->whine("L of unknown type $type!?", $token->attr('start_line'));
600 }
601 0 return 'FNORG'; # should never get called
602 }
603  
604 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
605  
606 9 ▶sub do_url_link { return $_[1]->attr('to') }
Subroutine do_url_link: called CC=1 SCAR=0.0
Pod undocumented
607  
608 3 ▶sub do_man_link {
Subroutine do_man_link: called CC=5 SCAR=16.7
Pod undocumented
609 3 my ($self, $link) = @_;
610 3 my $to = $link->attr('to');
611 3 my $frag = $link->attr('section');
612  
613 3 ▶ return undef unless defined $to and length $to; # should never happen
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to and length $to 0 3 3
Condition33%1/3
defined $to and length $to
!ll&&!rl&&r
003
MC/DC0%0/2
defined $to and length $to
defined $to length $to
Truth table33%1/3
A and B
A= defined $toB= length $to
ABresult
0X0
100
111
614  
615 3 ▶ $frag = $self->section_escape($frag)
Branch: 1 branch
BranchTrueFalseTotal
if defined $frag and length(($frag .= '')) 1 2 3
Condition66%2/3
defined $frag and length(($frag .= ''))
!ll&&!rl&&r
201
MC/DC50%1/2
defined $frag and length(($frag .= ''))
defined $frag length(($frag .= ''))
Truth table66%2/3
A and B
A= defined $fragB= length(($frag .= ''))
ABresult
0X0
100
111
616 if defined $frag and length($frag .= ''); # (stringify)
617  
618 3 DEBUG and print STDERR "Resolving \"$to/$frag\"\n\n";
619  
620 3 return $self->resolve_man_page_link($to, $frag);
621 }
622  
623  
624 10 ▶sub do_pod_link {
Subroutine do_pod_link: called CC=19 SCAR=34.4
Pod undocumented
625 # And now things get really messy...
626 10 my($self, $link) = @_;
627 10 my $to = $link->attr('to');
628 10 my $section = $link->attr('section');
629 return undef unless( # should never happen
630 10 ▶ (defined $to and length $to) or
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to and length $to or defined $section and length $section 0 10 10
Condition55%5/9
defined $to and length $to or defined $section and length $section
l!l&&r!l&&!r
730
defined $to and length $to
!ll&&!rl&&r
307
defined $section and length $section
!ll&&!rl&&r
003
MC/DC0%0/4
defined $to and length $to or defined $section and length $section
defined $to length $to defined $section length $section
Truth table28%2/7
A and B or C and D
A= defined $toB= length $toC= defined $sectionD= length $section
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
631 (defined $section and length $section)
632 );
633  
634 10 ▶ $section = $self->section_escape($section)
Branch: 1 branch
BranchTrueFalseTotal
if defined $section and length(($section .= '')) 5 5 10
Condition66%2/3
defined $section and length(($section .= ''))
!ll&&!rl&&r
505
MC/DC50%1/2
defined $section and length(($section .= ''))
defined $section length(($section .= ''))
Truth table66%2/3
A and B
A= defined $sectionB= length(($section .= ''))
ABresult
0X0
100
111
635 if defined $section and length($section .= ''); # (stringify)
636  
637 10 DEBUG and printf STDERR "Resolving \"%s\" \"%s\"...\n",
638 $to || "(nil)", $section || "(nil)";
639  
640 {
641 # An early hack:
642 10 my $complete_url = $self->resolve_pod_link_by_table($to, $section);
643 10 ▶ if( $complete_url ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($complete_url) { } 0 10 10
644 0 DEBUG > 1 and print STDERR "resolve_pod_link_by_table(T,S) gives ",
645 $complete_url, "\n (Returning that.)\n";
646 0 return $complete_url;
647 } else {
648 10 DEBUG > 4 and print STDERR " resolve_pod_link_by_table(T,S)",
649 " didn't return anything interesting.\n";
650 }
651 }
652  
653 10 ▶ if(defined $to and length $to) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $to and length $to) 7 3 10
Condition66%2/3
defined $to and length $to
!ll&&!rl&&r
307
MC/DC50%1/2
defined $to and length $to
defined $to length $to
Truth table66%2/3
A and B
A= defined $toB= length $to
ABresult
0X0
100
111
654 # Give this routine first hack again
655 7 my $there = $self->resolve_pod_link_by_table($to);
656 7 ▶ if(defined $there and length $there) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $there and length $there) { } 0 7 7
Condition33%1/3
defined $there and length $there
!ll&&!rl&&r
700
MC/DC0%0/2
defined $there and length $there
defined $there length $there
Truth table33%1/3
A and B
A= defined $thereB= length $there
ABresult
0X0
100
111
657 0 DEBUG > 1
658 and print STDERR "resolve_pod_link_by_table(T) gives $there\n";
659 } else {
660 7 $there =
661 $self->resolve_pod_page_link($to, $section);
662 # (I pass it the section value, but I don't see a
663 # particular reason it'd use it.)
664 7 DEBUG > 1 and print STDERR "resolve_pod_page_link gives ", $there || "(nil)", "\n";
665 7 ▶ unless( defined $there and length $there ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $there and length $there) 0 7 7
Condition33%1/3
defined $there and length $there
!ll&&!rl&&r
007
MC/DC0%0/2
defined $there and length $there
defined $there length $there
Truth table33%1/3
A and B
A= defined $thereB= length $there
ABresult
0X0
100
111
666 0 DEBUG and print STDERR "Can't resolve $to\n";
667 0 return undef;
668 }
669 # resolve_pod_page_link returning undef is how it
670 # can signal that it gives up on making a link
671 }
672 7 $to = $there;
673 }
674  
675 #DEBUG and print STDERR "So far [", $to||'nil', "] [", $section||'nil', "]\n";
676  
677 10 ▶ my $out = (defined $to and length $to) ? $to : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $to && length $to ? : 7 3 10
Condition66%2/3
defined $to and length $to
!ll&&!rl&&r
307
MC/DC50%1/2
defined $to and length $to
defined $to length $to
Truth table66%2/3
A and B
A= defined $toB= length $to
ABresult
0X0
100
111
678 10 ▶ $out .= "#" . $section if defined $section and length $section;
Branch: 1 branch
BranchTrueFalseTotal
if defined $section and length $section 5 5 10
Condition66%2/3
defined $section and length $section
!ll&&!rl&&r
505
MC/DC50%1/2
defined $section and length $section
defined $section length $section
Truth table66%2/3
A and B
A= defined $sectionB= length $section
ABresult
0X0
100
111
679  
680 10 ▶ unless(length $out) { # sanity check
Branch: 1 branch
BranchTrueFalseTotal
unless (length $out) 0 10 10
681 0 DEBUG and printf STDERR "Oddly, couldn't resolve \"%s\" \"%s\"...\n",
682 $to || "(nil)", $section || "(nil)";
683 0 return undef;
684 }
685  
686 10 DEBUG and print STDERR "Resolved to $out\n";
687 10 return $out;
688 }
689  
690  
691 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
692  
693 32 ▶sub section_escape {
Subroutine section_escape: called CC=1 SCAR=0.0
Pod undocumented
694 32 my($self, $section) = @_;
695 32 return $self->section_url_escape(
696 $self->section_name_tidy($section)
697 );
698 }
699  
700 69 ▶sub section_name_tidy {
Subroutine section_name_tidy: called CC=3 SCAR=11.3
Pod undocumented
701 69 my($self, $section) = @_;
702 69 $section =~ s/^\s+//;
703 69 $section =~ s/\s+$//;
704 69 $section =~ tr/ /_/;
705 69 ▶ if ("$]" >= 5.006) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$]" >= 5.006) { } 69 0 69
706 69 $section =~ s/[[:cntrl:][:^ascii:]]//g; # drop crazy characters
707 } elsif ('A' eq chr(65)) { # But not on early EBCDIC
708 0 $section =~ tr/\x00-\x1F\x80-\x9F//d;
709 }
710 69 $section = $self->unicode_escape_url($section);
711 69 ▶ $section = '_' unless length $section;
Branch: 1 branch
BranchTrueFalseTotal
unless length $section 0 69 69
712 69 return $section;
713 }
714  
715 32 ▶sub section_url_escape { shift->general_url_escape(@_) }
Subroutine section_url_escape: called CC=1 SCAR=0.0
Pod undocumented
716 7 ▶sub pagepath_url_escape { shift->general_url_escape(@_) }
Subroutine pagepath_url_escape: called CC=1 SCAR=0.0
Pod undocumented
717 3 ▶sub manpage_url_escape { shift->general_url_escape(@_) }
Subroutine manpage_url_escape: called CC=1 SCAR=0.0
Pod undocumented
718  
719 42 ▶sub general_url_escape {
Subroutine general_url_escape: called CC=2 SCAR=7.8
Pod undocumented
720 42 my($self, $string) = @_;
721  
722 0 $string =~ s/([^\x00-\xFF])/join '', map sprintf('%%%02X',$_), unpack 'C*', $1/eg;
723 # express Unicode things as urlencode(utf(orig)).
724  
725 # A pretty conservative escaping, behoovey even for query components
726 # of a URL (see RFC 2396)
727  
728 42 ▶ if ("$]" >= 5.007_003) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$]" >= 5.007003) { } 42 0 42
729 42 $string =~ s/([^-_\.!~*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/sprintf('%%%02X',utf8::native_to_unicode(ord($1)))/eg;
730 } else { # Is broken for non-ASCII platforms on early perls
731 0 $string =~ s/([^-_\.!~*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/sprintf('%%%02X',ord($1))/eg;
732 }
733 # Yes, stipulate the list without a range, so that this can work right on
734 # all charsets that this module happens to run under.
735  
736 42 return $string;
737 }
738  
739 #--------------------------------------------------------------------------
740 #
741 # Oh look, a yawning portal to Hell! Let's play touch football right by it!
742 #
743  
744 7 ▶sub resolve_pod_page_link {
Subroutine resolve_pod_page_link: called CC=2 SCAR=7.2
Pod undocumented
745 # resolve_pod_page_link must return a properly escaped URL
746 7 my $self = shift;
747 7 ▶ return $self->batch_mode()
Branch: 1 branch
BranchTrueFalseTotal
$self->batch_mode ? : 0 7 7
748 ? $self->resolve_pod_page_link_batch_mode(@_)
749 : $self->resolve_pod_page_link_singleton_mode(@_)
750 ;
751 }
752  
753 7 ▶sub resolve_pod_page_link_singleton_mode {
Subroutine resolve_pod_page_link_singleton_mode: called CC=5 SCAR=17.5
Pod undocumented
754 7 my($self, $it) = @_;
755 7 ▶ return undef unless defined $it and length $it;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $it and length $it 0 7 7
Condition33%1/3
defined $it and length $it
!ll&&!rl&&r
007
MC/DC0%0/2
defined $it and length $it
defined $it length $it
Truth table33%1/3
A and B
A= defined $itB= length $it
ABresult
0X0
100
111
756 7 my $url = $self->pagepath_url_escape($it);
757  
758 7 $url =~ s{::$}{}s; # probably never comes up anyway
759 7 ▶ $url =~ s{::}{/}g unless $self->perldoc_url_prefix =~ m/\?/s; # sane DWIM?
Branch: 1 branch
BranchTrueFalseTotal
unless $self->perldoc_url_prefix =~ /\?/s 7 0 7
760  
761 7 ▶ return undef unless length $url;
Branch: 1 branch
BranchTrueFalseTotal
unless length $url 0 7 7
762 7 return $self->perldoc_url_prefix . $url . $self->perldoc_url_postfix;
763 }
764  
765 0 ▶sub resolve_pod_page_link_batch_mode {
Subroutine resolve_pod_page_link_batch_mode: not called CC=2 SCAR=17.9
Pod undocumented
766 0 my($self, $to) = @_;
767 0 DEBUG > 1 and print STDERR " During batch mode, resolving $to ...\n";
768 0 my @path = grep length($_), split m/::/s, $to, -1;
769 0 ▶ unless( @path ) { # sanity
Branch: 1 branch
BranchTrueFalseTotal
unless (@path) 0 0 0
770 0 DEBUG and print STDERR "Very odd! Splitting $to gives (nil)!\n";
771 0 return undef;
772 }
773 0 $self->batch_mode_rectify_path(\@path);
774 0 my $out = join('/', map $self->pagepath_url_escape($_), @path)
775 . $HTML_EXTENSION;
776 0 DEBUG > 1 and print STDERR " => $out\n";
777 0 return $out;
778 }
779  
780 0 ▶sub batch_mode_rectify_path {
Subroutine batch_mode_rectify_path: not called CC=2 SCAR=17.9
Pod undocumented
781 0 my($self, $pathbits) = @_;
782 0 my $level = $self->batch_mode_current_level;
783 0 $level--; # how many levels up to go to get to the root
784 0 ▶ if($level < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level < 1) { } 0 0 0
785 0 unshift @$pathbits, '.'; # just to be pretty
786 } else {
787 0 unshift @$pathbits, ('..') x $level;
788 }
789 0 return;
790 }
791  
792 3 ▶sub resolve_man_page_link {
Subroutine resolve_man_page_link: called CC=5 SCAR=17.2
Pod undocumented
793 3 my ($self, $to, $frag) = @_;
794 3 my ($page, $section) = $to =~ /^([^(]+)(?:[(](\d+)[)])?$/;
795  
796 3 ▶ return undef unless defined $page and length $page;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $page and length $page 0 3 3
Condition33%1/3
defined $page and length $page
!ll&&!rl&&r
003
MC/DC0%0/2
defined $page and length $page
defined $page length $page
Truth table33%1/3
A and B
A= defined $pageB= length $page
ABresult
0X0
100
111
797 3 ▶ $section ||= 1;
Condition50%1/2
$section ||= 1
l!l
30
MC/DC0%0/1
$section ||= 1
$section
Truth table50%1/2
A
A= $section
Aresult
11
00
798  
799 3 ▶ return $self->man_url_prefix . "$section/"
Branch: 1 branch
BranchTrueFalseTotal
defined $frag ? : 1 2 3
800 . $self->manpage_url_escape($page) . ".$section"
801 . $self->man_url_postfix
802 . (defined $frag ? '#' . $frag : '');
803 }
804  
805 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
806  
807 17 ▶sub resolve_pod_link_by_table {
Subroutine resolve_pod_link_by_table: called CC=5 SCAR=30.8
Pod undocumented
808 # A crazy hack to allow specifying custom L<foo> => URL mappings
809  
810 17 ▶ return unless $_[0]->{'podhtml_LOT'}; # An optimizy shortcut
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"podhtml_LOT"} 17 0 17
811  
812 0 my($self, $to, $section) = @_;
813  
814 # TODO: add a method that actually populates podhtml_LOT from a file?
815  
816 0 ▶ if(defined $section) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $section) { } 0 0 0
817 0 ▶ $to = '' unless defined $to and length $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to and length $to 0 0 0
Condition0%0/3
defined $to and length $to
!ll&&!rl&&r
000
MC/DC0%0/2
defined $to and length $to
defined $to length $to
Truth table0%0/3
A and B
A= defined $toB= length $to
ABresult
0X0
100
111
818 0 return $self->{'podhtml_LOT'}{"$to#$section"}; # quite possibly undef!
819 } else {
820 0 return $self->{'podhtml_LOT'}{$to}; # quite possibly undef!
821 }
822 0 return;
823 }
824  
825 ###########################################################################
826  
827 37 ▶sub linearize_tokens { # self, tokens
Subroutine linearize_tokens: called CC=14 SCAR=29.3
Pod undocumented
828 37 my $self = shift;
829 37 my $out = '';
830  
831 37 my $t;
832 37 ▶ while($t = shift @_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t = shift @_) 79 37 116
833 79 ▶ if(!ref $t or !UNIVERSAL::can($t, 'is_text')) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $t && UNIVERSAL::can($t, 'is_text')) { } 0 79 79
elsif ($t->is_text) { } 39 40 79
elsif ($t->is_start and $t->tag eq 'X') { } 3 74 77
Condition33%1/3
ref $t && UNIVERSAL::can($t, 'is_text')
!ll&&!rl&&r
0079
MC/DC0%0/2
ref $t && UNIVERSAL::can($t, 'is_text')
ref $t UNIVERSAL::can($t, 'is_text')
Truth table33%1/3
A && B
A= ref $tB= UNIVERSAL::can($t, 'is_text')
ABresult
0X0
100
111
834 0 $out .= $t; # a string, or some insane thing
835 } elsif($t->is_text) {
836 39 $out .= $t->text;
837 ▶ } elsif($t->is_start and $t->tag eq 'X') {
Condition66%2/3
$t->is_start and $t->tag eq "X"
!ll&&!rl&&r
3703
MC/DC50%1/2
$t->is_start and $t->tag eq "X"
$t->is_start $t->tag eq "X"
Truth table66%2/3
A and B
A= $t->is_startB= $t->tag eq "X"
ABresult
0X0
100
111
838 # Ignore until the end of this X<...> sequence:
839 3 my $x_open = 1;
840 3 ▶ while($x_open) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x_open) 6 3 9
841 6 ▶ next if( ($t = shift @_)->is_text );
Branch: 1 branch
BranchTrueFalseTotal
if ($t = shift @_)->is_text 3 3 6
842 0 ▶ if( $t->is_start and $t->tag eq 'X') { ++$x_open }
Branch: 2 branches
BranchTrueFalseTotal
if ($t->is_start and $t->tag eq 'X') { } 0 3 3
elsif ($t->is_end and $t->tag eq 'X') { } 3 0 3
Condition33%1/3
$t->is_start and $t->tag eq "X"
!ll&&!rl&&r
300
MC/DC0%0/2
$t->is_start and $t->tag eq "X"
$t->is_start $t->tag eq "X"
Truth table33%1/3
A and B
A= $t->is_startB= $t->tag eq "X"
ABresult
0X0
100
111
843 3 ▶ elsif($t->is_end and $t->tag eq 'X') { --$x_open }
Condition33%1/3
$t->is_end and $t->tag eq "X"
!ll&&!rl&&r
003
MC/DC0%0/2
$t->is_end and $t->tag eq "X"
$t->is_end $t->tag eq "X"
Truth table33%1/3
A and B
A= $t->is_endB= $t->tag eq "X"
ABresult
0X0
100
111
844 }
845 }
846 }
847 37 ▶ return undef if length $out > $Linearization_Limit;
Branch: 1 branch
BranchTrueFalseTotal
if length $out > $Pod::Simple::HTML::Linearization_Limit 0 37 37
848 37 return $out;
849 }
850  
851 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
852  
853 69 ▶sub unicode_escape_url {
Subroutine unicode_escape_url: called CC=1 SCAR=0.2
Pod undocumented
854 69 my($self, $string) = @_;
855 0 $string =~ s/([^\x00-\xFF])/'('.ord($1).')'/eg;
856 # Turn char 1234 into "(1234)"
857 69 return $string;
858 }
859  
860 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
861 464 ▶sub esc { # a function.
Subroutine esc: called CC=7 SCAR=21.0
Pod undocumented
862 464 ▶ if(defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 326 138 464
863 326 ▶ if(wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 275 51 326
864 275 @_ = splice @_; # break aliasing
865 } else {
866 51 my $x = shift;
867 51 ▶ if ("$]" >= 5.007_003) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$]" >= 5.007003) { } 51 0 51
868 0 $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg;
869 } else { # Is broken for non-ASCII platforms on early perls
870 0 $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg;
871 }
872 51 return $x;
873 }
874 }
875 413 foreach my $x (@_) {
876 # Escape things very cautiously:
877 1101 ▶ if (defined $x) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $x) 1101 0 1101
878 1101 ▶ if ("$]" >= 5.007_003) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$]" >= 5.007003) { } 1101 0 1101
879 1101 $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg
880 } else { # Is broken for non-ASCII platforms on early perls
881 0 $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg
882 }
883 }
884 # Leave out "- so that "--" won't make it thru in X-generated comments
885 # with text in them.
886  
887 # Yes, stipulate the list without a range, so that this can work right on
888 # all charsets that this module happens to run under.
889 }
890 413 return @_;
891 }
892  
893 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
894  
895 7 1;
896 __END__
« Simple/PullParser.pm ↑ Summary Simple/HTMLBatch.pm »