1PERLPOD(1)             Perl Programmers Reference Guide             PERLPOD(1)
2
3
4

NAME

6       perlpod - the Plain Old Documentation format
7

DESCRIPTION

9       Pod is a simple-to-use markup language used for writing documentation
10       for Perl, Perl programs, and Perl modules.
11
12       Translators are available for converting Pod to various formats like
13       plain text, HTML, man pages, and more.
14
15       Pod markup consists of three basic kinds of paragraphs: ordinary,
16       verbatim, and command.
17
18   Ordinary Paragraph
19       Most paragraphs in your documentation will be ordinary blocks of text,
20       like this one.  You can simply type in your text without any markup
21       whatsoever, and with just a blank line before and after.  When it gets
22       formatted, it will undergo minimal formatting, like being rewrapped,
23       probably put into a proportionally spaced font, and maybe even
24       justified.
25
26       You can use formatting codes in ordinary paragraphs, for bold, italic,
27       "code-style", hyperlinks, and more.  Such codes are explained in the
28       "Formatting Codes" section, below.
29
30   Verbatim Paragraph
31       Verbatim paragraphs are usually used for presenting a codeblock or
32       other text which does not require any special parsing or formatting,
33       and which shouldn't be wrapped.
34
35       A verbatim paragraph is distinguished by having its first character be
36       a space or a tab.  (And commonly, all its lines begin with spaces
37       and/or tabs.)  It should be reproduced exactly, with tabs assumed to be
38       on 8-column boundaries.  There are no special formatting codes, so you
39       can't italicize or anything like that.  A \ means \, and nothing else.
40
41   Command Paragraph
42       A command paragraph is used for special treatment of whole chunks of
43       text, usually as headings or parts of lists.
44
45       All command paragraphs (which are typically only one line long) start
46       with "=", followed by an identifier, followed by arbitrary text that
47       the command can use however it pleases.  Currently recognized commands
48       are
49
50           =pod
51           =head1 Heading Text
52           =head2 Heading Text
53           =head3 Heading Text
54           =head4 Heading Text
55           =head5 Heading Text
56           =head6 Heading Text
57           =over indentlevel
58           =item stuff
59           =back
60           =begin format
61           =end format
62           =for format text...
63           =encoding type
64           =cut
65
66       To explain them each in detail:
67
68       "=head1 Heading Text"
69       "=head2 Heading Text"
70       "=head3 Heading Text"
71       "=head4 Heading Text"
72       "=head5 Heading Text"
73       "=head6 Heading Text"
74           Head1 through head6 produce headings, head1 being the highest
75           level.  The text in the rest of this paragraph is the content of
76           the heading.  For example:
77
78             =head2 Object Attributes
79
80           The text "Object Attributes" comprises the heading there.  The text
81           in these heading commands can use formatting codes, as seen here:
82
83             =head2 Possible Values for C<$/>
84
85           Such commands are explained in the "Formatting Codes" section,
86           below.
87
88           Note that "head5" and "head6" were introduced in 2020 and in
89           Pod::Simple 3.41, released in October 2020, so they might not be
90           supported on the Pod parser you use.
91
92       "=over indentlevel"
93       "=item stuff..."
94       "=back"
95           Item, over, and back require a little more explanation:  "=over"
96           starts a region specifically for the generation of a list using
97           "=item" commands, or for indenting (groups of) normal paragraphs.
98           At the end of your list, use "=back" to end it.  The indentlevel
99           option to "=over" indicates how far over to indent, generally in
100           ems (where one em is the width of an "M" in the document's base
101           font) or roughly comparable units; if there is no indentlevel
102           option, it defaults to four.  (And some formatters may just ignore
103           whatever indentlevel you provide.)  In the stuff in "=item
104           stuff...", you may use formatting codes, as seen here:
105
106             =item Using C<$|> to Control Buffering
107
108           Such commands are explained in the "Formatting Codes" section,
109           below.
110
111           Note also that there are some basic rules to using "=over" ...
112           "=back" regions:
113
114           •   Don't use "=item"s outside of an "=over" ... "=back" region.
115
116           •   The first thing after the "=over" command should be an "=item",
117               unless there aren't going to be any items at all in this
118               "=over" ... "=back" region.
119
120           •   Don't put "=headn" commands inside an "=over" ... "=back"
121               region.
122
123           •   And perhaps most importantly, keep the items consistent: either
124               use "=item *" for all of them, to produce bullets; or use
125               "=item 1.", "=item 2.", etc., to produce numbered lists; or use
126               "=item foo", "=item bar", etc.--namely, things that look
127               nothing like bullets or numbers.  (If you have a list that
128               contains both: 1) things that don't look like bullets nor
129               numbers,  plus 2) things that do, you should preface the
130               bullet- or number-like items with "Z<>".  See Z<> below for an
131               example.)
132
133               If you start with bullets or numbers, stick with them, as
134               formatters use the first "=item" type to decide how to format
135               the list.
136
137       "=cut"
138           To end a Pod block, use a blank line, then a line beginning with
139           "=cut", and a blank line after it.  This lets Perl (and the Pod
140           formatter) know that this is where Perl code is resuming.  (The
141           blank line before the "=cut" is not technically necessary, but many
142           older Pod processors require it.)
143
144       "=pod"
145           The "=pod" command by itself doesn't do much of anything, but it
146           signals to Perl (and Pod formatters) that a Pod block starts here.
147           A Pod block starts with any command paragraph, so a "=pod" command
148           is usually used just when you want to start a Pod block with an
149           ordinary paragraph or a verbatim paragraph.  For example:
150
151             =item stuff()
152
153             This function does stuff.
154
155             =cut
156
157             sub stuff {
158               ...
159             }
160
161             =pod
162
163             Remember to check its return value, as in:
164
165               stuff() || die "Couldn't do stuff!";
166
167             =cut
168
169       "=begin formatname"
170       "=end formatname"
171       "=for formatname text..."
172           For, begin, and end will let you have regions of text/code/data
173           that are not generally interpreted as normal Pod text, but are
174           passed directly to particular formatters, or are otherwise special.
175           A formatter that can use that format will use the region, otherwise
176           it will be completely ignored.
177
178           A command "=begin formatname", some paragraphs, and a command "=end
179           formatname", mean that the text/data in between is meant for
180           formatters that understand the special format called formatname.
181           For example,
182
183             =begin html
184
185             <hr> <img src="thang.png">
186             <p> This is a raw HTML paragraph </p>
187
188             =end html
189
190           The command "=for formatname text..."  specifies that the remainder
191           of just this paragraph (starting right after formatname) is in that
192           special format.
193
194             =for html <hr> <img src="thang.png">
195             <p> This is a raw HTML paragraph </p>
196
197           This means the same thing as the above "=begin html" ... "=end
198           html" region.
199
200           That is, with "=for", you can have only one paragraph's worth of
201           text (i.e., the text in "=foo targetname text..."), but with
202           "=begin targetname" ... "=end targetname", you can have any amount
203           of stuff in between.  (Note that there still must be a blank line
204           after the "=begin" command and a blank line before the "=end"
205           command.)
206
207           Here are some examples of how to use these:
208
209             =begin html
210
211             <br>Figure 1.<br><IMG SRC="figure1.png"><br>
212
213             =end html
214
215             =begin text
216
217               ---------------
218               |  foo        |
219               |        bar  |
220               ---------------
221
222             ^^^^ Figure 1. ^^^^
223
224             =end text
225
226           Some format names that formatters currently are known to accept
227           include "roff", "man", "latex", "tex", "text", and "html".  (Some
228           formatters will treat some of these as synonyms.)
229
230           A format name of "comment" is common for just making notes
231           (presumably to yourself) that won't appear in any formatted version
232           of the Pod document:
233
234             =for comment
235             Make sure that all the available options are documented!
236
237           Some formatnames will require a leading colon (as in "=for
238           :formatname", or "=begin :formatname" ... "=end :formatname"), to
239           signal that the text is not raw data, but instead is Pod text
240           (i.e., possibly containing formatting codes) that's just not for
241           normal formatting (e.g., may not be a normal-use paragraph, but
242           might be for formatting as a footnote).
243
244       "=encoding encodingname"
245           This command is used for declaring the encoding of a document.
246           Most users won't need this; but if your encoding isn't US-ASCII,
247           then put a "=encoding encodingname" command very early in the
248           document so that pod formatters will know how to decode the
249           document.  For encodingname, use a name recognized by the
250           Encode::Supported module.  Some pod formatters may try to guess
251           between a Latin-1 or CP-1252 versus UTF-8 encoding, but they may
252           guess wrong.  It's best to be explicit if you use anything besides
253           strict ASCII.  Examples:
254
255             =encoding latin1
256
257             =encoding utf8
258
259             =encoding koi8-r
260
261             =encoding ShiftJIS
262
263             =encoding big5
264
265           "=encoding" affects the whole document, and must occur only once.
266
267       And don't forget, all commands but "=encoding" last up until the end of
268       its paragraph, not its line.  So in the examples below, you can see
269       that every command needs the blank line after it, to end its paragraph.
270       (And some older Pod translators may require the "=encoding" line to
271       have a following blank line as well, even though it should be legal to
272       omit.)
273
274       Some examples of lists include:
275
276         =over
277
278         =item *
279
280         First item
281
282         =item *
283
284         Second item
285
286         =back
287
288         =over
289
290         =item Foo()
291
292         Description of Foo function
293
294         =item Bar()
295
296         Description of Bar function
297
298         =back
299
300   Formatting Codes
301       In ordinary paragraphs and in some command paragraphs, various
302       formatting codes (a.k.a. "interior sequences") can be used:
303
304       "I<text>" -- italic text
305           Used for emphasis (""be I<careful!>"") and parameters (""redo
306           I<LABEL>"")
307
308       "B<text>" -- bold text
309           Used for switches (""perl's B<-n> switch""), programs (""some
310           systems provide a B<chfn> for that""), emphasis (""be
311           B<careful!>""), and so on (""and that feature is known as
312           B<autovivification>"").
313
314       "C<code>" -- code text
315           Renders code in a typewriter font, or gives some other indication
316           that this represents program text (""C<gmtime($^T)>"") or some
317           other form of computerese (""C<drwxr-xr-x>"").
318
319       "L<name>" -- a hyperlink
320           There are various syntaxes, listed below.  In the syntaxes given,
321           "text", "name", and "section" cannot contain the characters '/' and
322           '|'; and any '<' or '>' should be matched.
323
324           •   "L<name>"
325
326               Link to a Perl manual page (e.g., "L<Net::Ping>").  Note that
327               "name" should not contain spaces.  This syntax is also
328               occasionally used for references to Unix man pages, as in
329               "L<crontab(5)>".
330
331           •   "L<name/"sec">" or "L<name/sec>"
332
333               Link to a section in other manual page.  E.g., "L<perlsyn/"For
334               Loops">"
335
336           •   "L</"sec">" or "L</sec>"
337
338               Link to a section in this manual page.  E.g., "L</"Object
339               Methods">"
340
341           A section is started by the named heading or item.  For example,
342           "L<perlvar/$.>" or "L<perlvar/"$.">" both link to the section
343           started by ""=item $."" in perlvar.  And "L<perlsyn/For Loops>" or
344           "L<perlsyn/"For Loops">" both link to the section started by
345           ""=head2 For Loops"" in perlsyn.
346
347           To control what text is used for display, you use ""L<text|...>"",
348           as in:
349
350           •   "L<text|name>"
351
352               Link this text to that manual page.  E.g., "L<Perl Error
353               Messages|perldiag>"
354
355           •   "L<text|name/"sec">" or "L<text|name/sec>"
356
357               Link this text to that section in that manual page.  E.g.,
358               "L<postfix "if"|perlsyn/"Statement Modifiers">"
359
360           •   "L<text|/"sec">" or "L<text|/sec>" or "L<text|"sec">"
361
362               Link this text to that section in this manual page.  E.g.,
363               "L<the various attributes|/"Member Data">"
364
365           Or you can link to a web page:
366
367           •   "L<scheme:...>"
368
369               "L<text|scheme:...>"
370
371               Links to an absolute URL.  For example,
372               "L<http://www.perl.org/>" or "L<The Perl Home
373               Page|http://www.perl.org/>".
374
375       "E<escape>" -- a character escape
376           Very similar to HTML/XML "&foo;" "entity references":
377
378           •   "E<lt>" -- a literal < (less than)
379
380           •   "E<gt>" -- a literal > (greater than)
381
382           •   "E<verbar>" -- a literal | (vertical bar)
383
384           •   "E<sol>" -- a literal / (solidus)
385
386               The above four are optional except in other formatting codes,
387               notably "L<...>", and when preceded by a capital letter.
388
389           •   "E<htmlname>"
390
391               Some non-numeric HTML entity name, such as "E<eacute>", meaning
392               the same thing as "&eacute;" in HTML -- i.e., a lowercase e
393               with an acute (/-shaped) accent.
394
395           •   "E<number>"
396
397               The ASCII/Latin-1/Unicode character with that number.  A
398               leading "0x" means that number is hex, as in "E<0x201E>".  A
399               leading "0" means that number is octal, as in "E<075>".
400               Otherwise number is interpreted as being in decimal, as in
401               "E<181>".
402
403               Note that older Pod formatters might not recognize octal or hex
404               numeric escapes, and that many formatters cannot reliably
405               render characters above 255.  (Some formatters may even have to
406               use compromised renderings of Latin-1/CP-1252 characters, like
407               rendering "E<eacute>" as just a plain "e".)
408
409       "F<filename>" -- used for filenames
410           Typically displayed in italics.  Example: ""F<.cshrc>""
411
412       "S<text>" -- text contains non-breaking spaces
413           This means that the words in text should not be broken across
414           lines.  Example: "S<$x ? $y : $z>".
415
416       "X<topic name>" -- an index entry
417           This is ignored by most formatters, but some may use it for
418           building indexes.  It always renders as empty-string.  Example:
419           "X<absolutizing relative URLs>"
420
421       "Z<>" -- a null (zero-effect) formatting code
422           This is rarely used.  It's one way to get around using an E<...>
423           code sometimes.  For example, instead of ""NE<lt>3"" (for "N<3")
424           you could write ""NZ<><3"" (the "Z<>" breaks up the "N" and the "<"
425           so they can't be considered the part of a (fictitious) "N<...>"
426           code).
427
428           Another use is to indicate that stuff in "=item Z<>stuff..."  is
429           not to be considered to be a bullet or number.  For example,
430           without the "Z<>", the line
431
432            =item Z<>500 Server error
433
434           could possibly be parsed as an item in a numbered list when it
435           isn't meant to be.
436
437           Still another use is to maintain visual space between "=item"
438           lines.  If you specify
439
440            =item foo
441
442            =item bar
443
444           it will typically get rendered as
445
446            foo
447            bar
448
449           That may be what you want, but if what you really want is
450
451            foo
452
453            bar
454
455           you can use "Z<>" to accomplish that
456
457            =item foo
458
459            Z<>
460
461            =item bar
462
463       Most of the time, you will need only a single set of angle brackets to
464       delimit the beginning and end of formatting codes.  However, sometimes
465       you will want to put a real right angle bracket (a greater-than sign,
466       '>') inside of a formatting code.  This is particularly common when
467       using a formatting code to provide a different font-type for a snippet
468       of code.  As with all things in Perl, there is more than one way to do
469       it.  One way is to simply escape the closing bracket using an "E" code:
470
471           C<$a E<lt>=E<gt> $b>
472
473       This will produce: ""$a <=> $b""
474
475       A more readable, and perhaps more "plain" way is to use an alternate
476       set of delimiters that doesn't require a single ">" to be escaped.
477       Doubled angle brackets ("<<" and ">>") may be used if and only if there
478       is whitespace right after the opening delimiter and whitespace right
479       before the closing delimiter!  For example, the following will do the
480       trick:
481
482           C<< $a <=> $b >>
483
484       In fact, you can use as many repeated angle-brackets as you like so
485       long as you have the same number of them in the opening and closing
486       delimiters, and make sure that whitespace immediately follows the last
487       '<' of the opening delimiter, and immediately precedes the first '>' of
488       the closing delimiter.  (The whitespace is ignored.)  So the following
489       will also work:
490
491           C<<< $a <=> $b >>>
492           C<<<<  $a <=> $b     >>>>
493
494       And they all mean exactly the same as this:
495
496           C<$a E<lt>=E<gt> $b>
497
498       The multiple-bracket form does not affect the interpretation of the
499       contents of the formatting code, only how it must end.  That means that
500       the examples above are also exactly the same as this:
501
502           C<< $a E<lt>=E<gt> $b >>
503
504       As a further example, this means that if you wanted to put these bits
505       of code in "C" (code) style:
506
507           open(X, ">>thing.dat") || die $!
508           $foo->bar();
509
510       you could do it like so:
511
512           C<<< open(X, ">>thing.dat") || die $! >>>
513           C<< $foo->bar(); >>
514
515       which is presumably easier to read than the old way:
516
517           C<open(X, "E<gt>E<gt>thing.dat") || die $!>
518           C<$foo-E<gt>bar();>
519
520       This is currently supported by pod2text (Pod::Text), pod2man
521       (Pod::Man), and any other pod2xxx or Pod::Xxxx translators that use
522       Pod::Parser 1.093 or later, or Pod::Tree 1.02 or later.
523
524   The Intent
525       The intent is simplicity of use, not power of expression.  Paragraphs
526       look like paragraphs (block format), so that they stand out visually,
527       and so that I could run them through "fmt" easily to reformat them
528       (that's F7 in my version of vi, or Esc Q in my version of emacs).  I
529       wanted the translator to always leave the "'" and "`" and """ quotes
530       alone, in verbatim mode, so I could slurp in a working program, shift
531       it over four spaces, and have it print out, er, verbatim.  And
532       presumably in a monospace font.
533
534       The Pod format is not necessarily sufficient for writing a book.  Pod
535       is just meant to be an idiot-proof common source for nroff, HTML, TeX,
536       and other markup languages, as used for online documentation.
537       Translators exist for pod2text, pod2html, pod2man (that's for nroff(1)
538       and troff(1)), pod2latex, and pod2fm.  Various others are available in
539       CPAN.
540
541   Embedding Pods in Perl Modules
542       You can embed Pod documentation in your Perl modules and scripts.
543       Start your documentation with an empty line, a "=head1" command at the
544       beginning, and end it with a "=cut" command and an empty line.  The
545       perl executable will ignore the Pod text.  You can place a Pod
546       statement where perl expects the beginning of a new statement, but not
547       within a statement, as that would result in an error.  See any of the
548       supplied library modules for examples.
549
550       If you're going to put your Pod at the end of the file, and you're
551       using an "__END__" or "__DATA__" cut mark, make sure to put an empty
552       line there before the first Pod command.
553
554         __END__
555
556         =head1 NAME
557
558         Time::Local - efficiently compute time from local and GMT time
559
560       Without that empty line before the "=head1", many translators wouldn't
561       have recognized the "=head1" as starting a Pod block.
562
563   Hints for Writing Pod
564
565
566
567           The podchecker command is provided for checking Pod syntax for
568           errors and warnings.  For example, it checks for completely blank
569           lines in Pod blocks and for unknown commands and formatting codes.
570           You should still also pass your document through one or more
571           translators and proofread the result, or print out the result and
572           proofread that.  Some of the problems found may be bugs in the
573           translators, which you may or may not wish to work around.
574
575       •   If you're more familiar with writing in HTML than with writing in
576           Pod, you can try your hand at writing documentation in simple HTML,
577           and converting it to Pod with the experimental Pod::HTML2Pod
578           module, (available in CPAN), and looking at the resulting code.
579           The experimental Pod::PXML module in CPAN might also be useful.
580
581       •   Many older Pod translators require the lines before every Pod
582           command and after every Pod command (including "=cut"!) to be a
583           blank line.  Having something like this:
584
585            # - - - - - - - - - - - -
586            =item $firecracker->boom()
587
588            This noisily detonates the firecracker object.
589            =cut
590            sub boom {
591            ...
592
593           ...will make such Pod translators completely fail to see the Pod
594           block at all.
595
596           Instead, have it like this:
597
598            # - - - - - - - - - - - -
599
600            =item $firecracker->boom()
601
602            This noisily detonates the firecracker object.
603
604            =cut
605
606            sub boom {
607            ...
608
609       •   Some older Pod translators require paragraphs (including command
610           paragraphs like "=head2 Functions") to be separated by completely
611           empty lines.  If you have an apparently empty line with some spaces
612           on it, this might not count as a separator for those translators,
613           and that could cause odd formatting.
614
615       •   Older translators might add wording around an L<> link, so that
616           "L<Foo::Bar>" may become "the Foo::Bar manpage", for example.  So
617           you shouldn't write things like "the L<foo> documentation", if you
618           want the translated document to read sensibly.  Instead, write "the
619           L<Foo::Bar|Foo::Bar> documentation" or "L<the Foo::Bar
620           documentation|Foo::Bar>", to control how the link comes out.
621
622       •   Going past the 70th column in a verbatim block might be
623           ungracefully wrapped by some formatters.
624

SEE ALSO

626       perlpodspec, "PODs: Embedded Documentation" in perlsyn, perlnewmod,
627       perldoc, pod2html, pod2man, podchecker.
628

AUTHOR

630       Larry Wall, Sean M. Burke
631
632
633
634perl v5.36.0                      2022-08-30                        PERLPOD(1)
Impressum