diff --git a/S26-documentation.pod b/S26-documentation.pod index b75e9d96d..001652f16 100644 --- a/S26-documentation.pod +++ b/S26-documentation.pod @@ -6,7 +6,7 @@ This file is deliberately specified in Perl 6 Pod format =TITLE Synopsis 26 - Documentation -=AUTHOR +=for AUTHOR Damian Conway |mailto:damian@conway.org>> =begin VERSION @@ -16,7 +16,8 @@ Damian Conway |mailto:damian@conway.org>> Last Modified: 16 Aug 2009 =end VERSION -=head1 Pod +=head1 +Pod D is an easy-to-use markup language with a simple, consistent underlying document object model. Pod can be used for writing language @@ -32,14 +33,14 @@ notation, with no presentational components. =head2 General syntactic structure -Pod documents are specified using D, which are used to -declare configuration information and to delimit blocks of textual -content. All Pod directives are considered to be special types of -comments in Perl 6. +Pod documents are specified using D, which are +used to declare configuration information and to delimit blocks of +textual content. All Pod directives are considered to be special types +of comments in Perl 6. Every directive starts either with an equals sign (C<=>) followed -immediately by an identifier, or with a C<#=> followed immediately by -whitespace or an opening bracket. +immediately by an identifier N, or with a +C<#=> followed immediately by whitespace or an opening bracket. Directives that start with C<=> can be indented like the code they interleave, but their initial C<=> must still be the first non-whitespace @@ -55,9 +56,10 @@ determined by the indentation of its opening delimiter. As with Perl 6 heredocs, the virtual margin treats leading tabs as aligning to tabstops spaced every C<($?TABSTOP // 8)> characters. -=head2 Pod blocks +=head2 +Pod blocks -The content of a document is specified within one or more D. +The content of a document is specified within one or more D. Every Pod block may be declared in any of four forms: L|#Delimited blocks>, L|#Paragraph blocks>, L|#Abbreviated blocks>, or L block), but renderers -will I ignore such blocks (see L<#Aliases>). +will I ignore such blocks (but see L<#Aliases>). In Perl 5's POD format, once a POD directive is encountered, the parser considers everything that follows to be POD, until an explicit C<=cut> @@ -92,16 +94,13 @@ C block: B<=end pod> =end code - =head3 Delimited blocks Delimited blocks are bounded by C<=begin> and C<=end> markers, both of -which are followed by a valid identifierN< - A valid identifier is a sequence of alphanumerics and/or - underscores, beginning with an alphabetic or underscore ->, which is the D of the block. Typenames that are entirely -lowercase (for example: C<=begin head1>) or entirely uppercase -(for example: C<=begin SYNOPSIS>) are reserved. +which are followed by a valid Perl 6 identifier, which is the +D of the block. Typenames that are entirely lowercase (for +example: C<=begin head1>) or entirely uppercase (for example: C<=begin +SYNOPSIS>) are reserved. After the typename, the rest of the C<=begin> marker line is treated as configuration information for the block. This information is used in @@ -117,9 +116,10 @@ Perl6-ish option pairs. That is, any of: List C«:key<1 2 3>» C«:key[1,2,3]» C«key => [1,2,3]» Hash C«:key{a=>1, b=>2}» C«key => {a=>1, b=>2}» -All option keys and values must, of course, be constants since Pod -is a specification language, not a programming language. -See Synopsis 2 for details of the various Perl 6 pair notations. +All option keys and values must, of course, be constants since Pod is a +specification language, not a programming language. Specifically, option +values cannot be closures. See Synopsis 2 for details of the various +Perl 6 pair notations. The configuration section may be extended over subsequent lines by starting those lines with an C<=> in the first (virtual) column followed @@ -147,8 +147,11 @@ For example: =begin code =begin table :caption Constants 1 + Variables 10 + Subroutines 33 + Everything else 57 =end table @@ -250,8 +253,8 @@ specifically, from some nearby declarator. Declarator blocks are introduced by a special Perl comment: C<#=>, which must be immediately followed by either by a space or an opening bracket. If followed by a space, the block is terminated by the end of line; if -followed by an opening bracket, the block is terminated by the matching -closing bracket. +followed by one or more opening brackets, the block is terminated by +the matching sequence of closing brackets. That is, declarator Pod blocks are syntactically like ordinary Perl 6 single-line comments and embedded comments. The general syntax is: @@ -318,10 +321,15 @@ by an entirely blank line). That is: ) { ... } sub fu2 (Any $bar) - #=[ This text stored in C<&fu2.WHY>, I in C<$bar.WHY>, + #=[ This text stored in C<&fu2.WHY>, not in C<$bar.WHY>, (because C is the declarator at the I of the preceding line) ] + + multi sub baz(Int $count, Str $name) + #=[ This text stored in C<&baz:(Int,Str).WHY> + (i.e. the C<.WHY> of the variant, not of the entire multisub) + ] =end code If a declarator block is I immediately preceded by an attached line @@ -363,11 +371,12 @@ which case they are concatenated with an intermediate newline: =end code -The Pod object representing each Declarator block is still appended -to the current surrounding Pod object (e.g. to C<$=POD> at the top -level). Each such Pod object has a C<.WHEREFORE> method that returns the -object or metaobject created by the declarator to which they are -attached. +The Pod object representing each Declarator block is still appended to +the current surrounding Pod object (e.g. to C<$=POD> at the top level). +Each such block representation is an object of class +C, and has a C<.WHEREFORE> method that returns +the code object or metaobject created by the declarator to which the +documentation is attached. When the L block|#How Pod is parsed and processed> renders these Pod objects, it automatically includes information about @@ -452,7 +461,8 @@ are used specifically to describe that declarand. Pod predefines a small number of standard configuration options that can be applied uniformly to any built-in block type. These include: -=begin item :term> +=begin defn +C<:nested> This option specifies that the block is to be nested within its current context. For example, nesting might be applied to block quotes, to textual @@ -491,7 +501,7 @@ nesting that might normally be applied to a paragraph. For example, to specify a block of code that should appear I its usual nesting: -=begin code :allow +=begin code :allow =comment Don't nest this code block in the usual way... B<=begin code :nested(0)> @@ -501,33 +511,34 @@ nesting: line instruction comments number code - =end code + V<=end code> =end code Note that C<:!nested> could also be used for this purpose: =begin code - =begin code :!nested + =Z<>begin code :!nested =end code -=end item +=end defn -=begin item :term> +=begin defn +C<:numbered> This option specifies that the block is to be numbered. The most common use of this option is to create L and L, but it can be applied to any block. -It is up to individual renderers to decide how to display any numbering -associated with other types of blocks. +The numbering conventions for headings and lists are specified in those +sections, but it is up to individual renderers to decide how to display +any numbering associated with other types of blocks. -=end item +Note that numbering is never explicit; it is always implied by context. -=for item :term> -This option specifies that a list item is the definition of a term. -See L<#Definition lists>. +=end defn -=begin item :term> +=begin defn +C<:formatted> This option specifies that the contents of the block should be treated as if they had one or more L placed around them. @@ -565,20 +576,25 @@ inherently cumulative. For example, if the block itself is already inside a formatting code, that formatting code will still apply, in addition to the extra "basis" and "important" formatting specified by C<:formatted>. -=end item +=end defn + +=begin defn +C<:like> -=begin item :term> This option specifies that a block or config has the same formatting properties as the type named by its value. This is useful for creating -related L. For example: +related L or for making +user-defined synonyms for existing types. For example: =begin code =config head2 :like :formatted + + =config Subhead :like =end code -=end item +=end defn -=for item :term> +=defn C<:allow> This option expects a list of formatting codes that are to be recognized within any C> codes that appear in (or are implicitly applied to) the current block. The option is most often used on C<=code> blocks to @@ -586,7 +602,9 @@ allow mark-up within those otherwise verbatim blocks, though it can be used in I block that contains verbatim text. See L<#Formatting within code blocks>. -=begin item :term> +=begin defn +C<:margin> + This option specifies a character that indicates the left margin of the contents of the block. Normally this left margin is determined by the column at which the C<=> of the opening block-delimiter occurs. For example: @@ -621,7 +639,7 @@ be convenient to guide subsequent indentations. For example: =begin code sub foo { - =begin pod :margin<|> + V<=begin> pod :margin<|> |=head1 Hey Look: Indented Pod! | |You can indent Pod in Perl 6 @@ -647,8 +665,9 @@ length of the "marginalized" indent that was just removed. This implicit margin is then used until the next line with an explicit margin marker is encountered, or the block terminates. +=end defn -=head2 Blocks +=head2 Block types Pod offers notations for specifying a wide range of standard block types... @@ -778,9 +797,9 @@ squeezed, lines filled, and any special L applied. Ordinary paragraphs consist of one or more consecutive lines of text, -each of which starts with a non-whitespace character at column 1. The -paragraph is terminated by the first blank line or block directive. -For example: +each of which starts with a non-whitespace character at (virtual) column +1. The paragraph is terminated by the first blank line or block +directive. For example: =begin code =head1 This is a heading block @@ -794,10 +813,14 @@ For example: Its text will also be squeezed and short lines filled. It is terminated by the trailing directive on the next line. - =head2 This is another heading block + =head2 This is another heading block + + This is yet another ordinary paragraph, + at the first virtual column set by the + previous directive =end code -Within a C<=pod>, C<=item>, C<=nested>, C<=END>, or +Within a C<=pod>, C<=item>, C<=defn>, C<=nested>, C<=END>, or L block, ordinary paragraphs do not require an explicit marker or delimiters, but there is also an explicit C marker (which may be used anywhere): @@ -823,7 +846,7 @@ and likewise the longer C<=for> and C<=begin>/C<=end> forms. For example: =end code As the previous example implies, when any form of explicit C block -is used, any whitespace at the start of each line is removed. +is used, any whitespace at the start of each line is removed during rendering. In addition, within a delimited C<=begin para>/C<=end para> block, any blank lines are preserved. @@ -838,7 +861,7 @@ of code, mark-up, or other textual specifications, and are rendered using a fixed-width font. A code block may be implicitly specified as one or more lines of text, -each of which starts with a whitespace character after the block's virtual +each of which starts with a whitespace character at the block's virtual left margin. The implicit code block is then terminated by a blank line. For example: @@ -849,7 +872,7 @@ For example: $which.is_specified(:by); =end code -Implicit code blocks may only be used within C<=pod>, C<=item>, +Implicit code blocks may only be used within C<=pod>, C<=item>, C<=defn>, C<=nested>, C<=END>, or L blocks. There is also an explicit C<=code> block (which can be specified within @@ -871,7 +894,7 @@ I other block type, not just C<=pod>, C<=item>, etc.): As the previous example demonstrates, within an explicit C<=code> block the code can start at the (virtual) left margin. Furthermore, lines that -start with whitespace characters after the margin then have that +start with whitespace characters after that margin have subsequent whitespace preserved exactly (in addition to the implicit nesting of the code). Explicit C<=code> blocks may also contain empty lines. @@ -1134,7 +1157,7 @@ character, the item is treated as having a C<:numbered> option: =end code To specify an I list item that starts with a literal C<#>, either -make it verbatim: +make the octothorpe verbatim: =begin code :allow =item B> introduces a comment @@ -1213,38 +1236,10 @@ which produces: =end nested -=head4 Definition lists - -To create term/definition lists, specify the term as a configuration value -of the item, and the definition as the item's contents: - -=begin code :allow - =for item B<:term> - Affected with a high degree of intellectual independence. - - =for item B<:term> - Uncommon patience in planning a revenge that is worth while. - - =for item B<:term> - Conforming to a local and mutable standard of right. - Having the quality of general expediency. -=end code - -An item that's specified as a term can still be numbered: - -=begin code :allow - =for item B<:numbered> :term - Devoid of consideration for the selfishness of others. - - =for item B<:numbered> :term - The one unpardonable sin against one's fellows. -=end code - - =head4 Unordered lists -List items that do not specify either the C<:numbered> or C<:term> options are -unordered. Typically, such lists are rendered with bullets. For example: +List items that are not C<:numbered> are treated as defining unordered +lists. Typically, such lists are rendered with bullets. For example: =begin code =item1 Reading @@ -1316,6 +1311,43 @@ As you can see, folk wisdom is often of dubious value. =end nested +=head4 Definition lists + +To create term/definition lists, use a C<=defn> block. This is +similar in effect to an C<=item> block, in that a series of C<=defn> +blocks implicitly defines a list (but which might then be rendered into +HTML using C«
...
» tags, rather than C«
    ...
