Manual Pages for UNIX Darwin command on man Pod::Simple::Subclassing
MyWebUniversity

Manual Pages for UNIX Darwin command on man Pod::Simple::Subclassing

Pod::Simple::SubclassinUgs(e3r)Contributed Perl DocumentPaotdi:o:nSimple::Subclassing(3)

NAME

Pod::Simple::Subclassing - write a formatter as a Pod::Simple subclass

SYNOPSIS

package Pod::SomeFormatter; use Pod::Simple; @ISA = qw(Pod::Simple);

$VERSION = '1.01';

use strict; sub handleelementstart {

my($parser, $elementname, $attrhashr) = @;

... } sub handleelementend {

my($parser, $elementname) = @;

... } sub handletext {

my($parser, $text) = @;

... } 1;

DESCRIPTION

This document is about using Pod::Simple to write a Pod processor, generally a Pod formatter. If you just want to know about using an existing Pod formatter, instead see its documentation and see also the docs in Pod::Simple. The zeroeth step in writing a Pod formatter is to make sure that there isn't already a decent one in CPAN. See , and run a search on the name of the format you want to render to. Also consider joining the Pod People list

and asking whether

anyone has a formatter for that format - maybe someone cobbled one

together but just hasn't released it. The first step in writing a Pod processor is to read perlpodspec, which contains notes information on writing a Pod parser (which has been largely taken care of by Pod::Simple), but also a lot of requirements and recommendations for writing a formatter. The second step is to actually learn the format you're planning to

format to - or at least as much as you need to know to represent Pod,

which probably isn't much. The third step is to pick which of Pod::Simple's interfaces you want to

use - the basic interface via Pod::Simple or Pod::Simple::Methody is

event-based, sort of like HTML::Parser's interface, or sort of like

XML::Parser's "Handlers" interface), but Pod::Simple::PullParser

provides a token-stream interface, sort of like HTML::TokeParser's

interface; Pod::Simple::SimpleTree provides a simple tree interface,

rather like XML::Parser's "Tree" interface. Users familiar with XML-

