Pod::Tree::PerlBin - translate program PODs to HTML


Pod-Tree documentation Contained in the Pod-Tree distribution.

Index


Code Index:

NAME

Top

Pod::Tree::PerlBin - translate program PODs to HTML

SYNOPSIS

Top

  $perl_map = new Pod::Tree::PerlMap;
  $perl_bin = new Pod::Tree::PerlBin $perl_dir, $HTML_dir, $perl_map, %opts;

  $perl_bin->scan(@path);
  $perl_bin->index;
  $perl_bin->translate;

  $top = $perl_bin->get_top_entry;

DESCRIPTION

Top

Pod::Tree::PerlBin translates program PODs to HTML.

It searches for programs in a list of directories (typically a PATH), and searches for PODs withing the programs. Only text (-T) files are considered.

Pod::Tree::PerlBin generates a top-level index of all the program PODs, and writes it to HTML_dir/bin.html.

Pod::Tree::PerlBin generates and uses an index of the PODs that it finds to construct HTML links. Other modules can also use this index.

METHODS

Top

$perl_bin = new Pod::Tree::PerlBin $perl_dir, $HTML_dir, $perl_map, %options

Creates and returns a new Pod::Tree::PerlBin object.

$HTML_dir is the directory where HTML files will be written.

$perl_map maps program names to URLs.

%options are passed through to Pod::Tree::HTML.

The $perl_dir argument is included for consistency with the other Pod::Tree::Perl* modules, but is currently unused.

$perl_bin->scan(@path)

Scans all the directories in @path for program PODs. Only text (-T) files are considered. The search does not recurse through subdirectories.

Each POD that is located is entered into $perl_map.

$perl_bin->index

Generates a top-level index of all the program PODs, and writes it to HTML_dir/bin.html.

$perl_bin->translate

Translates each program POD found by scan to HTML. The HTML pages are written to HTML_dir.

$perl_bin->get_top_entry

Returns a hash reference of the form

  { URL         => $URL,
    description => $description }

Pod::Tree::PerlTop uses this to build a top-level index of all the Perl PODs.

LINKING

Top

Pod::Tree::PerlBin expects the second paragraph of the POD to have the form

    name - description

and enters name into $perl_map. To link to a program POD from another POD, write

    L<name>

REQUIRES

Top

    5.005
    File::Find
    HTML::Stream
    Pod::Tree
    Pod::Tree::HTML
    Pod::Tree::PerlUtil

EXPORTS

Top

Nothing.

SEE ALSO

Top

Pod::Tree::HTML, Pod::Tree::PerlMap,

AUTHOR

Top

Steven McDougall, swmcd@world.std.com

COPYRIGHT

Top


Pod-Tree documentation Contained in the Pod-Tree distribution.

use strict;
use 5.005;
use File::Find;
use HTML::Stream;
use Pod::Tree;
use Pod::Tree::HTML;
use Pod::Tree::PerlUtil;

package Pod::Tree::PerlBin;

use base qw(Pod::Tree::PerlUtil);


sub new
{
    my %defaults = (col_width => 25,
		    bgcolor   => '#ffffff',
		    text      => '#000000');
    my($class, $perl_dir, $html_dir, $link_map, %options) = @_;
    my $options  = { %defaults, %options, link_map => $link_map };

    my $perl_bin = { perl_dir => $perl_dir,
		     html_dir => $html_dir,
		     bin_dir  => 'bin',
		     top_page => 'bin.html',
		     depth    => 1,
		     options  => $options };

    bless $perl_bin, $class
}


sub scan
{
    my($perl_bin, @dirs) = @_;
    $perl_bin->report1("scan");

    for my $dir (@dirs)
    {
	opendir(DIR, $dir) or next;  # Windows apps sometimes leave non-existant dirs on $PATH
	for my $file (readdir(DIR))
	{
	    my $path = "$dir/$file";
	    -f $path and -x $path and -T $path or next;
	    $perl_bin->scan_file($dir, $file);
	}
    }

    $perl_bin->scan_xsubpp;
}


