home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / mpod2html < prev    next >
Encoding:
Text File  |  2003-11-26  |  11.2 KB  |  421 lines

  1. #!perl
  2.     eval 'exec D:\Perl\bin\perl.exe -S $0 ${1+"$@"}'
  3.     if $running_under_some_shell;
  4. #!perl -w
  5.  
  6. use strict;
  7. use vars qw($VERSION $TEST_MODE);
  8. $VERSION = 0.2;
  9.  
  10. use Getopt::Long;
  11.  
  12. use Pod::Find qw(pod_find simplify_name);
  13.  
  14. my %opt = ( banner => 1 );
  15.  
  16. # compatibility hack for previous version(s) of pod2html
  17. my %oldopt;
  18.  
  19. die unless(GetOptions(\%opt, qw(
  20.   banner!
  21.   converter=s
  22.   suffix=s
  23.   filesuffix=s
  24.   dir=s
  25.   libpods=s
  26.   navigation!
  27.   localtoc!
  28.   toc!
  29.   idx!
  30.   tocname=s
  31.   idxname=s
  32.   toctitle=s
  33.   idxtitle=s
  34.   idxopt=s
  35.   ps!
  36.   psdir=s
  37.   psfont=s
  38.   papersize=s
  39.   inc!
  40.   script!
  41.   stylesheet=s
  42.   warnings!
  43.   verbose!
  44.   help|h
  45.   version|V),
  46.     'flush' => \$oldopt{flush},
  47.     'htmlroot=s' => \$oldopt{htmlroot}, # can be ignored
  48.     'index!' => \$oldopt{'index'},
  49.     'infile=s' => \$oldopt{infile},
  50.     'netscape!' => \$oldopt{netscape}, # ignore
  51.     'outfile=s' => \$oldopt{outfile},
  52.     'podpath=s' => \$oldopt{podpath}, # can be ignored
  53.     'podroot=s' => \$oldopt{podroot},
  54.     'recurse!' => \$oldopt{recurse}, # ignored now
  55.     'title=s' => \$oldopt{title}
  56. ));
  57.  
  58. my %addopts = ();
  59.  
  60. if($oldopt{infile}) {
  61.   @ARGV = ( $oldopt{infile} );
  62. }
  63.  
  64. if($oldopt{outfile}) {
  65.   $addopts{-outfile} = $oldopt{outfile};
  66. }
  67.  
  68. if($oldopt{podroot}) {
  69.   push(@ARGV, $oldopt{podroot});
  70. }
  71.  
  72. # process libpods
  73. if($opt{libpods}) {
  74.   # replace single : with , (old style)
  75.   $opt{libpods} =~ s/(?<!:):(?!:)/,/g;
  76. }
  77.  
  78. if(defined $oldopt{'index'}) {
  79.   $opt{localtoc} = $oldopt{'index'};
  80. }
  81.  
  82. if(defined $oldopt{title}) {
  83.   $addopts{-title} = $oldopt{title};
  84. }
  85.  
  86. my $converter = $opt{converter} || 'Marek::Pod::HTML';
  87. eval "use $converter qw(pod2html);";
  88. die "Fatal: Cannot load convertor module '$converter':\n$@\n"
  89.     if($@);
  90.  
  91. if($opt{help}) {
  92.   use Config;
  93.   exec "$Config{scriptdir}/perldoc -F $0";
  94. }
  95. elsif($opt{version}) {
  96.     print "$0 Version $VERSION\n";
  97. }
  98. else {
  99.  
  100.     my %pods = ();
  101.     my @dirs = ();
  102.  
  103.     foreach(@ARGV) {
  104.         if(-d) {
  105.             push(@dirs,$_);
  106.         }
  107.         elsif(/[*?]/) {
  108.             foreach (glob($_)) {
  109.                 if(-d) {
  110.                     push(@dirs,$_);
  111.                 }
  112.                 else {
  113.                     my $name = simplify_name($_);
  114.                     $pods{$_} = $name;
  115.                 }
  116.             }
  117.         }
  118.         else {
  119.            my $name = simplify_name($_);
  120.            $pods{$_} = $name;
  121.        }
  122.     }
  123.     my %search;
  124.  
  125.     if(@dirs || $opt{inc} || $opt{script}) {
  126.         warn "+++ Searching for POD documents\n";
  127.         %search = pod_find({
  128.             -inc => $opt{inc},
  129.             -script => $opt{script},
  130.             -verbose => $opt{verbose}
  131.           }, @dirs)
  132.     }
  133.  
  134.     map { $pods{$_} = $search{$_} } keys %search;
  135.  
  136.     # run as a filter
  137.     # we have to save it temporarily because we need two passes
  138.     my $tmp;
  139.     unless(%pods) {
  140.         my $self = $0;
  141.         $self =~ s:^.*/::;
  142.         $tmp = "/tmp/$self.$$";
  143.         open(TEMP, ">$tmp") || die "Cannot write temp file: $!\n";
  144.         while(<STDIN>) {
  145.             print TEMP;
  146.         }
  147.         close(TEMP);
  148.         $pods{$tmp} = 'stdin';
  149.         $addopts{-filter} = 1;
  150.         $opt{navigation} = 0 unless defined $opt{navigation};
  151.     }
  152.  
  153.     warn "+++ Starting conversion\n" if($opt{verbose});
  154.  
  155.     pod2html( {
  156.         -banner => $opt{banner},
  157.         -converter => $converter,
  158.         -suffix => $opt{suffix},
  159.         -filesuffix => $opt{filesuffix},
  160.         -dir => $opt{dir},
  161.         -libpods => $opt{libpods},
  162.         -navigation => $opt{navigation},
  163.         -localtoc => $opt{localtoc},
  164.         -toc => $opt{toc},
  165.         -idx => $opt{idx},
  166.         -tocname => $opt{tocname},
  167.         -idxname => $opt{idxname},
  168.         -toctitle => $opt{toctitle},
  169.         -idxtitle => $opt{idxtitle},
  170.         -ps => $opt{ps},
  171.         -psdir => $opt{psdir},
  172.         -psfont => $opt{psfont},
  173.         -papersize => $opt{papersize},
  174.         -warnings => $opt{warnings},
  175.         -verbose => $opt{verbose},
  176.         -stylesheet => $opt{stylesheet},
  177.         -idxopt => $opt{idxopt},
  178.         %addopts
  179.     }, { %pods });
  180.  
  181.     unlink $tmp if($tmp);
  182. }
  183.  
  184. exit 0 unless($TEST_MODE);
  185. 1; # this is for the module test
  186.  
  187. __END__
  188.  
  189. =head1 NAME
  190.  
  191. pod2html - convert Perl POD documentation to HTML
  192.  
  193. =head1 SYNOPSIS
  194.  
  195. B<pod2html> S<[ B<-converter> I<module> ]>
  196. S<[ B<-suffix> I<suffix> ]> S<[ B<-filesuffix> I<suffix> ]>
  197. S<[ B<-dir> I<path> ]> S<[ B<-libpods> I<pod1,pod2,...> ]>
  198. S<[ B<->(B<no>)B<localtoc> ]> 
  199. S<[ B<->(B<no>)B<navigation> ]> 
  200. S<[ B<->(B<no>)B<toc> ]> S<[ B<-tocname> I<filename> ]>
  201. S<[ B<-toctitle> I<title> ]>
  202. S<[ B<->(B<no>)B<idx> ]> S<[ B<-idxopt> I<options> ]>
  203. S<[ B<-idxname> I<filename> ]>
  204. S<[ B<-idxtitle> I<title> ]>
  205. S<[ B<->(B<no>)B<ps> ]> 
  206. S<[ B<-psdir> I<path> ]> S<[ B<-psfont> I<font> ]>
  207. S<[ B<-papersize> I<format> ]>
  208. S<[ B<->(B<no>)B<inc> ]> 
  209. S<[ B<->(B<no>)B<script> ]> 
  210. S<[ B<->(B<no>)B<warnings> ]> 
  211. S<[ B<->(B<no>)B<verbose> ]> 
  212. S<[ B<->(B<no>)B<banner> ]> 
  213. S<[ B<-stylesheet> I<link> ]>
  214. S<[ I<dir1> , I<dir2> , ... ]>
  215. S<[ I<pod1> , I<pod2> , ... ]>
  216.  
  217. =head1 DESCRIPTION
  218.  
  219. B<mpod2html> converts Perl POD documentation to HTML. This was
  220. originally meant as a replacement for the existing core
  221. C<pod2html>, but has turned out to be a heavy-weight, fancy
  222. HTML converter that needs quite a lot of additional modules.
  223. There are a lot of other Pod to HTML converters out there that
  224. may suit you needs better.
  225.  
  226. See L<SEE ALSO> below for sources of more details.
  227.  
  228. An important note: B<mpod2html> will cross-link I<only>
  229. those documents that are processed in one conversion
  230. session. The benefit is that you will get I<only>
  231. working hyperlinks, no "dead ends". The downside is that
  232. you cannot simply convert one additional Pod and everything
  233. will be nicely crosslinked. Future versions of this module
  234. (or a complete rewrite) may support a caching mechanism 
  235. for the hyperlink destination, such that additional Pods
  236. converted to HTML will have working hyperlinks to the
  237. existing, already converted Pods; but updating all
  238. existing HTML files for links to the newly converted Pod
  239. is rather cumbersome.
  240.  
  241. =head1 OPTIONS
  242.  
  243. =over 4
  244.  
  245. =item B<-converter> I<module>
  246.  
  247. The converter class to use, defaults to C<Marek::Pod::HTML>. This hook allows
  248. for simple customization, see also L<Marek::Pod::HTML/"Customizing">.
  249.  
  250. =item B<-suffix> I<string>
  251.  
  252. Use this string for links to other converted Pod documents. The default
  253. is C<.html> and also sets the filename suffix unless B<-filesuffix> has
  254. been specified. The dot must be included!
  255.  
  256. =item B<-filesuffix> I<string>
  257.  
  258. Use this string as a suffix for the output HTML files. This does not
  259. change the suffix used in the hyperlinks to different documents. This
  260. feature is meant to be used if some (Makefile based) postprocessing
  261. of the generated files has to be performed, but without having to
  262. adapt the links.
  263.  
  264. =item B<-dir> I<path>
  265.  
  266. Write the generated HTML files (can be a directory hierarchy) to this
  267. path. The default is the current working directory.
  268.  
  269. =item B<-libpods> I<name1,name2,...>
  270.  
  271. This option activates a highly magical feature: The C<=item> nodes of
  272. the specified Pod documents (given by Pod name, e.g. C<Pod::Parser>)
  273. serve as destinations for highlighted text in all converted Pod
  274. documents. Typical usage: When converting your Perl installation's
  275. documentation, you may want to say
  276.  
  277.   pod2html -libpods perlfunc,perlvar,perlrun -script -inc
  278.  
  279. then you will get a hyperlink to L<perlvar|perlvar> in the text
  280. C<IE<lt>$|E<gt>>.
  281.  
  282. =item B<-localtoc> | B<-nolocaltoc>
  283.  
  284. This is by default true, so that at the top of the page a local
  285. table of contents with all the C<=head>I<n> lines is generated.
  286.  
  287. =item B<-navigation> | B<-nonavigation>
  288.  
  289. When using the default customization, this flag enables or disables
  290. the navigation in the header of each Pod document (next/previous doc,
  291. table of contents, index).
  292.  
  293. =item B<-toc> | B<-notoc>
  294.  
  295. If true, a table of contents is built from the processed Pod documents.
  296.  
  297. =item B<-tocname> I<name>
  298.  
  299. Use I<name> as the filename of the table of contents. Default is
  300. F<podtoc>. The general file suffix is added to this name.
  301.  
  302. =item B<-toctitle> I<string>
  303.  
  304. The string that is used as the heading of the table of contents.
  305. Default is `Table of Contents'.
  306.  
  307. =item B<-idx> | B<-noidx>
  308.  
  309. If true, an index is built from all processed Pod documents.
  310.  
  311. =item B<-idxopt> I<options>
  312.  
  313. Options for index building. Default is "item,x", which means that
  314. item strings as well as text marked up with C<XE<lt>...E<gt>> 
  315. generate entries in the index.
  316.  
  317. =item B<-idxname> I<name>
  318.  
  319. Use I<name> as the filename of the index. Default is
  320. F<podindex>. The general file suffix is added to this name.
  321.  
  322. =item B<-idxtitle> I<string>
  323.  
  324. The string that is used as the heading of the table of contents.
  325. Default is `Index'.
  326.  
  327. =item B<-ps> | B<-nops>
  328.  
  329. In addition to HTML, generate also Postscript output. The suffix is
  330. F<.ps>. Default is no.
  331.  
  332. =item B<-psdir>
  333.  
  334. The root directory where to write Postscript files. Defaults to the
  335. same as B<-dir>.
  336.  
  337. =item B<-psfont> I<fontname>
  338.  
  339. Generate Postscript files using the font I<fontname>. Default is
  340. `Helvetica'.
  341.  
  342. =item B<-papersize> I<size>
  343.  
  344. Generate Postscript files using the paper size I<size>. Default is
  345. `A4'.
  346.  
  347. =item B<-inc> | B<-noinc>
  348.  
  349. In addition to the files specified on the command line, use
  350. L<Pod::Find> to traverse C<@INC> for all Pod documents. For a
  351. decent Perl installation this will collect a I<huge> number
  352. of files.
  353.  
  354. =item B<-script> | B<-noscript>
  355.  
  356. Similar to B<-inc>, this looks in the Perl installation
  357. executables directory for scripts containing Pod to be
  358. converted. Using this, you will e.g. catch C<perldoc>.
  359.  
  360. =item B<-warnings> | B<-nowarnings>
  361.  
  362. When processing the first pass, print warnings. See L<Pod::Checker>
  363. for more information on warnings. Note: This can produce a lot of
  364. output if the Pod source does not correspond to strict guidelines.
  365.  
  366. =item B<-verbose> | B<-noverbose>
  367.  
  368. Print more status information along the conversion process.
  369.  
  370. =item B<-banner> | B<-nobanner>
  371.  
  372. Generate a banner at the bottom of all converted files (or not).
  373. Default is true.
  374.  
  375. =item B<-stylesheet> I<link>
  376.  
  377. The (optional) link to a style sheet, which is included in the resulting HTML
  378. as
  379.  
  380.   <LINK TYPE="text/css" REL="stylesheet" HREF=$link>
  381.  
  382. =back
  383.  
  384. =head1 ARGUMENTS
  385.  
  386. =over 4
  387.  
  388. =item I<none>
  389.  
  390. If no arguments are specified (and neither B<-inc> nor
  391. B<-script>), then B<mpod2html> acts as a filter, reading
  392. STDIN and writing to STDOUT.
  393.  
  394. =item I<dir1> , I<dir2> , ...
  395.  
  396. Directories specified on the command line will be processed
  397. recursively. This means especially that if there is e.g. 
  398. F<Pod/Checker.pm> in the specified directory, it will be
  399. recognized as C<Pod::Checker> (rather than C<Checker>).
  400.  
  401. =item I<pod1> , I<pod2> , ...
  402.  
  403. A list of files. Note that if you specify F<Mail/Alias.pm>, then
  404. this is I<not> recognized as C<Mail::Alias>, with the consequence
  405. that links in other documents pointing to C<Mail::Alias> will
  406. not be resolved.
  407.  
  408. =back
  409.  
  410. =head1 AUTHOR
  411.  
  412. Marek Rouchal E<lt>marekr@cpan.orgE<gt>
  413.  
  414. =head1 SEE ALSO
  415.  
  416. L<Marek::Pod::HTML>,
  417. L<HTML::Element>, L<Pod::Parser>, L<Pod::Checker>, L<HTML::Entities>
  418.  
  419. =cut
  420.  
  421.