handling will find one of these styles relatively familiar; but if you would be even more at home with XML, there are classes that produce an XML representation of the Pod stream, notably Pod::Simple::XMLOutStream; you can feed the output of such a class to whatever XML parsing system you are most at home with. The last step is to write your code based on how the events (or tokens,

or tree-nodes, or the XML, or however you're parsing) will map to

constructs in the output format. Also sure to consider how to escape text nodes containing arbitrary text, and also what to do with text nodes that represent preformatted text (from verbatim sections). EEvveennttss TODO intro... mention that events are supplied for implicits, like for missing >'s In the following section, we use XML to represent the event structure associated with a particular construct. That is, TODO

"$parser->handleelementstart( elementname, attrhashref )"

"$parser->handleelementend( elementname )"

"$parser->handletext( textstring )"

TODO describe events with an elementname of Document Parsing a document produces this event structure: ...all events... The value of the startline attribute will be the line number of the first Pod directive in the document. If there is no Pod in the given document, then the event structure will be this: In that case, the value of the startline attribute will not be meaningful; under current implementations, it will probably be the line number of the last line in the file. events with an elementname of Para

Parsing a plain (non-verbatim, non-directive, non-data) paragraph

in a Pod document produces this event structure: ...all events in this paragraph... The value of the startline attribute will be the line number of the start of the paragraph. For example, parsing this paragraph of Pod: The value of the I attribute will be the line number of the start of the paragraph. produces this event structure: The value of the startline attribute will be the line number of the first Pod directive in the document. events with an elementname of B, C, F, or I. Parsing a B<...> formatting code (or of course any of its semantically identical syntactic variants B<< ... >>, or B<<<< ... >>>>, etc.) produces this event structure: ...stuff... Currently, there are no attributes conveyed. Parsing C, F, or I codes produce the same structure, with only a different element name. If your parser object has been set to accept other formatting

codes, then they will be presented like these B/C/F/I codes -

i.e., without any attributes. events with an elementname of S Normally, parsing an S<...> sequence produces this event structure, just as if it were a B/C/F/I code: ...stuff... However, Pod::Simple (and presumably all derived parsers) offers the "nbspforS" option which, if enabled, will suppress all S

events, and instead change all spaces in the content to non-

breaking spaces. This is intended for formatters that output to a format that has no code that means the same as S<...>, but which

has a code/character that means non-breaking space.

events with an elementname of X Normally, parsing an X<...> sequence produces this event structure, just as if it were a B/C/F/I code: ...stuff... However, Pod::Simple (and presumably all derived parsers) offers the "nixXcodes" option which, if enabled, will suppress all X events and ignore their content. For formatters/processors that don't use X events, this is presumably quite useful. events with an elementname of L Because the L<...> is the most complex construct in the language, it should not surprise you that the events it generates are the most complex in the language. Most of complexity is hidden away in the attribute values, so for those of you writing a Pod formatter

that produces a non-hypertextual format, you can just ignore the

attributes and treat an L event structure like a formatting element that (presumably) doesn't actually produce a change in formatting. That is, the content of the L event structure (as opposed to its attributes) is always what text should be displayed. There are, at first glance, three kinds of L links: URL, man, and pod. When a L code is parsed, it produces this event structure:

thaturl The "type="url"" attribute is always specified for this type of L code. For example, this Pod source: L produces this event structure:

http://www.perl.com/CPAN/authors/ When a L code is parsed (and these are fairly rare and not terribly useful), it produces this event structure:

manpage(section) The "type="man"" attribute is always specified for this type of L code. For example, this Pod source: L produces this event structure:

crontab(5) In the rare cases where a man page link has a specified, that text appears in a section attribute. For example, this Pod source: L will produce this event structure:

"ENVIRONMENT" in crontab(5) In the rare case where the Pod document has code like L, then the sometext will appear as the content of the element, the manpage(section) text will appear only as the value of the to attribute, and there will be no

"content-implicit="yes"" attribute (whose presence means that the

Pod parser had to infer what text should appear as the link text -

as opposed to cases where that attribute is absent, which means that the Pod parser did not have to infer the link text, because that L code explicitly specified some link text.) For example, this Pod source: L will produce this event structure: hell itself! The last type of L structure is for links to/within Pod documents. It is the most complex because it can have a to attribute, or a section attribute, or both. The "type="pod"" attribute is always specified for this type of L code. In the most common case, the simple case of a L code produces this event structure:

podpage For example, this Pod source: L produces this event structure:

Net::Ping

In cases where there is link-text explicitly specified, it is to be

found in the content of the element (and not the attributes), just as with the L case discussed above. For example, this Pod source: L produces this event structure: Perl Error Messages In cases of links to a section in the current Pod document, there is a section attribute instead of a to attribute. For example, this Pod source: L produces this event structure:

"Member Data" As another example, this Pod source: L produces this event structure: the various attributes In cases of links to a section in a different Pod document, there are both a section attribute and a to attribute. For example, this Pod source: L produces this event structure:

"Basic BLOCKs and Switch Statements" in perlsyn As another example, this Pod source: L produces this event structure: SWITCH statements Incidentally, note that we do not distinguish between these syntaxes: L L<"Member Data"> L L [deprecated syntax] That is, they all produce the same event structure, namely:

"Member Data"

events with an elementname of E or Z While there are Pod codes E<...> and Z<>, these do not produce any

E or Z events - that is, there are no such events as E or Z.

events with an elementname of Verbatim When a Pod verbatim paragraph (AKA "codeblock") is parsed, it produces this event structure: ...text... The value of the startline attribute will be the line number of the first line of this verbatim block. The xml:space attribute is always present, and always has the value "preserve". The text content will have tabs already expanded. events with an elementname of head1 .. head4 When a "=head1 ..." directive is parsed, it produces this event structure: ...stuff... For example, a directive consisting of this: =head1 Options to C et al. will produce this event structure: Options to new et al. "=head2" thru "=head4" directives are the same, except for the element names in the event structure.

events with an elementname of over-bullet

When an "=over ... =back" block is parsed where the items are a bulletted list, it will produce this event structure:

...Stuff...

...more item-bullets...

The value of the indent attribute is whatever value is after the "=over" directive, as in "=over 8". If no such value is specified in the directive, then the indent attribute has the value "4". For example, this Pod source: =over =item * Stuff =item * Bar I! =back produces this event structure:

Stuff

Bar baz!

events with an elementname of over-number

When an "=over ... =back" block is parsed where the items are a numbered list, it will produce this event structure:

...Stuff...

...more item-number...

This is like the "over-bullet" event structure; but note that the

contents are "item-number" instead of "item-bullet", and note that

they will have a "number" attribute, which some formatters/processors may ignore (since, for example, there's no need for it in HTML when producing an "
  • ...
  • ...
" structure), but which any processor may use.

Note that the values for the number attributes of "item-number"

elements in a given "over-number" area will start at 1 and go up by

one each time. If the Pod source doesn't follow that order (even though it really should should!), whatever numbers it has will be ignored (with the correct values being put in the number attributes), and an error message might be issued to the user.

events with an elementname of over-text

These events are are somewhat unlike the other over-* structures,

as far as what their contents are. When an "=over ... =back" block is parsed where the items are a list of text "subheadings", it will produce this event structure:

...stuff...

...stuff (generally Para or Verbatim elements)...

...more item-text and/or stuff...

The indent attribute is as with the other over-* events.

For example, this Pod source: =over =item Foo Stuff =item Bar I! Quux =back produces this event structure:

Foo

Stuff

Bar baz !

Quux

events with an elementname of over-block

These events are are somewhat unlike the other over-* structures,

as far as what their contents are. When an "=over ... =back" block is parsed where there are no items, it will produce this event structure:

...stuff (generally Para or Verbatim elements)...

The indent attribute is as with the other over-* events.

For example, this Pod source: =over For cutting off our trade with all parts of the world For transporting us beyond seas to be tried for pretended offenses He is at this time transporting large armies of foreign mercenaries to complete the works of death, desolation and tyranny, already begun with circumstances of cruelty and perfidy scarcely paralleled in the most barbarous ages, and totally unworthy the head of a civilized nation. =cut will produce this event structure:

For cutting off our trade with all parts of the world For transporting us beyond seas to be tried for pretended offenses He is at this time transporting large armies of [...more text...]

events with an elementname of item-bullet

See "events with an elementname of over-bullet", above.

events with an elementname of item-number

See "events with an elementname of over-number", above.

events with an elementname of item-text

See "events with an elementname of over-text", above.

events with an elementname of for TODO... events with an elementname of Data TODO... More Pod::Simple Methods Pod::Simple provides a lot of methods that aren't generally interesting to the end user of an existing Pod formatter, but some of which you might find useful in writing a Pod formatter. They are listed below. The first several methods (the accept* methods) are for declaring the capabilites of your parser, notably what "=for targetname" sections it's interested in, what extra N<...> codes it accepts beyond the ones described in the perlpod.

"$parser->accepttargets( SOMEVALUE )"

As the parser sees sections like: =for html or =begin html =end html ...the parser will ignore these sections unless your subclass has specified that it wants to see sections targetted to "html" (or whatever the formatter name is). If you want to process all sections, even if they're not targetted for you, call this before you start parsing:

$parser->accepttargets('*');

"$parser->accepttargetsastext( SOMEVALUE )"

This is like accepttargets, except that it specifies also that the content of sections for this target should be treated as Pod text even if the target name in "=for targetname" doesn't start with a ":". At time of writing, I don't think you'll need to use this.

"$parser->acceptcodes( Codename, Codename... )"

This tells the parser that you accept additional formatting codes, beyond just the standard ones (I B C L F S X, plus the two weird ones you don't actually see in the parse tree, Z and E). For example, to also accept codes "N", "R", and "W":

$parser->acceptcodes( qw( N R W ) );

TTOODDOO:: ddooccuummeenntt hhooww tthhiiss iinntteerraaccttss wwiitthh ==eexxtteenndd,, aanndd lloonngg eelleemmeenntt nnaammeess

"$parser->acceptdirectiveasdata( directivename )"

"$parser->acceptdirectiveasverbatim( directivename )"

"$parser->acceptdirectiveasprocessed( directivename )"

In the unlikely situation that you need to tell the parser that you will accept additional directives ("=foo" things), you need to first set the parset to treat its content as data (i.e., not really processed at all), or as verbatim (mostly just expanding tabs), or as processed text (parsing formatting codes like B<...>). For example, to accept a new directive "=method", you'd presumably use:

$parser->acceptdirectiveasprocessed("method");

so that you could have Pod lines like:

=method I<$whatever> thing B

Making up your own directives breaks compatibility with other Pod formatters, in a way that using "=for target ..." lines doesn't; however, you may find this useful if you're making a Pod superset format where you don't need to worry about compatibility.

"$parser->nbspforS( BOOLEAN );"

Setting this attribute to a true value (and by default it is false) will turn "S<...>" sequences into sequences of words separated by

"\xA0" (non-breaking space) characters. For example, it will take

this: I like S, don't you? and treat it as if it were: I like DutchEappleEpie, don't you? This is handy for output formats that don't have anything quite

like an "S<...>" code, but which do have a code for non-breaking

space. There is currently no method for going the other way; but I can probably provide one upon request.

"$parser->versionreport()"

This returns a string reporting the $VERSION value from your module

(and its classname) as well as the $VERSION value of Pod::Simple.

Note that perlpodspec requires output formats (wherever possible) to note this detail in a comment in the output format. For example, for some kind of SGML output format:

print OUT "versionreport, "\n ->";

"$parser->podparacount()"

This returns the count of Pod paragraphs seen so far.

"$parser->linecount()"

This is the current line number being parsed. But you might find the "linenumber" event attribute more accurate, when it is present.

"$parser->nixXcodes( SOMEVALUE )"

This attribute, when set to a true value (and it is false by default) ignores any "X<...>" sequences in the document being parsed. Many formats don't actually use the content of these codes, so have no reason to process them.

"$parser->mergetext( SOMEVALUE )"

This attribute, when set to a true value (and it is false by default) makes sure that only one event (or token, or node) will be created for any single contiguous sequence of text. For example, consider this somewhat contrived example: I just LOVE Z<>hotE<32>apple pie! When that is parsed and events are about to be called on it, it may actually seem to be four different text events, one right after another: one event for "I just LOVE ", one for "hot", one for " ", and one for "apple pie!". But if you have mergetext on, then you're guaranteed that it will be fired as one text event: "I just LOVE hot apple pie!".

"$parser->codehandler( CODEREF )"

This specifies code that should be called when a code line is seen (i.e., a line outside of the Pod). Normally this is undef, meaning that no code should be called. If you provide a routine, it should start out like this:

sub getcodeline { # or whatever you'll call it

my($line, $linenumber, $parser) = @;

... } Note, however, that sometimes the Pod events aren't processed in

exactly the same order as the code lines are - i.e., if you have a

file with Pod, then code, then more Pod, sometimes the code will be processed (via whatever you have codehandler call) before the all of the preceding Pod has been processed.

"$parser->cuthandler( CODEREF )"

This is just like the codehandler attribute, except that it's for "=cut" lines, not code lines. The same caveats apply. "=cut" lines are unlikely to be interesting, but this is included for completeness.

"$parser->whine( linenumber, complaint string )"

This notes a problem in the Pod, which will be reported to in the "Pod Errors" section of the document and/or send to STDERR, depending on the values of the attributes "nowhining", "noerratasection", and "complainstderr".

"$parser->scream( linenumber, complaint string )"

This notes an error like "whine" does, except that it is not suppressable with "nowhining". This should be used only for very serious errors.

"$parser->sourcedead(1)"

This aborts parsing of the current document, by switching on the flag that indicates that EOF has been seen. In particularly drastic cases, you might want to do this. It's rather nicer than just calling "die"!

"$parser->hidelinenumbers( SOMEVALUE )"

Some subclasses that indescriminately dump event attributes (well, except for ones beginning with "~") can use this object attribute for refraining to dump the "startline" attribute.

"$parser->nowhining( SOMEVALUE )"

This attribute, if set to true, will suppress reports of non-fatal

error messages. The default value is false, meaning that complaints are reported. How they get reported depends on the values of the attributes "noerratasection" and "complainstderr".

"$parser->noerratasection( SOMEVALUE )"

This attribute, if set to true, will suppress generation of an

errata section. The default value is false - i.e., an errata

section will be generated.

"$parser->complainstderr( SOMEVALUE )"

This attribute, if set to true will send complaints to STDERR. The

default value is false - i.e., complaints do not go to STDERR.

"$parser->bareoutput( SOMEVALUE )"

Some formatter subclasses use this as a flag for whether output should have prologue and epilogue code omitted. For example, setting this to true for an HTML formatter class should omit the "......" prologue and the "" epilogue. If you want to set this to true, you should probably also set "nowhining" or at least "noerratasection" to true.

"$parser->preservewhitespace( SOMEVALUE )"

If you set this attribute to a true value, the parser will try to preserve whitespace in the output. This means that such formatting conventions as two spaces after periods will be preserved by the parser. This is primarily useful for output formats that treat whitespace as significant (such as text or *roff, but not HTML).

SEE ALSO

Pod::Simple - event-based Pod-parsing framework

Pod::Simple::Methody - like Pod::Simple, but each sort of event calls

its own method (like "starthead3")

Pod::Simple::PullParser - a Pod-parsing framework like Pod::Simple,

but with a token-stream interface

Pod::Simple::SimpleTree - a Pod-parsing framework like Pod::Simple,

but with a tree interface

Pod::Simple::Checker - a simple Pod::Simple subclass that reads

documents, and then makes a plaintext report of any errors found in the document

Pod::Simple::DumpAsXML - for dumping Pod documents as tidily indented

XML, showing each event on its own line

Pod::Simple::XMLOutStream - dumps a Pod document as XML (without

introducing extra whitespace as Pod::Simple::DumpAsXML does).

Pod::Simple::DumpAsText - for dumping Pod documents as tidily indented

text, showing each event on its own line

Pod::Simple::LinkSection - class for objects representing the values

of the TODO and TODO attributes of L<...> elements

Pod::Escapes - the module the Pod::Simple uses for evaluating E<...>

content

Pod::Simple::Text - a simple plaintext formatter for Pod

Pod::Simple::TextContent - like Pod::Simple::Text, but makes no effort

for indent or wrap the text being formatted perlpod perlpodspec perldoc COPYRIGHT AND DISCLAIMERS Copyright (c) 2002 Sean M. Burke. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. AUTHOR Sean M. Burke "sburke@cpan.org"

perl v5.8.8 2006-07-07 Pod::Simple::Subclassing(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™