# A Very Special search for a Very Special executable
sub scan_xsubpp
{
    my $perl_bin = shift;

    my @inc = grep { m(^/) } @INC;  # Don't ask.
    File::Find::find(sub { $perl_bin->_scan_xsubpp }, @inc) if @inc;
}

sub _scan_xsubpp
{
    my $perl_bin = shift;

    /^xsubpp$/ and
	$perl_bin->scan_file($File::Find::dir, $_);
}


sub scan_file
{
    my($perl_bin, $dir, $file) = @_;

    my $source   = "$dir/$file";
    my $html_dir =  $perl_bin->{html_dir};
    my $bin_dir  =  $perl_bin->{bin_dir};
    my $link     = "$bin_dir/$file";
    my $dest     = "$html_dir/$link.html";

    my($name, $description) = $perl_bin->get_name($source);
       $name or return;

       # Translate the first copy found in $PATH
       $perl_bin->{index}{$name} and return;

       $perl_bin->report2($source);

    my $entry = { source      => $source,
		  dest        => $dest,
		  file        => $file,
		  description => $description };

       $perl_bin->{index}{$name} = $entry;
       $perl_bin->{options}{link_map}->add_page($file, $link);
       $perl_bin->{options}{link_map}->add_page($name, $link);
}


sub index
{
    my $perl_bin = shift;
       $perl_bin->report1("index");

    my $html_dir = $perl_bin->{html_dir};
    my $bin_dir  = $perl_bin->{bin_dir};
    my $top_page = $perl_bin->{top_page};
    my $dest     = "$html_dir/$top_page";

    $perl_bin->mkdir("$html_dir/$bin_dir");

    my $fh       = new IO::File ">$dest";
    defined $fh or die "Pod::Tree::PerlBin::index: Can't open $dest: $!\n";
    my $stream   = new HTML::Stream $fh;

    my $options  = $perl_bin->{options};
    my $bgcolor  = $options->{bgcolor};
    my $text 	 = $options->{text};
    my $title    = "Perl Executables";

    $stream-> HTML->HEAD;
    $stream-> TITLE->text($title)->_TITLE;
    $stream->_HEAD
	   -> BODY(BGCOLOR => $bgcolor, TEXT => $text);
    $stream->H1->t($title)->_H1;

    $perl_bin->_emit_entries($stream);

    $stream->_BODY->_HTML;
}


sub get_top_entry
{
    my $perl_bin = shift;

    +{ URL         => $perl_bin->{top_page},
       description => 'Executables' }
}


sub _emit_entries
{
    my($perl_bin, $stream) = @_;

    my $bin_dir   = $perl_bin->{bin_dir};
    my $index     = $perl_bin->{index};
    my $options   = $perl_bin->{options};
    my $col_width = $options->{col_width};

    $stream->PRE;

    for my $name (sort keys %$index)
    {
	my $entry = $index->{$name};
	my $file  = $entry->{file};
	my $desc  = $entry->{description};
	my $pad   = $col_width - length $name;

	$stream->A(HREF => "$bin_dir/$file.html")->t($name)->_A;

	$pad < 1 and do
	{
	    $stream->nl;
	    $pad = $col_width;
	};

	$stream->t(' ' x $pad, $desc)->nl;
    }

    $stream->_PRE;
}


sub translate
{
    my $perl_bin = shift;
       $perl_bin->report1("translate");

    my $index    = $perl_bin->{index};
    my $options  = $perl_bin->{options};

    for my $name (sort keys %$index)
    {
	$perl_bin->report2($name);
	my $depth  = $perl_bin->{depth};
	$options->{link_map}->set_depth($depth);
	
	my $entry  = $index->{$name};
	my $source = $entry->{source};
	my $dest   = $entry->{dest};
	my $html   = new Pod::Tree::HTML $source, $dest, %$options;
	$html->translate;
    }
}

1

__END__