| 40 | | I<Pod> is an evolution of Perl 5's Plain Ol' Documentation (POD) markup. |
| 41 | | Compared to Perl 5 POD, Perldoc's Pod dialect is much more uniform, |
| 42 | | somewhat more compact, and considerably more expressive. |
| | 40 | B<Pod> is an evolution of Perl 5's L<I<Plain Ol' Documentation>|doc:perlpod> |
| | 41 | (POD) markup. Compared to Perl 5 POD, Perldoc's Pod dialect is much more |
| | 42 | uniform, somewhat more compact, and considerably more expressive. The |
| | 43 | Pod dialect also differs in that it is a purely descriptive mark-up |
| | 44 | notation, with no presentational components. |
| | 45 | |
| 46 | | Pod blocks are specified using I<directives>, which always start with an |
| 47 | | C<=> in the first column. Every Pod block directive may be written in |
| 48 | | any of three equivalent forms: I<delimited style>, I<paragraph style>, |
| 49 | | or I<abbreviated style>. |
| | 49 | Pod documents are specified using D<directives>, which are used to |
| | 50 | declare configuration information and to delimit blocks of textual content. |
| | 51 | Every directive starts with an equals sign (C<=>) in the first column. |
| | 52 | |
| | 53 | The content of a document is specified within one or more D<blocks>. Every |
| | 54 | Pod block may be declared in any of three equivalent forms: |
| | 55 | L<I<delimited style>|#Delimited blocks>, L<I<paragraph style>|#Paragraph |
| | 56 | blocks>, or L<I<abbreviated style>|#Abbreviated blocks>. |
| | 57 | |
| | 58 | Anything in a document that is neither a Pod directive nor contained |
| | 59 | within a Pod block is treated as "ambient" material. Typically this |
| | 60 | would be the source code of the program that the Pod is documenting. Pod |
| | 61 | parsers still parse this text into the internal representation of the |
| | 62 | file (representing it as an C<Perldoc::Block::Ambient> block), but |
| | 63 | renderers will usually ignore such blocks. |
| | 64 | |
| | 65 | In Perl 5's POD format, once a POD directive is encountered, the parser |
| | 66 | considers everything that follows to be POD, until an explicit C<=cut> |
| | 67 | directive is encountered, at which point the parser flips between POD |
| | 68 | and ambient text. The Perl 6 Pod format is different. A Pod parser |
| | 69 | always reverts to "ambient" at the end of each Pod directive or block. |
| | 70 | To cause the parser to remain in Pod mode, you must enclose the desired |
| | 71 | Pod region in a C<pod> block: |
| | 72 | |
| | 73 | =begin code :allow<B> |
| | 74 | B<=begin pod> |
| | 75 | |
| | 76 | =head1 A heading |
| | 77 | |
| | 78 | This is Pod too. Specifically, this is a simple C<para> block |
| | 79 | |
| | 80 | $this = pod('also'); # Specifically, a code block |
| | 81 | |
| | 82 | B<=end pod> |
| | 83 | =end code |
| | 84 | |
| | 85 | Alternatively you can indicate an entire file contains only Pod, by |
| | 86 | giving it a C<.pod> suffix. |
| 105 | | |
| 106 | | Note also that in the following specifications, a "blank line" is a line that |
| 107 | | is either empty or that contains only whitespace characters. That is, a blank |
| 108 | | line matches C</^\s*?$/>. Pod uses blank lines, rather than empty lines, as |
| 109 | | delimiters (on the principle of least surprise). |
| | 142 | This is a universal feature of Pod. |
| | 143 | |
| | 144 | Note also that in the following specifications, a "blank line" is a line |
| | 145 | that is either empty or that contains only whitespace characters. That |
| | 146 | is, a blank line matches the Perl 6 pattern: C</^^ \h* $$/>. Pod uses |
| | 147 | blank lines, rather than empty lines, as delimiters on the principle of |
| | 148 | least surprise. |
| 175 | | The three equivalent block specifications (delimited, paragraph, and |
| 176 | | abbreviated) are treated identically by the underlying documentation |
| 177 | | model, so you can use whichever form is most convenient for a particular |
| 178 | | documentation task. In the descriptions that follow, the abbreviated form |
| 179 | | will generally be used, but should be read as standing for all three |
| 180 | | forms equally. |
| | 213 | The three block specifications (delimited, paragraph, and abbreviated) |
| | 214 | are treated identically by the underlying documentation model, so you |
| | 215 | can use whichever form is most convenient for a particular |
| | 216 | documentation task. In the descriptions that follow, the abbreviated |
| | 217 | form will generally be used, but should be read as standing for all |
| | 218 | three forms equally. |
| 203 | | =begin item :term<C<:indented>> |
| 204 | | |
| 205 | | This option specifies that the block is to be indented by a particular |
| 206 | | amount. If the indentation amount includes a sign (i.e. C<+> or C<->) then |
| 207 | | the indentation is relative to the indentation of the surrounding construct; |
| 208 | | unsigned indentations are absolute offsets from the first column. |
| 209 | | |
| 210 | | If a simple number is used (e.g. C<:indent(4)>) it indicates "columns" (for |
| 211 | | fixed-width renderers) or "ems" for variable-width renderers. You can also |
| 212 | | specify a unit after the number. For example: |
| 213 | | |
| 214 | | =for para :indented<1 tab> |
| 215 | | |
| 216 | | =for para :indented<1 em> |
| 217 | | |
| 218 | | =for para :indented<1 col> |
| 219 | | |
| 220 | | =for para :indented<1 lvl> |
| 221 | | |
| 222 | | =for para :indented<4 sp> |
| | 241 | =begin item :term<C<:nested>> |
| | 242 | |
| | 243 | This option specifies that the block is to be nested within its current |
| | 244 | context. For example, nesting might be applied to block quotes, to textual |
| | 245 | examples, or to commentaries. In addition the L<C<=code>|#Code blocks>, |
| | 246 | L<C<=item>|#Lists>, L<C<=input>|#I/O blocks>, and L<C<=output>|#I/O blocks> |
| | 247 | blocks all have implicit nesting. |
| | 248 | |
| | 249 | Nesting of blocks is usually rendered by adding extra indentation to the |
| | 250 | block contents, but may also be indicated in others ways: |
| | 251 | by boxing the contents, by changing the font or size of the nested text, |
| | 252 | or even by folding the text (so long as a visible placeholder is provided). |
| | 253 | |
| | 254 | Occasionally it is desirable to nest content by more than one level: |
| | 255 | |
| | 256 | =begin para :nested |
| | 257 | =begin para :nested |
| | 258 | =begin para :nested |
| | 259 | "We're going deep, deep, I<deep> undercover!" |
| | 260 | =end para |
| | 261 | =end para |
| | 262 | =end para |
| | 263 | |
| | 264 | This can be simplified by giving the C<:nested> option a positive integer |
| | 265 | value: |
| | 266 | |
| | 267 | =for code :allow<B> |
| | 268 | =begin para B<:nested(3)> |
| | 269 | "We're going deep, deep, I<deep> undercover!" |
| | 270 | =end para |
| | 271 | |
| | 272 | You can also give the option a value of zero, to defeat any implicit |
| | 273 | nesting that might normally be applied to a paragraph. For example, to |
| | 274 | specify a block of code that should appear I<without> its usual |
| | 275 | nesting: |
| | 276 | |
| | 277 | =for code :allow<B> |
| | 278 | =comment Don't nest this code block in the usual way... |
| | 279 | B<=begin code :nested(0)> |
| | 280 | |
| | 281 | 1 2 3 4 5 6 |
| | 282 | 123456789012345678901234567890123456789012345678901234567890 |
| | 283 | |------|-----------------------|---------------------------| |
| | 284 | line instruction comments |
| | 285 | number code |
| | 286 | |
| | 287 | =end code |
| | 288 | |
| | 289 | Note that C<:!nested> could also be used for this purpose: |
| | 290 | |
| | 291 | =begin code :!nested |
| 267 | | Like all formatting codes, these are inherently cumulative. For example, |
| 268 | | if the block itself is already inside a formatting code, that formatting |
| 269 | | code will still apply, in addition to the extra bold and italic |
| 270 | | formatting specified by C<:formatted<B I>>. It is also possible to |
| 271 | | I<remove> formatting using a C<:formatted> option, by specifying the |
| 272 | | formatting code(s) with a minus sign before them: |
| 273 | | |
| 274 | | =comment The next para is less important, so de-emphasize it... |
| 275 | | =begin para :formatted<-B> |
| 276 | | Fire. The Untamed Element. Oldest of Man's Mysteries. Giver of |
| 277 | | warmth. Destroyer of forests. Right now I<this> building is on fire. |
| 278 | | Yes! The building is on fire! Leave the building! Enact the age-old |
| 279 | | drama of self-preservation! |
| 280 | | =end para |
| 281 | | |
| | 336 | The internal representations of these two versions are exactly the same, |
| | 337 | except that the second one retains the C<:formatted> option information |
| | 338 | as part of the resulting block object. |
| | 339 | |
| | 340 | Like all formatting codes, codes applied via a C<:formatted> are |
| | 341 | inherently cumulative. For example, if the block itself is already |
| | 342 | inside a formatting code, that formatting code will still apply, in |
| | 343 | addition to the extra "basis" and "important" formatting specified by |
| | 344 | C<:formatted<B I>>. |
| 291 | | within any C<V<>> codes nested inside the current block. The option is |
| 292 | | most often used on C<=code> blocks to allow mark-up within those |
| 293 | | (otherwise verbatim) blocks, though it can be used in I<any> block that |
| 294 | | contains verbatim text. See L<#Formatting within code blocks>. |
| 295 | | |
| | 358 | within any C<V<>> codes that appear in (or are implicitly applied to) |
| | 359 | the current block. The option is most often used on C<=code> blocks to |
| | 360 | allow mark-up within those otherwise verbatim blocks, though it can be |
| | 361 | used in I<any> block that contains verbatim text. See L<#Formatting |
| | 362 | within code blocks>. |
| 417 | | squeezed, lines filled, and any special inline mark-up (see |
| 418 | | L<#Formatting codes>) applied. |
| 419 | | |
| 420 | | Ordinary paragraphs consist of one or more lines of text, each of which |
| 421 | | starts with a non-whitespace character at column 1. The paragraph is |
| 422 | | terminated by the first blank line or opening block directive. For example: |
| 423 | | |
| 424 | | This is an ordinary paragraph. |
| 425 | | Its text will be squeezed and |
| 426 | | short lines filled. It is terminated by |
| 427 | | the first blank line |
| 428 | | |
| 429 | | This is another ordinary paragraph. |
| 430 | | Its text will also be squeezed and |
| 431 | | short lines filled. It is terminated by |
| 432 | | the trailing directive on the next line |
| 433 | | =head2 This is a heading block, not associated with the previous para |
| 434 | | |
| 435 | | Within a C<=begin pod>/C<=end pod> block, ordinary paragraphs do not |
| 436 | | require an explicit marker or delimiters, but there I<is> an explicit |
| 437 | | C<para> marker available: |
| | 482 | squeezed, lines filled, and any special L<inline mark-up|#Formatting codes> |
| | 483 | applied. |
| | 484 | |
| | 485 | Ordinary paragraphs consist of one or more consecutive lines of text, |
| | 486 | each of which starts with a non-whitespace character at column 1. The |
| | 487 | paragraph is terminated by the first blank line or opening block |
| | 488 | directive. For example: |
| | 489 | |
| | 490 | =head1 This is a heading block |
| | 491 | |
| | 492 | This is an ordinary paragraph. |
| | 493 | Its text will be squeezed and |
| | 494 | short lines filled. It is terminated by |
| | 495 | the first blank line |
| | 496 | |
| | 497 | This is another ordinary paragraph. |
| | 498 | Its text will also be squeezed and |
| | 499 | short lines filled. It is terminated by |
| | 500 | the trailing directive on the next line |
| | 501 | |
| | 502 | =head2 This is another heading block |
| | 503 | |
| | 504 | Within a C<=pod>, C<=item>, or C<=nested> block, ordinary paragraphs do not |
| | 505 | require an explicit marker or delimiters, but there is also an explicit |
| | 506 | C<para> marker (which may be used anywhere): |
| 459 | | Code blocks are used to specify pre-formatted text, which should |
| 460 | | be rendered without rejustification, without whitespace-squeezing, and without |
| 461 | | recognizing any inline formatting codes. Typically these blocks are used |
| 462 | | to show examples of code, data, or I/O, and are set using a fixed-width font. |
| 463 | | |
| 464 | | A code block is specified as one or more lines of text, each of which |
| 465 | | starts with a whitespace character. The block is terminated by a blank line. |
| 466 | | For example: |
| 467 | | |
| 468 | | This I<ordinary> paragraph introduces a following |
| 469 | | B<code> block: |
| | 528 | Code blocks are used to specify pre-formatted text (typically source |
| | 529 | code), which should be rendered without rejustification, without |
| | 530 | whitespace-squeezing, and without recognizing any inline formatting |
| | 531 | codes. Code blocks also have an implicit L<nesting|#Nesting blocks> |
| | 532 | associated with them. Typically these blocks are used to show examples |
| | 533 | of code, mark-up, or other textual specifications, and are rendered |
| | 534 | using a fixed-width font. |
| | 535 | |
| | 536 | A code block may be implicitly specified as one or more lines of text, |
| | 537 | each of which starts with a whitespace character. The block is |
| | 538 | terminated by a blank line. For example: |
| | 539 | |
| | 540 | =begin code |
| | 541 | This ordinary paragraph introduces a code block: |
| 472 | | $that.is_specified(:by<indenting>); |
| 473 | | |
| 474 | | There is also an explicit C<code> directive, which allows the contents |
| 475 | | of code blocks to start at the first column, to start with whitespace |
| 476 | | characters that are preserved exactly, and to contain blank lines: |
| 477 | | |
| | 544 | $which.is_specified(:by<indenting>); |
| | 545 | =end code |
| | 546 | |
| | 547 | Implicit code blocks may only be used within C<=pod>, C<=item>, |
| | 548 | C<=nested>, or C<=END> blocks. |
| | 549 | |
| | 550 | There is also an explicit C<=code> block (which can be specified within |
| | 551 | I<any> other block type, not just C<=pod>, C<=item>, etc.): |
| | 552 | |
| | 553 | =begin code :allow<B> |
| 488 | | =end code |
| 489 | | |
| 490 | | The only limitation on the contents of a C<code> block is that they cannot |
| 491 | | begin with an C<=> in the first column. If this is required, the leading C<=> |
| 492 | | must be made C<verbatim|#Verbatim text>: |
| 493 | | |
| 494 | | =begin code :allow<V> |
| 495 | | |
| 496 | | V<=> in the first column is always a Perldoc directive |
| 497 | | |
| 498 | | =end code |
| 499 | | |
| 500 | | Renderers would normally indent the contents of any C<code> block (whether |
| 501 | | it was implicitly or explicitly specified), but this can be overridden using |
| 502 | | the C<:indented> option: |
| 503 | | |
| 504 | | =comment |
| 505 | | Indent this code block to the same column |
| 506 | | as the surrounding text |
| 507 | | |
| 508 | | =begin code :indented(+0) |
| | 564 | B<=end code> |
| | 565 | =end code |
| | 566 | |
| | 567 | As the previous example demonstrates, within an explicit C<=code> block |
| | 568 | the code can start at the first column. Furthermore, lines that start |
| | 569 | with whitespace characters have that whitespace preserved exactly (in |
| | 570 | addition to the implicit nesting of the code). Explicit C<=code> blocks may |
| | 571 | also contain empty lines. |
| | 572 | |
| | 573 | |
| | 574 | =head4 Formatting within code blocks |
| | 575 | |
| | 576 | Although C<=code> blocks automatically disregard all L<formatting |
| | 577 | codes|#Formatting codes>, occasionally you may still need to specify |
| | 578 | some formatting within a code block. For example, you may wish |
| | 579 | to emphasize a particular keyword in an example (using a C<B<>> code). Or |
| | 580 | you may want to indicate that part of the example is metasyntactic |
| | 581 | (using the C<R<>> code). Or you might need to insert a non-ASCII |
| | 582 | character (using the C<E<>> code). |
| | 583 | |
| | 584 | You can specify a list of formatting codes that should still be |
| | 585 | recognized within a code block using the C<:allow> option. The value of |
| | 586 | the C<:allow> option must be a list of the (single-letter) names of one |
| | 587 | or more formatting codes. Those codes will then remain active inside the |
| | 588 | code block. For example: |
| | 589 | |
| | 590 | =begin code :allow< B R > |