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