#!/usr/local/bin/perl5.00401

use strict;
use Getopt::Long;
use File::Find;
use Pod::Tree::HTML;

my %Options;
$Options{toc} = 1;
my $ok = GetOptions(\%Options, 
		    "base:s",
		    "toc!", "hr:i", 
		    "bgcolor:s", "text:s");
$ok or die "Bad command line options\n";

my($PodDir, $HTMLDir) = @ARGV;
$HTMLDir or die "pods2html PodDir HTMLDir\n";

$PodDir  =~ s(/$)();
$HTMLDir =~ s(/$)();

umask 0022;
find(\&Pod, $PodDir);


sub Pod
{
    -d and &MakeDir;
    -f and &Translate;
}


sub MakeDir
{
    print "$File::Find::name\n";
    my $dir = $File::Find::name;
    $dir =~ s/^$PodDir/$HTMLDir/o;
    -d $dir or mkdir $dir, 0755 or die "Can't mkdir $dir: $!\n";
}


sub Translate
{
    m( \.(pm|pod)$ )x or return;
    print "$File::Find::name\n";
    
    my $source = $_;

    my $dest = $File::Find::name;
    $dest =~ s/^$PodDir/$HTMLDir/o;
    $dest =~ s( \.\w+$ )(.html)x;

    my $html = new Pod::Tree::HTML $source, $dest;
    $html->set_options(%Options);
    $html->translate;
}

__END__

=head1 NAME

pods2html - translate a tree of PODs to HTML

=head1 SYNOPSIS

C<pods2html> 
[C<--base> I<url>]
[C<-->[C<no>]C<toc>] [C<--hr> I<level>] 
[C<--bgcolor> I<#rrggbb>] [C<--text> I<#rrggbb>]
F<PODdir> F<HTMLdir>

=head1 DESCRIPTION

C<pod2html> finds all the F<.pod> and F<.pm> files in the 
directory tree rooted at F<PODdir>.
It translates each POD to HTML,
and writes it to a parallel directory tree rooted at F<HTMLdir>

It makes the HTML files world-readable.

=head1 OPTIONS

=over 4

=item C<--base> I<url>

Translate C<LE<lt>E<gt>> sequences into HTML
links relative to I<url>.

=item C<-->[C<no>]C<toc>

Includes or omits the table of contents.
Default is to include the TOC.

=item C<--hr> I<level>

Controls the profusion of horizontal lines in the output, as follows:

    level   horizontal lines
    0 	    none
    1 	    between TOC and body
    2 	    after each =head1
    3 	    after each =head1 and =head2

Default is level 1.

=item C<--bgcolor> I<#rrggbb>

Set the background color to I<#rrggbb>.
Default is off-white.

=item C<--text> I<#rrggbb>

Set the text color to I<#rrggbb>.
Default is black.

=back

=head1 REQUIRES

L<C<Pod::Tree::HTML>>

=head1 SEE ALSO

L<C<pod2html>>, L<C<Pod::Tree::HTML>>

=head1 AUTHOR

Steven McDougall, <swmcd@world.std.com>

=head1 COPYRIGHT

Copyright 1999 by Steven McDougall.  This program is free software;
you can redistribute it and/or modify it under the same terms as Perl.

