Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

313 lines
7.2 KiB

  1. package ActivePerl::DocTools::TOC;
  2. use strict;
  3. use warnings;
  4. use File::Basename;
  5. use File::Find;
  6. use Config;
  7. use Symbol;
  8. # get a default value for $dirbase ... can be overridden?
  9. our $dirbase;
  10. if (exists $Config{installhtmldir}) {
  11. $dirbase = $Config{installhtmldir};
  12. }
  13. else {
  14. $dirbase = "$Config{installprefix}/html";
  15. }
  16. my @corePodz = qw(
  17. perl perlfaq perltoc perlbook
  18. __
  19. perlsyn perldata perlop perlsub perlfunc perlreftut perldsc perlrequick perlpod perlstyle perltrap
  20. __
  21. perlrun perldiag perllexwarn perldebtut perldebug
  22. __
  23. perlvar perllol perlopentut perlretut
  24. __
  25. perlre perlref
  26. __
  27. perlform
  28. __
  29. perlboot perltoot perltootc perlobj perlbot perltie
  30. __
  31. perlipc perlfork perlnumber perlthrtut
  32. __
  33. perlport perllocale perlunicode perlebcdic
  34. __
  35. perlsec
  36. __
  37. perlmod perlmodlib perlmodinstall perlnewmod
  38. __
  39. perlfaq1 perlfaq2 perlfaq3 perlfaq4 perlfaq5 perlfaq6 perlfaq7 perlfaq8 perlfaq9
  40. __
  41. perlcompile
  42. __
  43. perlembed perldebguts perlxstut perlxs perlclib perlguts perlcall perlutil perlfilter perldbmfilter perlapi perlintern perlapio perltodo perlhack
  44. __
  45. perlhist perldelta perl5005delta perl5004delta
  46. __
  47. perlaix perlamiga perlbs2000 perlcygwin perldos perlepoc perlhpux perlmachten perlmacos perlmpeix perlos2 perlos390 perlsolaris perlvmesa perlvms perlvos perlwin32
  48. );
  49. # LIST OF METHODS TO OVERRIDE IN YOUR SUBCLASS
  50. {
  51. no strict "refs"; # trust me, I know what I'm doing
  52. for my $abstract_method (qw/
  53. header
  54. before_pods pod_separator pod after_pods
  55. before_pragmas pragma after_pragmas
  56. before_libraries library library_indent_open library_indent_close library_indent_same library_container after_libraries
  57. footer/) {
  58. *$abstract_method = sub { die "The subroutine $abstract_method() must be overriden by the child class!" };
  59. };
  60. }
  61. sub new {
  62. my ($invocant, $options) = @_;
  63. my $class = ref($invocant) || $invocant; # object or class name.
  64. my $self;
  65. if (ref($options) eq 'HASH') {
  66. $self = $options;
  67. } else {
  68. $self = {};
  69. }
  70. _BuildHashes($self);
  71. bless ($self, $class);
  72. return $self;
  73. }
  74. # generic structure for the website, HTML help, RDF
  75. sub TOC {
  76. # warn "entered Write";
  77. my ($self) = @_;
  78. my $verbose = $self->{'verbose'};
  79. my $output;
  80. my %filez = %{$self->{'filez'}};
  81. my %pragmaz = %{$self->{'pragmaz'}};
  82. my %podz = %{$self->{'podz'}};
  83. # generic header stuff
  84. $output .= $self->boilerplate();
  85. $output .= $self->header();
  86. # core pods
  87. my %unused_podz = %podz;
  88. $output .= $self->before_pods();
  89. foreach my $file (@corePodz) {
  90. if ($file eq '__') {
  91. $output .= $self->pod_separator();
  92. } elsif ($podz{"Pod::$file"}) {
  93. $output .= $self->pod($file);
  94. delete $unused_podz{"Pod::$file"};
  95. } else {
  96. warn "Couldn't find pod for $file" if $verbose;
  97. }
  98. }
  99. foreach my $file (sort keys %unused_podz) {
  100. warn "Unused Pod: $file" if $verbose;
  101. }
  102. $output .= $self->after_pods();
  103. # pragmas (or pragmata to the pedantic :)
  104. $output .= $self->before_pragmas();
  105. foreach my $file (sort keys %pragmaz) {
  106. $output .= $self->pragma($file)
  107. }
  108. $output .= $self->after_pragmas();
  109. # libraries
  110. $output .= $self->before_libraries();
  111. my $depth=0;
  112. foreach my $file (sort {uc($a) cmp uc($b)} keys %filez) {
  113. my $showfile=$file;
  114. my $file_depth=0;
  115. my $depthflag=0;
  116. # cuts $showfile down to its last part, i.e. Foo::Baz::Bar --> Bar
  117. # and counts the number of times, to get indent. --> 2
  118. while ($showfile =~ s/.*?::(.*)/$1/) { $file_depth++ }
  119. # if the current file's depth is further out or in than last time,
  120. # add opening or closing tags.
  121. while ($file_depth != $depth) {
  122. if ($file_depth > $depth) {
  123. $output .= $self->library_indent_open();
  124. $depth++;
  125. $depthflag=1;
  126. }
  127. elsif ($file_depth < $depth) {
  128. $output .= $self->library_indent_close();
  129. $depth--;
  130. $depthflag=1;
  131. }
  132. }
  133. unless ($depthflag) {
  134. $output .= $self->library_indent_same();
  135. }
  136. if ($filez{$file}) {
  137. $output .= $self->library($file, $showfile, $depth);
  138. } else {
  139. # assume this is a containing item like a folder or something
  140. $output .= $self->library_container($file, $showfile, $depth);
  141. }
  142. }
  143. $output .= $self->after_libraries();
  144. $output .= $self->footer();
  145. return $output;
  146. }
  147. sub _BuildHashes {
  148. my ($self) = shift;
  149. my $verbose = $self->{'verbose'};
  150. unless (-d $dirbase) {
  151. die "htmldir not found at: $dirbase";
  152. }
  153. #warn "entered buildhashes";
  154. my @checkdirs = qw(lib site/lib);
  155. my (%filez, %pragmaz, %podz);
  156. my $Process = sub {
  157. return if -d;
  158. my $parsefile = $_;
  159. my ($filename,$dir,$suffix) = fileparse($parsefile,'\.html');
  160. if ($suffix !~ m#\.html#) { return; }
  161. my $TOCdir = $dir;
  162. $filename =~ s/(.*)\..*/$1/;
  163. # print "$TOCdir";
  164. $TOCdir =~ s#.*?lib/(.*)$#$1#;
  165. $TOCdir =~ s#/#::#g;
  166. # print " changed to: $TOCdir\n";
  167. $dir =~ s#.*?/((site/)?lib.*)/$#$1#; #looks ugly to get around warning
  168. if ($filez{"$TOCdir/$filename.html"}) {
  169. warn "$parsefile: REPEATED!\n";
  170. }
  171. $filez{"$TOCdir$filename"} = "$dir/$filename.html";
  172. # print "adding $parsefile as " . $filez{"$TOCdir/$filename.html"} . "\n";
  173. # print "\%filez{$TOCdir$filename.html}: " . $filez{"$TOCdir$filename.html"} . "\n";
  174. return 1;
  175. };
  176. foreach my $dir (@checkdirs) {
  177. find ( { wanted => $Process, no_chdir => 1 }, "$dirbase/$dir")
  178. if -d "$dirbase/$dir";
  179. }
  180. foreach my $file (keys %filez) {
  181. if ($file =~ /^[a-z]/) { # pragmas in perl are denoted by all lowercase...
  182. if ($file ne 'perlfilter' and $file ne 'lwpcook') { # ... except these. sigh. Yes, Dave, it's their fault, but we ought to fix it anyway.
  183. $pragmaz{$file} = $filez{$file};
  184. delete $filez{$file};
  185. }
  186. } elsif ($file =~ /^Pod::perl/) {
  187. $podz{$file} = $filez{$file};
  188. delete $filez{$file};
  189. } elsif ($file eq 'Pod::PerlEz') {
  190. #this should be part of ActivePerl dox
  191. delete $filez{$file};
  192. }
  193. }
  194. foreach my $file (sort {uc($b) cmp uc($a)} keys %filez) {
  195. my $prefix = $file;
  196. if (! ($prefix =~ s/(.*)?::(.*)/$1/)) {
  197. warn "$prefix from $file\n" if $verbose;
  198. } else {
  199. if (! defined ($filez{$prefix})) {
  200. $filez{$prefix} = '';
  201. warn "Added topic: $prefix\n" if $verbose;
  202. }
  203. warn " $prefix from $file\n" if $verbose;
  204. }
  205. }
  206. $self->{'filez'} = \%filez;
  207. $self->{'podz'} = \%podz;
  208. $self->{'pragmaz'} = \%pragmaz;
  209. }
  210. sub text {
  211. my ($text) = join '', map { "$_\n" } @_;
  212. return sub { $text };
  213. }
  214. 1;
  215. __END__
  216. =head1 NAME
  217. ActivePerl::DocTools::TOC- base class for generating Perl documentation TOC
  218. =head1 SYNOPSIS
  219. use base ('ActivePerl::DocTools::TOC');
  220. # override lots of methods here... see source for which ones
  221. =head1 DESCRIPTION
  222. Base class for generating TOC's from Perl html docs.
  223. =head2 EXPORTS
  224. $dirbase - where the html files are
  225. =head1 AUTHOR
  226. David Sparks, DaveS@ActiveState.com
  227. Neil Kandalgaonkar, NeilK@ActiveState.com
  228. =head1 SEE ALSO
  229. The amazing L<PPM>.
  230. L<ActivePerl::DocTools::TOC::HTML>
  231. L<ActivePerl::DocTools::TOC::RDF>
  232. =cut