blib/lib/OODoc/Format/Html.pm untested

filter: Statementstmt 0.0% 0 / 507 Branchbran 0.0% 0 / 138 Conditioncond 0.0% 0 / 268 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 51 Podpod 0.0% 0 / 38 totaltotal 0.0% 0 / 1002 SCAR 85.1
CC
70
Cov
0%
templateList
462.0
templateIndex
110.0
showSubroutineUse
90.0
CRAP 4970.0
1 # Copyrights 2003-2021 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of perl distribution OODoc. It is licensed under the
6 # same terms as Perl itself: https://spdx.org/licenses/Artistic-2.0.html
7  
8 package OODoc::Format::Html;
9 use vars '$VERSION';
10 $VERSION = '2.02';
11  
12 use base 'OODoc::Format';
13  
14 use strict;
15 use warnings;
16  
17 use Log::Report 'oodoc';
18 use OODoc::Template ();
19  
20 use IO::File ();
21 use File::Spec ();
22 use File::Find qw/find/;
23 use File::Basename qw/basename dirname/;
24 use File::Copy qw/copy/;
25 use POSIX qw/strftime/;
26 use List::Util qw/first/;
27  
28  
29 sub init($)
30 { my ($self, $args) = @_;
31 $self->SUPER::init($args) or return;
32  
33 my $html = delete $args->{html_root} || '/';
34 $html =~ s! /$ !!x;
35  
36 $self->{OFH_html} = $html;
37 $self->{OFH_jump} = delete $args->{jump_script} || "$html/jump.cgi";
38  
39 my $meta = delete $args->{html_meta_data} || '';
40 if(my $ss = $self->{OFH_style} = delete $args->{html_stylesheet})
41 { my $base = basename $ss;
42 $meta .= qq[<link rel="STYLESHEET" href="/$base">];
43 }
44 $self->{OFH_meta} = $meta;
45 $self;
46 }
47  
48 #-------------------------------------------
49  
50  
51 sub manual(;$) {my $s = shift; @_ ? $s->{OFH_manual}=shift : $s->{OFH_manual}}
52  
53 #-------------------------------------------
54  
55  
56 sub cleanupString($$)
57 { my $self = shift;
58 my $text = $self->cleanup(@_);
59 $text =~ s!</p>\s*<p>!<br>!gs;
60 $text =~ s!\</?p\>!!g;
61 $text;
62 }
63  
64  
65 sub link($$;$)
66 { my ($self, $manual, $object, $text) = @_;
67 $text = $object->name unless defined $text;
68  
69 my $jump;
70 if($object->isa('OODoc::Manual'))
71 { (my $manname = $object->name) =~ s!\:\:!_!g;
72 $jump = "$self->{OFH_html}/$manname/index.html";
73 }
74 else
75 { (my $manname = $manual->name) =~ s!\:\:!_!g;
76 $jump = $self->{OFH_jump}.'?'.$manname.'&'.$object->unique;
77 }
78  
79 qq[<a href="$jump" target="_top">$text</a>];
80 }
81  
82  
83 sub mark($$)
84 { my ($self, $manual, $id) = @_;
85 $manual =~ s/\:\:/_/g;
86 $self->{OFH_markers}->print("$id $manual $self->{OFH_filename}\n");
87 }
88  
89  
90 sub createManual($@)
91 { my ($self, %args) = @_;
92 my $verbose = $args{verbose} || 0;
93 my $manual = $args{manual} or panic;
94 my $options = $args{format_options} || [];
95  
96 # Location for the manual page files.
97  
98 my $template = $args{template} || File::Spec->catdir('html', 'manual');
99 my %template = $self->expandTemplate($template, $options);
100  
101 (my $manfile = "$manual") =~ s!\:\:!_!g;
102 my $dest = File::Spec->catdir($self->workdir, $manfile);
103 $self->mkdirhier($dest);
104  
105 # File to trace markers must be open.
106  
107 unless(defined $self->{OFH_markers})
108 { my $markers = File::Spec->catdir($self->workdir, 'markers');
109 my $mark = IO::File->new($markers, 'w')
110 or fault __x"cannot write markers to {fn}", fn => $markers;
111 $self->{OFH_markers} = $mark;
112 $mark->print($self->{OFH_html}, "\n");
113 }
114  
115 #
116 # Process template
117 #
118  
119 my $manifest = $self->manifest;
120 while(my($raw, $options) = each %template)
121 { my $cooked = File::Spec->catfile($dest, basename $raw);
122  
123 print "$manual: $cooked\n" if $verbose > 2;
124 $manifest->add($cooked);
125  
126 my $output = IO::File->new($cooked, 'w')
127 or fault __x"cannot write html manual to {fn}", fn => $cooked;
128  
129 $self->{OFH_filename} = basename $raw;
130  
131 $self->manual($manual);
132 $self->format
133 ( output => $output
134 , template_fn => $raw
135 , @$options
136 );
137 $self->manual(undef);
138 $output->close;
139 }
140  
141 delete $self->{OFH_filename};
142 $self;
143 }
144  
145  
146 sub createOtherPages(@)
147 { my ($self, %args) = @_;
148  
149 my $verbose = $args{verbose} || 0;
150  
151 #
152 # Collect files to be processed
153 #
154  
155 my $source = $args{source};
156 if(defined $source)
157 { -d $source
158 or fault __x"html source directory {dir}", dir => $source;
159 }
160 else
161 { $source = File::Spec->catdir("html", "other");
162 -d $source or return $self;
163 }
164  
165 my $process = $args{process} || qr/\.(s?html|cgi)$/;
166  
167 my $dest = $self->workdir;
168 $self->mkdirhier($dest);
169  
170 my @sources;
171 find( { no_chdir => 1
172 , wanted => sub { my $fn = $File::Find::name;
173 push @sources, $fn if -f $fn;
174 }
175 }, $source
176 );
177  
178 #
179 # Process files, one after the other
180 #
181  
182 my $manifest = $self->manifest;
183 foreach my $raw (@sources)
184 { (my $cooked = $raw) =~ s/\Q$source\E/$dest/;
185  
186 print "create $cooked\n" if $verbose > 2;
187 $manifest->add($cooked);
188  
189 if($raw =~ $process)
190 { $self->mkdirhier(dirname $cooked);
191 my $output = IO::File->new($cooked, 'w')
192 or fault __x"cannot write html to {fn}", fn => $cooked;
193  
194 my $options = [];
195 $self->format
196 ( manual => undef
197 , output => $output
198 , template_fn => $raw
199 , @$options
200 );
201 $output->close;
202 }
203 else
204 { copy($raw, $cooked)
205 or fault __x"copy from {from} to {to} failed"
206 , from => $raw, to => $cooked;
207 }
208  
209 my $rawmode = (stat $raw)[2] & 07777;
210 chmod $rawmode, $cooked
211 or fault __x"chmod of {fn} to {mode%o} failed"
212 , fn => $cooked, mode => $rawmode;
213 }
214  
215 $self;
216 }
217  
218  
219 sub expandTemplate($$)
220 { my $self = shift;
221 my $loc = shift || panic;
222 my $defaults = shift || [];
223  
224 my @result;
225 if(ref $loc eq 'HASH')
226 { foreach my $n (keys %$loc)
227 { my %options = (@$defaults, @{$loc->{$n}});
228 push @result, $self->expandTemplate($n, [ %options ])
229 }
230 }
231 elsif(-d $loc)
232 { find( { no_chdir => 1,
233 wanted => sub { my $fn = $File::Find::name;
234 push @result, $fn, $defaults
235 if -f $fn;
236 }
237 }, $loc
238 );
239 }
240 elsif(-f $loc) { push @result, $loc => $defaults }
241 else { error __x"cannot find template source '{name}'", name => $loc }
242  
243 @result;
244 }
245  
246 sub showStructureExpand(@)
247 { my ($self, %args) = @_;
248  
249 my $examples = $args{show_chapter_examples} || 'EXPAND';
250 my $text = $args{structure} or panic;
251  
252 my $name = $text->name;
253 my $level = $text->level +1; # header level, chapter = H2
254 my $output = $args{output} or panic;
255 my $manual = $args{manual} or panic;
256  
257 # Produce own chapter description
258  
259 my $descr = $self->cleanup($manual, $text->description);
260 my $unique = $text->unique;
261 (my $id = $name) =~ s/\W+/_/g;
262  
263 $output->print(
264 qq[\n<h$level id="$id"><a name="$unique">$name</a></h$level>\n$descr]
265 );
266  
267 $self->mark($manual, $unique);
268  
269 # Link to inherited documentation.
270  
271 my $super = $text;
272 while($super = $super->extends)
273 { last if $super->description !~ m/^\s*$/;
274 }
275  
276 if(defined $super)
277 { my $superman = $super->manual; # :-)
278 $output->print( "<p>See ", $self->link($superman, $super), " in "
279 , $self->link(undef, $superman), "</p>\n");
280 }
281  
282 # Show the subroutines and examples.
283  
284 $self->showSubroutines(%args, subroutines => [$text->subroutines]);
285 $self->showExamples(%args, examples => [$text->examples])
286 if $examples eq 'EXPAND';
287  
288 $self;
289 }
290  
291 sub showStructureRefer(@)
292 { my ($self, %args) = @_;
293  
294 my $text = $args{structure} or panic;
295 my $name = $text->name;
296 my $level = $text->level;
297  
298 my $output = $args{output} or panic;
299 my $manual = $args{manual} or panic;
300  
301 my $link = $self->link($manual, $text);
302 $output->print(
303 qq[\n<h$level id="$name"><a href="$link">$name</a><h$level>\n]);
304 $self;
305 }
306  
307 sub chapterDiagnostics(@)
308 { my ($self, %args) = @_;
309  
310 my $manual = $args{manual} or panic;
311 my $diags = $manual->chapter('DIAGNOSTICS');
312  
313 my @diags = map {$_->diagnostics} $manual->subroutines;
314 $diags = OODoc::Text::Chapter->new(name => 'DIAGNOSTICS')
315 if !$diags && @diags;
316  
317 return unless $diags;
318  
319 $self->showChapter(chapter => $diags, %args)
320 if defined $diags;
321  
322 $self->showDiagnostics(%args, diagnostics => \@diags);
323 $self;
324 }
325  
326 sub showExamples(@)
327 { my ($self, %args) = @_;
328 my $examples = $args{examples} or panic;
329 return unless @$examples;
330  
331 my $manual = $args{manual} or panic;
332 my $output = $args{output} or panic;
333  
334 $output->print( qq[<dl class="example">\n] );
335  
336 foreach my $example (@$examples)
337 { my $name = $example->name;
338 my $descr = $self->cleanup($manual, $example->description);
339 my $unique = $example->unique;
340 $output->print( <<EXAMPLE );
341 <dt>&raquo;&nbsp;<a name="$unique">Example</a>: $name</dt>
342 <dd>$descr</dd>
343 EXAMPLE
344  
345 $self->mark($manual, $unique);
346 }
347 $output->print( qq[</dl>\n] );
348  
349 $self;
350 }
351  
352 sub showDiagnostics(@)
353 { my ($self, %args) = @_;
354 my $diagnostics = $args{diagnostics} or panic;
355 return unless @$diagnostics;
356  
357 my $manual = $args{manual} or panic;
358 my $output = $args{output} or panic;
359  
360 $output->print( qq[<dl class="diagnostics">\n] );
361  
362 foreach my $diag (sort @$diagnostics)
363 { my $name = $diag->name;
364 my $type = $diag->type;
365 my $text = $self->cleanup($manual, $diag->description);
366 my $unique = $diag->unique;
367  
368 $output->print( <<DIAG );
369 <dt class="type">&raquo;&nbsp;$type: <a name="$unique">$name</a></dt>
370 <dd>$text</dd>
371 DIAG
372  
373 $self->mark($manual, $unique);
374 }
375  
376 $output->print( qq[</dl>\n] );
377 $self;
378 }
379  
380 sub showSubroutine(@)
381 { my $self = shift;
382 my %args = @_;
383 my $output = $args{output} or panic;
384 my $sub = $args{subroutine} or panic;
385 my $type = $sub->type;
386 my $name = $sub->name;
387  
388 $self->SUPER::showSubroutine(@_);
389  
390 $output->print( qq[</dd>\n</dl>\n</div>\n] );
391 $self;
392 }
393  
394 sub showSubroutineUse(@)
395 { my ($self, %args) = @_;
396 my $subroutine = $args{subroutine} or panic;
397 my $manual = $args{manual} or panic;
398 my $output = $args{output} or panic;
399  
400 my $type = $subroutine->type;
401 my $name = $self->cleanupString($manual, $subroutine->name);
402 my $paramlist = $self->cleanupString($manual, $subroutine->parameters);
403 my $unique = $subroutine->unique;
404  
405 my $class = $manual->package;
406  
407 my $call = qq[<b><a name="$unique">$name</a></b>];
408 $call .= "(&nbsp;$paramlist&nbsp;)" if length $paramlist;
409 $self->mark($manual, $unique);
410  
411 my $use
412 = $type eq 'i_method' ? qq[\$obj-&gt;$call]
413 : $type eq 'c_method' ? qq[\$class-&gt;$call]
414 : $type eq 'ci_method'? qq[\$obj-&gt;$call<br>\$class-&gt;$call]
415 : $type eq 'overload' ? qq[overload: $call]
416 : $type eq 'function' ? qq[$call]
417 : $type eq 'tie' ? $call
418 : warning("unknown subroutine type {type} for {name} in {manual}"
419 , type => $type, name => $name, manual => $manual);
420  
421 $output->print( <<SUBROUTINE );
422 <div class="$type" id="$name">
423 <dl>
424 <dt class="sub_use">$use</dt>
425 <dd class="sub_body">
426 SUBROUTINE
427  
428 if($manual->inherited($subroutine))
429 { my $defd = $subroutine->manual;
430 my $sublink = $self->link($defd, $subroutine, $name);
431 my $manlink = $self->link($manual, $defd);
432 $output->print( qq[See $sublink in $manlink.<br>\n] );
433 }
434 $self;
435 }
436  
437 sub showSubsIndex(@)
438 { my ($self, %args) = @_;
439 my $output = $args{output} or panic;
440 }
441  
442 sub showSubroutineName(@)
443 { my ($self, %args) = @_;
444 my $subroutine = $args{subroutine} or panic;
445 my $manual = $args{manual} or panic;
446 my $output = $args{output} or panic;
447 my $name = $subroutine->name;
448  
449 my $url
450 = $manual->inherited($subroutine)
451 ? "M<".$subroutine->manual."::$name>"
452 : "M<$name>";
453  
454 $output->print
455 ( $self->cleanupString($manual, $url)
456 , ($args{last} ? ".\n" : ",\n")
457 );
458 }
459  
460 sub showOptions(@)
461 { my $self = shift;
462 my %args = @_;
463 my $output = $args{output} or panic;
464 $output->print( qq[<dl class="options">\n] );
465  
466 $self->SUPER::showOptions(@_);
467  
468 $output->print( qq[</dl>\n] );
469 $self;
470 }
471  
472 sub showOptionUse(@)
473 { my ($self, %args) = @_;
474 my $output = $args{output} or panic;
475 my $option = $args{option} or panic;
476 my $manual = $args{manual} or panic;
477  
478 my $params = $self->cleanupString($manual, $option->parameters);
479 $params =~ s/\s+$//;
480 $params =~ s/^\s+//;
481 $params = qq[ =&gt; <span class="params">$params</span>]
482 if length $params;
483  
484 my $use = qq[<span class="option">$option</span>];
485 $output->print( qq[<dt class="option_use">$use$params</dt>\n] );
486 $self;
487 }
488  
489 sub showOptionExpand(@)
490 { my ($self, %args) = @_;
491 my $output = $args{output} or panic;
492 my $option = $args{option} or panic;
493 my $manual = $args{manual} or panic;
494  
495 $self->showOptionUse(%args);
496  
497 my $where = $option->findDescriptionObject or return $self;
498 my $descr = $self->cleanupString($manual, $where->description);
499  
500 $output->print( qq[<dd>$descr</dd>\n] )
501 if length $descr;
502  
503 $self;
504 }
505  
506  
507 sub writeTable($@)
508 { my ($self, %args) = @_;
509  
510 my $rows = $args{rows} or panic;
511 return unless @$rows;
512  
513 my $head = $args{header} or panic;
514 my $output = $args{output} or panic;
515  
516 $output->print( qq[<table cellspacing="0" cellpadding="2" border="1">\n] );
517  
518 local $" = qq[</th> <th align="left">];
519 $output->print( qq[<tr><th align="left">@$head</th></tr>\n] );
520  
521 local $" = qq[</td> <td valign="top">];
522 $output->print( qq[<tr><td align="left">@$_</td></tr>\n] )
523 foreach @$rows;
524  
525 $output->print( qq[</table>\n] );
526 $self;
527 }
528  
529 sub showSubroutineDescription(@)
530 { my ($self, %args) = @_;
531 my $manual = $args{manual} or panic;
532 my $subroutine = $args{subroutine} or panic;
533  
534 my $text = $self->cleanup($manual, $subroutine->description);
535 return $self unless length $text;
536  
537 my $output = $args{output} or panic;
538 $output->print($text);
539  
540 my $extends = $self->extends or return $self;
541 my $refer = $extends->findDescriptionObject or return $self;
542  
543 $output->print("<br>\n");
544 $self->showSubroutineDescriptionRefer(%args, subroutine => $refer);
545 }
546  
547 sub showSubroutineDescriptionRefer(@)
548 { my ($self, %args) = @_;
549 my $manual = $args{manual} or panic;
550 my $subroutine = $args{subroutine} or panic;
551 my $output = $args{output} or panic;
552 $output->print("\nSee ", $self->link($manual, $subroutine), "\n");
553 }
554  
555 #----------------------
556  
557  
558 our %producers =
559 ( a => 'templateHref'
560 , chapter => 'templateChapter'
561 , date => 'templateDate'
562 , index => 'templateIndex'
563 , inheritance => 'templateInheritance'
564 , list => 'templateList'
565 , manual => 'templateManual'
566 , meta => 'templateMeta'
567 , distribution=> 'templateDistribution'
568 , name => 'templateName'
569 , project => 'templateProject'
570 , title => 'templateTitle'
571 , version => 'templateVersion'
572 );
573  
574 sub format(@)
575 { my ($self, %args) = @_;
576 my $output = delete $args{output};
577  
578 my %permitted = %args;
579 my $template = OODoc::Template->new;
580 while(my ($tag, $method) = each %producers)
581 { $permitted{$tag} = sub
582 { # my ($istag, $attrs, $ifblock, $elseblock) = @_;
583 shift;
584 $self->$method($template, @_)
585 };
586 }
587  
588 $output->print(
589 scalar $template->processFile($args{template_fn}, \%permitted));
590 }
591  
592  
593 sub templateProject($$)
594 { my ($self, $templ, $attrs, $if, $else) = @_;
595 $self->project;
596 }
597  
598  
599 sub templateTitle($$)
600 { my ($self, $templ, $attrs, $if, $else) = @_;
601  
602 my $manual = $self->manual
603 or error __x"not a manual, so no automatic title in {fn}"
604 , fn => scalar $templ->valueFor('template_fn');
605  
606 my $name = $self->cleanupString($manual, $manual->name);
607 $name =~ s/\<[^>]*\>//g;
608 $name;
609 }
610  
611  
612 sub templateManual($$)
613 { my ($self, $templ, $attrs, $if, $else) = @_;
614  
615 my $manual = $self->manual
616 or error __x"not a manual, so no manual name for {fn}"
617 , fn => scalar $templ->valueFor('template_fn');
618  
619 $self->cleanupString($manual, $manual->name);
620 }
621  
622  
623 sub templateDistribution($$)
624 { my ($self, $templ, $attrs, $if, $else) = @_;
625 my $manual = $self->manual;
626 defined $manual ? $manual->distribution : '';
627 }
628  
629  
630 sub templateVersion($$)
631 { my ($self, $templ, $attrs, $if, $else) = @_;
632 my $manual = $self->manual;
633 defined $manual ? $manual->version : $self->version;
634 }
635  
636  
637 sub templateDate($$)
638 { my ($self, $templ, $attrs, $if, $else) = @_;
639 strftime "%Y/%m/%d", localtime;
640 }
641  
642  
643 sub templateName($$)
644 { my ($self, $templ, $attrs, $if, $else) = @_;
645  
646 my $manual = $self->manual
647 or error __x"not a manual, so no name for {fn}"
648 , fn => scalar $templ->valueFor('template_fn');
649  
650 my $chapter = $manual->chapter('NAME')
651 or error __x"cannot find chapter NAME in manual {fn}", $manual->source;
652  
653 my $descr = $chapter->description;
654  
655 return $1 if $descr =~ m/^ \s*\S+\s*\-\s*(.*?)\s* $ /x;
656  
657 error __x"chapter NAME in manual {manual} has illegal shape"
658 , manual => $manual;
659 }
660  
661  
662 our %path_lookup =
663 ( front => "/index.html"
664 , manuals => "/manuals/index.html"
665 , methods => "/methods/index.html"
666 , diagnostics => "/diagnostics/index.html"
667 , details => "/details/index.html"
668 );
669  
670 sub templateHref($$)
671 { my ($self, $templ, $attrs, $if, $else) = @_;
672 my $window = delete $attrs->{window} || '_top';
673 keys %$attrs==1
674 or error __x"expect one name with 'a'";
675 (my $to) = keys %$attrs;
676  
677 my $path = $path_lookup{$to}
678 or error __x"missing path for {dest}", dest => $to;
679  
680 qq[<a href="$self->{OFH_html}$path" target="$window">];
681 }
682  
683  
684 sub templateMeta($$)
685 { my ($self, $templ, $attrs, $if, $else) = @_;
686 $self->{OFH_meta};
687 }
688  
689  
690 sub templateInheritance(@)
691 { my ($self, $templ, $attrs, $if, $else) = @_;
692  
693 my $manual = $self->manual;
694 my $chapter = $manual->chapter('INHERITANCE')
695 or return '';
696  
697 my $buffer = '';
698 open my $out, '>', \$buffer;
699 $self->showChapter
700 ( %$attrs
701 , manual => $self->manual
702 , chapter => $chapter
703 , output => $out
704 );
705 close $out;
706  
707 for($buffer)
708 { s#\<pre\>\s*(.*?)\</pre\>\n*#\n$1#gs; # over-eager cleanup
709 s#^( +)#'&nbsp;' x length($1)#gme;
710 s# $ #<br>#gmx;
711 s#(\</h\d\>)(\<br\>\n?)+#$1\n#;
712 }
713  
714 $buffer;
715 }
716  
717  
718 sub templateChapter($$)
719 { my ($self, $templ, $attrs, $if, $else) = @_;
720 warning __x"no meaning for container {c} in chapter block", c => $if
721 if defined $if && length $if;
722  
723 my $name = first { !/[a-z]/ } keys %$attrs;
724 defined $name
725 or error __x"chapter without name in template {fn}"
726 , fn => scalar $templ->valueFor('template_fn');
727  
728 my $manual = $self->manual;
729 defined $manual or panic;
730 my $chapter = $manual->chapter($name) or return '';
731  
732 my $buffer = '';
733 open my $out, '>', \$buffer;
734 $self->showChapter
735 ( %$attrs
736 , manual => $self->manual
737 , chapter => $chapter
738 , output => $out
739 );
740 close $out;
741  
742 $buffer;
743 }
744  
745  
746 sub templateIndex($$)
747 { my ($self, $templ, $attrs, $if, $else) = @_;
748  
749 warning __x"no meaning for container {c} in list block", c => $if
750 if defined $if && length $if;
751  
752 my $group = first { !/[a-z]/ } keys %$attrs;
753 defined $group
754 or error __x"no group named as attribute for list";
755  
756 my $start = $attrs->{starting_with} || 'ALL';
757 my $types = $attrs->{type} || 'ALL';
758  
759 my $select = sub { @_ };
760 unless($start eq 'ALL')
761 { $start =~ s/_/[\\W_]/g;
762 my $regexp = qr/^$start/i;
763 $select = sub { grep $_->name =~ $regexp, @_ };
764 }
765 unless($types eq 'ALL')
766 { my @take = map { $_ eq 'method' ? '.*method' : $_ }
767 split /[_|]/, $types;
768 local $" = ')|(';
769 my $regexp = qr/^(@take)$/i;
770 my $before = $select;
771 $select = sub { grep $_->type =~ $regexp, $before->(@_) };
772 }
773  
774 my $columns = $attrs->{table_columns} || 2;
775 my @rows;
776  
777 if($group eq 'SUBROUTINES')
778 { my @subs;
779  
780 foreach my $manual ($self->manuals)
781 { foreach my $sub ($select->($manual->ownSubroutines))
782 { my $linksub = $self->link($manual, $sub, $sub->name);
783 my $linkman = $self->link(undef, $manual, $manual->name);
784 my $link = "$linksub -- $linkman";
785 push @subs, [ lc("$sub-$manual"), $link ];
786 }
787 }
788  
789 @rows = map { $_->[1] }
790 sort { $a->[0] cmp $b->[0] } @subs;
791 }
792 elsif($group eq 'DIAGNOSTICS')
793 { foreach my $manual ($self->manuals)
794 { foreach my $sub ($manual->ownSubroutines)
795 { my @diags = $select->($sub->diagnostics) or next;
796  
797 my $linksub = $self->link($manual, $sub, $sub->name);
798 my $linkman = $self->link(undef, $manual, $manual->name);
799  
800 foreach my $diag (@diags)
801 { my $type = uc($diag->type);
802 push @rows, <<"DIAG";
803 $type: $diag<br>
804 &middot;&nbsp;$linksub in $linkman<br>
805 DIAG
806 }
807 }
808 }
809  
810 @rows = sort @rows;
811 }
812 elsif($group eq 'DETAILS')
813 { foreach my $manual (sort $select->($self->manuals))
814 { my $details = $manual->chapter("DETAILS") or next;
815 my @sections;
816 foreach my $section ($details->sections)
817 { my @subsect = grep !$manual->inherited($_) && $_->description
818 , $section->subsections;
819 push @sections, $section
820 if @subsect || $section->description;
821 }
822  
823 @sections || length $details->description
824 or next;
825  
826 my $sections = join "\n"
827 , map { "<li>".$self->link($manual, $_)."</li>" }
828 @sections;
829  
830 push @rows, $self->link($manual, $details, "Details in $manual")
831 . qq[\n<ul>\n$sections</ul>\n]
832 }
833 }
834 elsif($group eq 'MANUALS')
835 { @rows = map $self->link(undef, $_, $_->name)
836 , sort $select->($self->manuals);
837 }
838 else
839 { error __x"unknown group {name} as list attribute", name => $group;
840 }
841  
842 push @rows, ('') x ($columns-1);
843 my $rows = int(@rows/$columns);
844  
845 my $output = qq[<tr>];
846 while(@rows >= $columns)
847 { $output .= qq[<td valign="top">]
848 . join( "<br>\n", splice(@rows, 0, $rows))
849 . qq[</td>\n];
850 }
851 $output .= qq[</tr>\n];
852 $output;
853 }
854  
855  
856 sub templateList($$)
857 { my ($self, $templ, $attrs, $if, $else) = @_;
858 warning __x"no meaning for container {c} in index block", c => $if
859 if defined $if && length $if;
860  
861 my $group = first { !/[a-z]/ } keys %$attrs;
862 defined $group
863 or error __x"no group named as attribute for list";
864  
865 my $show_sub = $attrs->{show_subroutines} || 'LIST';
866 my $types = $attrs->{subroutine_types} || 'ALL';
867 my $manual = $self->manual or panic;
868 my $output = '';
869  
870 my $selected = sub { @_ };
871 unless($types eq 'ALL')
872 { my @take = map { $_ eq 'method' ? '.*method' : $_ }
873 split /[_|]/, $types;
874 local $" = ')|(?:';
875 my $regexp = qr/^(?:@take)$/;
876 $selected = sub { grep $_->type =~ $regexp, @_ };
877 }
878  
879 my $sorted = sub { sort {$a->name cmp $b->name} @_ };
880  
881 if($group eq 'ALL')
882 { my @subs = $sorted->($selected->($manual->subroutines));
883 if(!@subs || $show_sub eq 'NO') { ; }
884 elsif($show_sub eq 'COUNT') { $output .= @subs }
885 else
886 { $output .= $self->indexListSubroutines($manual,@subs);
887 }
888 }
889 else # any chapter
890 { my $chapter = $manual->chapter($group) or return '';
891 my $show_sec = $attrs->{show_sections} || 'LINK';
892 my @sections = $show_sec eq 'NO' ? () : $chapter->sections;
893  
894 my @subs = $sorted->($selected->( @sections
895 ? $chapter->subroutines
896 : $chapter->all('subroutines')
897 )
898 );
899  
900 $output .= $self->link($manual, $chapter, $chapter->niceName);
901 my $count = @subs && $show_sub eq 'COUNT' ? ' ('.@subs.')' : '';
902  
903 if($show_sec eq 'NO') { $output .= qq[$count<br>\n] }
904 elsif($show_sec eq 'LINK' || $show_sec eq 'NAME')
905 { $output .= qq[<br>\n<ul>\n];
906 if(!@subs) {;}
907 elsif($show_sec eq 'LINK')
908 { my $link = $self->link($manual, $chapter, 'unsorted');
909 $output .= qq[<li>$link$count\n];
910 }
911 elsif($show_sec eq 'NAME')
912 { $output .= qq[<li>];
913 }
914  
915 $output .= $self->indexListSubroutines($manual,@subs)
916 if @subs && $show_sub eq 'LIST';
917 }
918 else
919 { error __x"illegal value to show_sections: {v}", v => $show_sec;
920 }
921  
922 # All sections within the chapter (if show_sec is enabled)
923  
924 foreach my $section (@sections)
925 { my @subs = $sorted->($selected->($section->all('subroutines')));
926  
927 my $count = ! @subs ? ''
928 : $show_sub eq 'COUNT' ? ' ('.@subs.')'
929 : ': ';
930  
931 if($show_sec eq 'LINK')
932 { my $link = $self->link($manual, $section, $section->niceName);
933 $output .= qq[<li>$link$count\n];
934 }
935 else
936 { $output .= qq[<li>$section$count\n];
937 }
938  
939 $output .= $self->indexListSubroutines($manual,@subs)
940 if $show_sub eq 'LIST' && @subs;
941  
942 $output .= qq[</li>\n];
943 }
944  
945 $output .= qq[</ul>\n]
946 if $show_sec eq 'LINK' || $show_sec eq 'NAME';
947 }
948  
949 $output;
950 }
951  
952 sub indexListSubroutines(@)
953 { my $self = shift;
954 my $manual = shift;
955  
956 join ",\n"
957 , map { $self->link($manual, $_, $_) }
958 @_;
959 }
960  
961 #-------------------------------------------
962  
963  
964 1;