perlpod - plain old documentation |
perlpod - plain old documentation
A pod-to-whatever translator reads a pod file paragraph by paragraph, and translates it to the appropriate output format. There are three kinds of paragraphs: verbatim, command, and ordinary text.
A verbatim paragraph, distinguished by being indented (that is, it starts with space or tab). It should be reproduced exactly, with tabs assumed to be on 8-column boundaries. There are no special formatting escapes, so you can't italicize or anything like that. A \ means \, and nothing else.
All command paragraphs start with ``='', followed by an identifier, followed by arbitrary text that the command can use however it pleases. Currently recognized commands are
=head1 heading =head2 heading =item text =over N =back =cut =pod =for X =begin X =end X
=for html <br> <p> This is a raw HTML paragraph </p>
The paired commands ``=begin'' and ``=end'' work very similarly to ``=for'', but instead of only accepting a single paragraph, all text from ``=begin'' to a paragraph with a matching ``=end'' are treated as a particular format.
Here are some examples of how to use these:
=begin html
<br>Figure 1.<IMG SRC="figure1.png"><br>
=end html
=begin text
--------------- | foo | | bar | ---------------
^^^^ Figure 1. ^^^^
=end text
Some format names that formatters currently are known to accept include ``roff'', ``man'', ``latex'', ``tex'', ``text'', and ``html''. (Some formatters will treat some of these as synonyms.)
And don't forget, when using any command, that the command lasts up until the end of the paragraph, not the line. Hence in the examples below, you can see the empty lines after each command to end its paragraph.
Some examples of lists include:
=over 4
=item *
First item
=item *
Second item
=back
=over 4
=item Foo()
Description of Foo function
=item Bar()
Description of Bar function
=back
It will be filled, and maybe even justified. Certain interior sequences are recognized both here and in commands:
I<text> Italicize text, used for emphasis or variables B<text> Embolden text, used for switches and programs S<text> Text contains non-breaking spaces C<code> Render code in a typewriter font, or give some other indication that this represents program text L<name> A link (cross reference) to name L<name> manual page L<name/ident> item in manual page L<name/"sec"> section in other manual page L<"sec"> section in this manual page (the quotes are optional) L</"sec"> ditto same as above but only 'text' is used for output. (Text can not contain the characters '/' and '|', and should contain matched '<' or '>') L<text|name> L<text|name/ident> L<text|name/"sec"> L<text|"sec"> L<text|/"sec">
F<file> Used for filenames X<index> An index entry Z<> A zero-width character E<escape> A named character (very similar to HTML escapes) E<lt> A literal < E<gt> A literal > E<sol> A literal / E<verbar> A literal | (these are optional except in other interior sequences and when preceded by a capital letter) E<n> Character number n (probably in ASCII) E<html> Some non-numeric HTML entity, such as E<Agrave>
Most of the time, you will only need a single set of angle brackets to
delimit the beginning and end of interior sequences. However, sometimes
you will want to put a right angle bracket (or greater-than sign '>')
inside of a sequence. This is particularly common when using a sequence
to provide a different font-type for a snippet of code. As with all
things in Perl, there is more than one way to do it. One way is to
simply escape the closing bracket using an E
sequence:
C<$a E<lt>=E<gt> $b>
This will produce: ``$a <=> $b
''
A more readable, and perhaps more ``plain'' way is to use an alternate set of delimiters that doesn't require a ``>'' to be escaped. As of perl5.5.660, doubled angle brackets (``<<'' and ``>>'') may be used if and only if there is whitespace immediately following the opening delimiter and immediately preceding the closing delimiter! For example, the following will do the trick:
C<< $a <=> $b >>
In fact, you can use as many repeated angle-brackets as you like so long as you have the same number of them in the opening and closing delimiters, and make sure that whitespace immediately follows the last '<' of the opening delimiter, and immediately precedes the first '>' of the closing delimiter. So the following will also work:
C<<< $a <=> $b >>> C<<<< $a <=> $b >>>>
This is currently supported by pod2text (Pod::Text), pod2man (Pod::Man), and any other pod2xxx and Pod::Xxxx translator that uses Pod::Parser 1.093 or later.
That's it. The intent is simplicity, not power. I wanted paragraphs to look like paragraphs (block format), so that they stand out visually, and so that I could run them through fmt easily to reformat them (that's F7 in my version of vi). I wanted the translator (and not me) to worry about whether `` or ' is a left quote or a right quote within filled text, and I wanted it to leave the quotes alone, dammit, in verbatim mode, so I could slurp in a working program, shift it over 4 spaces, and have it print out, er, verbatim. And presumably in a constant width font.
In particular, you can leave things like this verbatim in your text:
Perl FILEHANDLE $variable function() manpage(3r)
Doubtless a few other commands or sequences will need to be added along the way, but I've gotten along surprisingly well with just these.
Note that I'm not at all claiming this to be sufficient for producing a
book. I'm just trying to make an idiot-proof common source for nroff,
TeX, and other markup languages, as used for online documentation.
Translators exist for pod2man (that's for nroff(1)
and troff(1)),
pod2text, pod2html, pod2latex, and pod2fm.
You can embed pod documentation in your Perl scripts. Start your documentation with a ``=head1'' command at the beginning, and end it with a ``=cut'' command. Perl will ignore the pod text. See any of the supplied library modules for examples. If you're going to put your pods at the end of the file, and you're using an __END__ or __DATA__ cut mark, make sure to put an empty line there before the first pod directive.
__END__
=head1 NAME
modern - I am a modern module
If you had not had that empty line there, then the translators wouldn't have seen it.
L<foo(1)>
becomes ``the foo(1) manpage'', for example (see
pod2man for details). Thus, you shouldn't write things like the
LE<lt>fooE<gt> manpage
, if you want the translated document to read
sensibly.
If you need total control of the text used for a link in the output use the form L<show this text|foo> instead.
pod2man, PODs: Embedded Documentation in the perlsyn manpage, podchecker
Larry Wall
perlpod - plain old documentation |