» tags) + +The first non-blank line of content is treated as a term being defined, +and the remaining content is treated as the definition for the term. +For example: + +=begin code + =defn MAD + Affected with a high degree of intellectual independence. + + =defn MEEKNESS + Uncommon patience in planning a revenge that is worth while. + + =defn + MORAL + Conforming to a local and mutable standard of right. + Having the quality of general expediency. +=end code + +Like other kinds of list items, definitions can be numbered, using either an +option or a leading C<#>: + +=begin code :allow + =for defn B<:numbered> + SELFISH + Devoid of consideration for the selfishness of others. + + =defn B<#> SUCCESS + The one unpardonable sin against one's fellows. +=end code + + =head3 Nesting blocks Any block can be nested by specifying a C<:nested> option on it: @@ -1356,8 +1388,8 @@ nested: Nesting blocks can contain any other kind of block, including implicit paragraph and code blocks. Note that the relative physical indentation -of the blocks plays not role in determining their ultimate nesting. -The above is exactly equivalent to: +of the blocks plays no role in determining their ultimate nesting. +The preceding example could equally have been specified: =begin code :allow B<=begin nested> @@ -1376,12 +1408,16 @@ Simple tables can be specified in Pod using a C<=table> block. The table may be given an associated description or title using the C<:caption> option. -Columns are separated by whitespace, vertical lines (C<|>), or border -intersections (C<+>). Rows can be specified in one of two ways: either -one row per line, with no separators; or multiple lines per row with -explicit horizontal separators (whitespace, intersections (C<+>), or -horizontal lines: C<->, C<=>, C<_>) between I row. Either style -can also have an explicitly separated header row at the top. +Columns are separated by two or more consecutive whitespace characters, +or by a vertical line (C<|>) or a border intersection (C<+>), either of +which must be separated from any content by at least one whitespace +character. + +Rows can be specified in one of two ways: either one row per line, with +no separators; or multiple lines per row with explicit horizontal +separators (whitespace, intersections (C<+>), or horizontal lines: C<->, +C<=>, C<_>) between I row. Either style can also have an +explicitly separated header row at the top. Each individual table cell is separately formatted, as if it were a nested C<=para>. @@ -1433,8 +1469,9 @@ or with multi-line headers I multi-line data: =head3 Named blocks -Blocks whose names are not recognized as Pod built-ins are assumed to be -destined for specialized renderers or parser plug-ins. For example: +Blocks whose names contain at least one uppercase and one lowercase +letter are assumed to be destined for specialized renderers or parser +plug-ins. For example: =begin code =begin Xhtml @@ -1461,24 +1498,25 @@ loaded via some prior L|#How Pod is parsed and processed>. The resulting object's C<.typename> method retrieves the short name of the block type: C<'Xhtml'>, C<'Image'>, etc. The object's C<.config> -method retreives the list of configuration options (if any). The +method retrieves the list of configuration options (if any). The object's C<.contents> method retrieves a list of the block's verbatim contents. Named blocks for which no explicit class has been defined or loaded are usually not rendered by the standard renderers. -Note that all block names consisting entirely of lower-case or entirely of -upper-case letters are reserved. See L<#Semantic blocks>. +Note that all block names consisting entirely of lowercase or entirely of +uppercase letters are reserved. See L<#Semantic blocks>. =head3 Pod comments -All Pod blocks are intrinsically Perl 6 comments, but D -are comments that Pod renderers ignore too. That is, Pod blocks are -never to be rendered by any renderer. They are, of course, still -included in any internal Pod representation, and are accessible via the -Pod API...and via the C<$=POD> variable within a Perl 6 program. +All Pod blocks are intrinsically Perl 6 comments, but +D are comments that Pod renderers ignore too. +That is, they are Pod blocks that are never to be rendered by any +renderer. They are, of course, still included in any internal Pod +representation, and are accessible via the Pod API...and via the +C<$=POD> variable within a Perl 6 program. Comments are useful for meta-documentation (documenting the documentation): @@ -1513,7 +1551,6 @@ nestable block comments in Perl 6: =end code - =head3 The C<=END> block The C<=END> block is special in that all three of its forms @@ -1548,13 +1585,15 @@ program's Pod tree. just have a C<&postcircumfix:<{ }>> that inorder walks the Pod tree and retrieves every nested Pod object of the requested type?) +C<=DATA> blocks are never rendered by the standard Pod renderers. + =head3 Semantic blocks -All other uppercase block typenames are reserved for specifying standard -documentation, publishing, or source components. In particular, all -the standard components found in Perl and manpage documentation have -reserved uppercase typenames. +All uppercase block typenames except C<=END> and C<=DATA> are reserved +for specifying standard documentation, publishing, or source components. +In particular, all the standard components found in Perl and manpage +documentation have reserved uppercase typenames. Standard semantic blocks include: @@ -1573,7 +1612,7 @@ Standard semantic blocks include: =WARNING =DEPENDENCY =BUG - =SEEALSO + =SEE-ALSO =ACKNOWLEDGEMENT =AUTHOR =COPYRIGHT @@ -1651,7 +1690,8 @@ B<3.EI> =head2 Formatting codes Formatting codes provide a way to add inline mark-up to a piece of text -within the contents of (most types of) block. Formatting codes are +within the contents of (most types of) Pod block (including all +L). Formatting codes are themselves a type of block, and most of them may nest sequences of any other type of block (most often, other formatting codes). In particular, you can nest comment blocks in the middle of a formatting code: @@ -1735,7 +1775,8 @@ in C< ... > tags. The C> formatting code indicates that the contained text is a B, introducing a term that the adjacent text -elucidates. For example: +elucidates. It is the inline equivalent of a C<=defn> block. +For example: =begin code :allow There ensued a terrible moment of B>: a brief @@ -1747,7 +1788,7 @@ A definition may be given synonyms, which are specified after a vertical bar and separated by semicolons: =begin code :allow - A B> provides a way + A B> provides a way to add inline mark-up to a piece of text. =end code @@ -1882,7 +1923,7 @@ That technique still works, but it's now easier to accomplish the same goal using a verbatim formatting code: =begin code :allow - In Perl 5 POD, the B«V<»Z<>B«>» code was widely used to break up text + In Perl 5 POD, the B«V>>» code was widely used to break up text that would otherwise be considered mark-up. =end code @@ -1890,13 +1931,30 @@ Moreover, the C> code automatically treats its contents as being verbatim, which often eliminates the need for the C> as well: =begin code :allow - In Perl 5 POD, the B«C<»Z<>B«>» code was widely used to break up text + In Perl 5 POD, the B«V>>» code was widely used to break up text that would otherwise be considered mark-up. =end code The C> formatting code is the inline equivalent of a L block|#Comments>. +=head4 Comments as category markers + +Most Pod renderers will provide a mechanism that allows particular Pod +blocks to be explicitly excluded or included if they match a particular +pattern. For example, a renderer might be instructed to omit any block +that contains the pattern C. Corresponding "invisibility +markers" can then be placed inside C> comments within any block that +should not normally be displayed. For example: + +=for code :allow + class Widget is Bauble + { + has $.things; #= a collection of other stuff + #={ Z + This variable needs to be replaced for political reasons + } + } =head3 Links @@ -1917,7 +1975,9 @@ recommended that C<#> be used to mark the start of internal addresses. Standard schemes include: -=begin item :term('C and C') +=begin defn +C and C + A standard web URL. For example: =begin code :allow @@ -1933,9 +1993,10 @@ the location of the current document: L> =end code -=end item +=end defn -=begin item :term> +=begin defn +C A filename on the local system. For example: @@ -1944,17 +2005,18 @@ A filename on the local system. For example: L> or L>). =end code -Filenames that don't begin with a C or a C<~> are relative to the current -document's location: +Filenames that don't begin with a C or a C<~> are relative +to the current document's location: =begin code :allow Then, edit the local config file (that is, either L> or L>. =end code -=end item +=end defn -=begin item :term> +=begin defn +C An email address. Typically, activating this type of link invokes a mailer. For example: @@ -1963,9 +2025,10 @@ For example: Please forward bug reports to L> =end code -=end item +=end defn -=begin item :term> +=begin defn +C A link to the system manpages. For example: @@ -1974,12 +2037,13 @@ A link to the system manpages. For example: Unix L> facilities. =end code -=end item +=end defn -=begin item :term> +=begin defn +C A link to some other documentation, typically a module or part of the -core documentation; things that would normally be read with C. +core documentation; things that would normally be read with C. For example: =begin code :allow @@ -1987,30 +2051,35 @@ For example: view the results. See also: L>. =end code -=end item +=end defn -=begin item :term> +=begin defn +C -A link to the L of the specified term within -the current document. For example: +A link to the L or L +definition of the specified term within the current document. For example: =begin code :allow He was highly prone to B>: an unfortunate proclivity for employing grandiloquisms (for example, words such as "proclivity", "grandiloquism", and indeed "lexiphania"). + + B<=defn glossoligation> + Restraint of the tongue (voluntary or otherwise) =end code and later, to link back to the definition =begin code :allow - To treat his chronic L> the doctor prescribed an - immediate glossoligation or, if that proved ineffective, a complete - cephalectomy. +To treat his chronic L> the doctor prescribed an +immediate L> or, if that proved ineffective, +a complete cephalectomy. =end code -=end item +=end defn -=begin item :term and C> +=begin defn +C and C The International Standard Book Number or International Standard Serial Number for a publication. For example: @@ -2020,7 +2089,7 @@ Serial Number for a publication. For example: serial publication (L>) =end code -=end item +=end defn To refer to a specific section within a webpage, manpage, or Pod document, add the name of that section after the main link, separated by @@ -2055,6 +2124,8 @@ For example: You could also write the code L doc:Lingua::Romana::Perligata> + + His Ldefn:lexiphania>> tendencies were, alas, incurable. =end code @@ -2062,11 +2133,11 @@ For example: A second kind of linkEthe C> or BEworks in the opposite direction. Instead of directing focus out to another -document, it allows you to suck the contents of another document +document, it allows you to assimilate the contents of another document into your own. In other words, the C> formatting code takes a URI and (where possible) -places the contents of the corresponding document inline in place of the +inserts the contents of the corresponding document inline in place of the code itself. C> codes are handy for breaking out standard elements of @@ -2140,11 +2211,13 @@ Note also that, for C>, all L are treated as equivalent to C headings, and the C<=item1>/C<=item> equivalence is preserved. +A document may have as many C> placements as necessary. + =head3 Alias placements A variation on placement codes is the C> code, which is replaced -by the contents of the named alias specified within its delimiters. +by the contents of the named alias or object specified within its delimiters. For example: =begin code @@ -2156,12 +2229,31 @@ For example: laid out by A, as specified at A. =end code -All Perl 6 compile-time variables are automatically alias names as well. -So, for example, a document can refer to its own filename (as C>), -to the subroutine inside which the specific Pod is nested (as C>), -or to the current class (as C>). +Any compile-time Perl 6 object that starts with a sigil is automatically +available within an alias placement as well. Unless the object is already +a string type, it is converted to a string during document-generation by +implicitly calling C<.perl> on it. -See L<#Aliases> for details of the aliasing macro mechanism. +So, for example, a document can refer to its own filename (as +C>), or to the subroutine inside which the specific Pod is nested +(as C>), or to the current class (as C>). +Similarly, the value of any program constants defined with sigils can be +easily reproduced in documentation: + + # Actual code... + constant $GROWTH_RATE of Num where 0..* = 1.6; + + =pod + =head4 Standard Growth Rate + + The standard growth rate is assumed to be A<$GROWTH_RATE>. + +Non-mutating method calls on these objects are also allowed, so a +document can reproduce the surrounding subroutine's signature +(C>) or the type of a constant +(C>). + +See L<#Aliases> for further details of the aliasing macro mechanism. =head3 Space-preserving text @@ -2188,11 +2280,11 @@ The emergency signal is: dot dot dot dash dash dash dot dot dot. =head3 Entities -To include named Unicode or XHTML entities, use the C> code. +To include Unicode code points or HTML5 character references in a +Pod document, specify the required D using the C> code. -If the contents of the C> are a number, that number is -treated as the decimal Unicode value for the desired codepoint. -For example: +If the C> contains a number, that number is treated as the decimal +Unicode value for the desired code point. For example: Perl 6 makes considerable use of E<171> and E<187>. @@ -2204,9 +2296,9 @@ You can also use explicit binary, octal, decimal, or hexadecimal numbers Perl 6 makes considerable use of E<0d171> and E<0d187>. Perl 6 makes considerable use of E<0xAB> and E<0xBB>. -If the contents are not a number, they are interpreted as a Unicode -character name (which is always upper-case), or else as an XHTML entity. -For example: +If the C> contains anything that is not a number, the contents are +interpreted as a Unicode character name (which is always uppercase), or +else as an HTML5 named character reference. For example: Perl 6 makes considerable use of E and E. @@ -2215,10 +2307,10 @@ or, equivalently: Perl 6 makes considerable use of E and E. -Multiple consecutive entities can be specified in a single C> code, -separated by semicolons: +Multiple consecutive entities (in any format) can be specified in a +single C> code, separated by semicolons: - Perl 6 makes considerable use of E. + Perl 6 makes considerable use of E. =head3 Indexing terms @@ -2303,10 +2395,10 @@ predecessor. =end nested -=head3 User-defined formatting codes +=head3 Module-defined formatting codes Modules loaded with a L|#How Pod is parsed and processed> -can define classes to implement their own formatting codes, which can +can define classes that implement new formatting codes, which can then be specified using the C> code. An C> code must start with a colon-terminated scheme specifier. The rest of the enclosed text is treated as the (verbatim) contents of the formatting code. For example: @@ -2387,7 +2479,7 @@ The C<=config> directive allows you to prespecify standard configuration information that is applied to every block of a particular type. For example, to specify particular formatting for different levels of -heading, you could preconfigure all the heading directives with +heading, you could preconfigure all the heading blocks with appropriate formatting schemes: =begin code @@ -2437,7 +2529,7 @@ it. Like so: =begin code :allow =comment Mark this =head3 (but only this one) as being important - (in addition to the normal formatting)... + (in addition to the normal formatting)... =head3 B<:like> :formatted =end code @@ -2466,16 +2558,15 @@ subsequent instances of the code. The C<=alias> directive provides a way to define lexically scoped synonyms for longer Pod sequences, (meta)object declarators from the -code, or even entire blocks of ambient source. These synonyms can then +code, or even entire chunks of ambient source. These synonyms can then be inserted into subsequent Pod using the L formatting code>|Alias placements>. Note that C<=alias> is a fundamental Pod directive, like C<=begin> or C<=for>; there are no equivalent paragraph or delimited forms. -There are three forms of C<=alias> directive: macro aliases, code block -aliases, and declarator aliases. All three forms are lexically scoped to the -surrounding Pod block. +There are two forms of C<=alias> directive: macro aliases and contextual +aliases. Both forms are lexically scoped to the surrounding Pod block. =head3 Macro aliases @@ -2484,18 +2575,19 @@ identifier (which is usually specified in uppercase, though this is certainly not mandatory). The second argument consists of one or more lines of replacement text. -This creates a macro that can be invoked by placing the identifier in an -C> formatting code, which is then replaced by the text specified by -the innermost lexically visible C<=alias> of that name. +This creates a lexically scoped Perl 6 macro that can be invoked during +document generation by placing the identifier (i.e. the first argument +of the alias) in an C> formatting code. This formatting code is then +replaced by the text returned by new macro. -The replacement code begins at the first non-whitespace character after -the alias's identifier, and continues to the end of the line. You can -extend the replacement text over multiple lines by starting the -following line(s) with an C<=> (at the same level of indentation as the -C<=alias> directive itself) followed by at least one whitespace. Each -addition line of replacement text uses the original line's (virtual) -left margin, as specified by the indentation of the replacement text on -the C<=alias> line. +The replacement text returned by the alias macro begins at the first +non-whitespace character after the alias's identifier, and continues to +the end of the line. You can extend the replacement text over multiple +lines by starting the following line(s) with an C<=> (at the same level +of indentation as the C<=alias> directive itself) followed by at least +one whitespace. Each addition line of replacement text uses the original +line's (virtual) left margin, as specified by the indentation of the +replacement text on the C<=alias> line. For example: @@ -2515,7 +2607,7 @@ For example: would produce: -=begin output +=begin para :nested The use of Earl Irradiatem Evermore is subject to the terms and conditions laid out by 4D Kingdoms Inc, as specified at: @@ -2523,34 +2615,41 @@ would produce: =item L =item L -=end output +=end para The advantage of using aliases is, obviously, that the same alias can be reused in multiple places in the documentation. Then, if the replacement text ever has to be changed, it need only be modified in a single place: +=begin code =alias PROGNAME Count Krunchem Constantly =alias VENDOR Last Chance Receivers Intl =alias TERMS_URLS L +=end code -=head3 Code block aliases +=head3 Contextual aliases If the C<=alias> directive is specified with only a single argument -(that is, only with it's identifier), a D is created. In +(that is, with only its identifier), a D is created. In this form, the C<=alias> directive must be followed immediately (on the -next non-blank line) by a curly-delimited block of ambient code. +next non-blank line) by ambient code. -The single argument is then used as the synonym being created, and the -contents of the block, I the outermost curly braces, are used -as the replacement text. +The single argument is then used as the name of the alias being created, +and some portion of the following code is used as the value returned by the +alias macro. Note that the code block following the C<=alias> line is still treated -as real code by the Perl 6 parser, but its contents are I treated -as the replacement text of the alias. +as real code by the Perl 6 parser, but its contents are I used to +create the replacement macro of the alias. This allows the developer to +reproduce chunks of actual source code directly in the documentation, +without having to copy it. -This allows the developer to reproduce chunks of ambient source code -directly in the documentation, without having to copy it. For example: +If the code following the one-argument C<=alias> directive begins with a +sequence of one or more repetitions of any opening bracket character, +the replacement macro returns a string containing everything from the +end of that opening sequence to just before the corresponding closing +bracket sequence. For example: =begin code @@ -2561,8 +2660,7 @@ directly in the documentation, without having to copy it. For example: { my $hash = 0; for $key.split("") -> $char { - $hash *= 33; - $hash += $char.ord; + $hash = $hash*33 + $char.ord; } return $hash; } @@ -2591,32 +2689,28 @@ An ancient (but fast) hashing algorithm is used: =end nested - -=head3 Declarator aliases - -If the C<=alias> directive is specified with I arguments, it creates -a D. Declarator aliases are a variation on -L, in which the alias automatically creates a -synonym to the name of the declared object (or type) that starts on the -very next line. - -The name of the synonym created is the actual declarator keyword -(C, C, C, C, etc.) and the replacement text is -the name of the declared object or type. For example: +Alternatively, if the C<=alias> directive is I followed by an +opening bracket, it must be followed by a declarator (such as C, +C, C, etc.) The declared object then becomes the (read-only) +return value of the alias. For example: =begin code :allow - B<=alias> + B<=alias CLASSNAME> class Database::Handle { - B<=alias> + B<=alias ATTR> has IO $!handle; - B<=alias> - my Bool method open ($filename) {...} + B<=alias OPEN> + my Bool method open ($filename?) {...} + + B<=alias DEFNAME> + constant Str DEFAULT_FILENAME = 'db.log'; =for para - Note that the B> method of class B> + Note that the B> method of class B> stores the resulting low-level database handle - in its private B> attribute. + in its private B> attribute. By default, + handles are opened to the file "B>". } =end code @@ -2624,42 +2718,42 @@ the name of the declared object or type. For example: This would produce: =nested - Note that the C method of class C stores the - resulting low-level database handle in its private C<$!handle> - attribute. +Note that the C method of class C stores the +resulting low-level database handle in its private C<$!handle> +attribute. By default, handles are opened to the file "C". =head1 How Pod is parsed and processed -Pod is just a set of specialized forms of Perl 6 comment. Every Perl 6 -implementation must provide a special command-line flag that -locates, parses, and processes Pod to produce documentation. -That flag is K<-doc>. +Pod is just a collection of specialized forms of Perl 6 comment. Every +Perl 6 implementation must provide a special command-line flag that +locates, parses, and processes Pod to produce documentation. That flag +is K<--doc>. Hence, to read Pod documentation you would type things like: - perl -doc perlrun + perl --doc perlrun - perl -doc DBI::DBD::Metadata + perl --doc DBI::DBD::Metadata - perl -doc ./lib/My/Module.pm + perl --doc ./lib/My/Module.pm When the Perl 6 interpreter is run in this mode, it sets the compiler -hint C<$?DOC> to true. If the K<-doc> flag is given a value, that value +hint C<$?DOC> to true. If the K<--doc> flag is given a value, that value (with a C added) is placed in C<$?DOC>. This can be used to specify, for example, the output format desired: - perl -doc=html perldelta > perldelta.html + perl --doc=html perldelta > perldelta.html -Under K<-doc>, the interpreter runs in a special mode, parsing the +Under K<--doc>, the interpreter runs in a special mode, parsing the source code (including the Pod, as it always does) during compilation and building the program's syntax tree. However, during parsing and -initialization under K<-doc>, the interpreter only executes those +initialization under K<--doc>, the interpreter executes any C, C, and C blocks (and equivalents, such as C statements and subroutine declarations) that are preceded by the special prefix: C -When the K<-doc> is I specified on the commandline, blocks and +When the K<--doc> is I specified on the commandline, blocks and statements that are preceded by the C prefix are not executed at all. By default, once the C phase is complete, the interpreter then @@ -2708,17 +2802,17 @@ long as you remember to exit before the default C can run: } The idea is that developers will be able to add their own documentation -mechanisms simply by loading modules that install suitable DOC blocks, -to augment or override the default documentation behaviour. Such -mechanisms can then be built using code written in standard Perl 6 that -accesses C<$=POD>, as well as using the C<.WHY> and C<.WHEREFORE> -introspection methods of any constructs that have attached Pod blocks. +mechanisms simply by loading a module (via a C) to augment or +override the default documentation behaviour. Such mechanisms can then +be built using code written in standard Perl 6 that accesses C<$=POD>, +as well as using the C<.WHY> and C<.WHEREFORE> introspection methods of +any constructs that have attached Pod blocks. Note also that this mechanism means that, on many systems, you can create a self-converting documentation file like so: =begin code - #! /usr/bin/perl6 -doc + #! /usr/bin/perl6 --doc =begin pod @@ -2728,6 +2822,9 @@ create a self-converting documentation file like so: convert it to a readable text representation. =head2 Et cetera + ... + + =end pod =end code @@ -2746,7 +2843,7 @@ create a self-converting documentation file like so: C<=for> Start of an implicitly (blank-line) terminated block C<=alias> Define a Pod macro -=end table :nested +=end table =head2 Blocks @@ -2756,6 +2853,7 @@ create a self-converting documentation file like so: ______________ ___________________________________________________ C<=code> Verbatim pre-formatted sample source code C<=comment> Content to be ignored by all renderers + C<=defn> Definition of a term C<=head>R Ith-level heading C<=input> Pre-formatted sample input C<=item> First-level list item @@ -2763,6 +2861,7 @@ create a self-converting documentation file like so: C<=nested> Nest block contents within the current context C<=output> Pre-formatted sample output C<=para> Ordinary paragraph + C<=pod> No "ambient" blocks inside C<=table> Simple rectangular table C<=DATA> Perl 6 data section C<=END> No ambient blocks after this point @@ -2777,7 +2876,7 @@ create a self-converting documentation file like so: Formatting code Specifies _______________ ___________________________________________________ - C> Replaced by contents of specified macro + C> Replaced by contents of specified macro/object C> Basis/focus of sentence (typically rendered bold) C> Code (typically rendered fixed-width) C> Definition (C|R;R;...>>)