Pod::Tree::HTML(3pm)

Pod::Tree::HTML3pm

Generate html from a pod::tree

Usage

  use Pod::Tree::HTML;
  $source   =   Pod::Tree->new(%options);
  $source   =  "file.pod";
  $source   =   IO::File->new;
  $source   = \$pod;
  $source   = \@pod;
  $dest     =   HTML::Stream->new;
  $dest     =   IO::File->new;
  $dest     =  "file.html";
  $html     =   Pod::Tree::HTML->new($source, $dest, %options);
              $html->set_options(%options);
  @values   = $html->get_options(@keys);
              $html->translate;
              $html->translate($template);
              $html->emit_toc;
              $html->emit_body;
  $fragment = $html->escape_2396 ($section);
  $url      = $html->assemble_url($base, $page, $fragment);

Requires

"HTML::Stream", "Text::Template"

Overview

"Pod::Tree::HTML" reads a POD and translates it to HTML. The source and destination are fixed when the object is created. Options are provided for controlling details of the translation.

The "translate" method does the actual translation.

For convenience, "Pod::Tree::HTML" can read PODs from a variety of sources, and write HTML to a variety of destinations. The "new" method resolves the $source and $dest arguments.

"Pod::Tree::HTML" can also use "Text::Template" to fill in an HTML template file.

Source resolution

"Pod::Tree::HTML" can obtain a POD from any of 5 sources. "new" resolves $source by checking these things, in order:

1.

If $source "isa" "POD::Tree", then the POD is taken from that tree.

2.

If $source is not a reference, then it is taken to be the name of a file containing a POD.

3.

If $source "isa" "IO::File", then it is taken to be an "IO::File" object that is already open on a file containing a POD.

4.

If $source is a SCALAR reference, then the text of the POD is taken from that scalar.

5.

if $source is an ARRAY reference, then the paragraphs of the POD are taken from that array.

If $source isn't any of these things, "new" "die"s.

Destination resolution

"Pod::Tree::HTML" can write HTML to any of 5 destinations. "new" resolves $dest by checking these things, in order:

1.

If $dest "isa" "HTML::Stream", then "Pod::Tree::HTML" writes HTML to that stream.

2.

If $dest "isa" "IO::File", then "Pod::Tree::HTML" writes HTML to that file.

3.

If $dest has a "print" method, then "Pod::Tree::HTML" passes HTML to that method.

4.

If $dest is a SCALAR reference, then "Pod::Tree::HTML" writes HTML to that scalar.

5.

If $dest is a string, then "Pod::Tree::HTML" writes HTML to the file with that name.

If $dest isn't any of these things, "new" "die"s.

Methods

$html = "new" "Pod::Tree::HTML" $source, $dest, %options

Creates a new "Pod::Tree::HTML" object.

$html reads a POD from $source, and writes HTML to $dest. See "Source resolution" and "Destination resolution" for details.

Options controlling the translation may be passed in the %options hash. See "OPTIONS" for details.

$html->"set_options"(%options)

Sets options controlling the translation. See "OPTIONS" for details.

@values = $html->"get_options"(@keys)

Returns the current values of the options specified in @keys. See "OPTIONS" for details.

$html->"translate"
$html->"translate"($template)

Translates the POD to HTML. This method should only be called once.

In the second form, $template is the name of a file containing a template. The template will be filled in by the "Text::Template" module. Here is a minimal template, showing example usage of all the variables that are set by "Pod::Tree::HTML".

  <html>
   <head>
    <base href="{$base}">
    <link href="{$css}" rel="stylesheet" type="text/css">
    <title>{$title}</title>
   </head>
   <body bgcolor="{$bgcolor}" text="{$text}">
    {$toc}
    {$body}
   </body>
  </html>

The program fragments in the template are evaulted in the "Pod::Tree::HTML" package. Any variables that you set in this package will be available to your template.

When a template is used, the destination must not be an "HTML::Stream" object.

"translate" doesn't return anything. The first form always returns. The second form "die"s if there is an error creating or filling in the template.

$html->"emit_toc"
$html->"emit_body"

Emits the table of contents and body of the HTML document.

These methods are called automatically by "translate". They are exposed in the API for applications that wish to embed the HTML inside a larger document.

Utility methods

These methods are provided for implementors who write their own link mapper objects.

$fragment = $html->"escape_2396"($section)

Escapes $section according to RFC 2396. For example, the section

    some section

is returned as

    some%20section
$url = $html->"assemble_url"($base, $page, $fragment)

Assembles $base, $page, and $fragment into a URL, of the form

    $base/$page#$fragment

Attempts to construct a valid URL, even if some of $base, $page, and $fragment are empty.

Options

"base" => $url

Specifies a base URL for relative HTML links.

"bgcolor" => #rrggbb

Set the background color to #rrggbb. Default is white.

"css" => $url

Specifies a Cascading Style Sheet for the generated HTML page.

"depth" => $depth

Specifies the depth of the generated HTML page in a directory tree. See "LINK MAPPING" for details.

"empty" => 1

Causes the "translate" method to emit an HTML file, even if the POD is empty. If this option is not provided, then no HTML file is created for empty PODs.

"hr" => $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.

"link_map" => $link_map

Sets the link mapper. See "LINK MAPPING" for details.

"text" => #rrggbb

Set the text color to #rrggbb. Default is black.

"title" => title

Set the page title to title. If no "title" option is given, "Pod::Tree::HTML" will attempt construct a title from the second paragrah of the POD. This supports the following style:

    =head1 NAME
    ls - list contents of directory
"toc" => [0|1]

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

Diagnostics

"Pod::Tree::HTML::new: not enough arguments"

(F) "new" called with fewer than 2 arguments.

"Pod::Tree::HTML::new: Can't load POD from $source"

(F) "new" couldn't resolve the $source argument. See "Source resolution" for details.

"Pod::Tree::HTML::new: Can't write HTML to $dest"

(F) "new" couldn't resolve the $dest argument. See "Destination resolution" for details.

"Pod::Tree::HTML::new: Can't open $dest: $!"

(F) The destination file couldn't be opened.

Releases

8 releases since Debian 6.0 (Squeeze); the text changed 3 times.

  1. 6.0–8
  2. 9
  3. 10–11
  4. 12–13

Author

Steven McDougall, [email protected]

From libpod-tree-perl 1.31-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.