.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Pod::Parser 3"
.TH Pod::Parser 3 "2002-11-24" "perl v5.8.0" "Perl Programmers Reference Guide"
.SH "NAME"
Pod::Parser \- base class for creating POD filters and translators
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Pod::Parser;
.Ve
.PP
.Vb 2
\& package MyParser;
\& @ISA = qw(Pod::Parser);
.Ve
.PP
.Vb 10
\& sub command {
\& my ($parser, $command, $paragraph, $line_num) = @_;
\& ## Interpret the command and its text; sample actions might be:
\& if ($command eq 'head1') { ... }
\& elsif ($command eq 'head2') { ... }
\& ## ... other commands and their actions
\& my $out_fh = $parser->output_handle();
\& my $expansion = $parser->interpolate($paragraph, $line_num);
\& print $out_fh $expansion;
\& }
.Ve
.PP
.Vb 6
\& sub verbatim {
\& my ($parser, $paragraph, $line_num) = @_;
\& ## Format verbatim paragraph; sample actions might be:
\& my $out_fh = $parser->output_handle();
\& print $out_fh $paragraph;
\& }
.Ve
.PP
.Vb 7
\& sub textblock {
\& my ($parser, $paragraph, $line_num) = @_;
\& ## Translate/Format this block of text; sample actions might be:
\& my $out_fh = $parser->output_handle();
\& my $expansion = $parser->interpolate($paragraph, $line_num);
\& print $out_fh $expansion;
\& }
.Ve
.PP
.Vb 8
\& sub interior_sequence {
\& my ($parser, $seq_command, $seq_argument) = @_;
\& ## Expand an interior sequence; sample actions might be:
\& return "*$seq_argument*" if ($seq_command eq 'B');
\& return "`$seq_argument'" if ($seq_command eq 'C');
\& return "_${seq_argument}_'" if ($seq_command eq 'I');
\& ## ... other sequence commands and their resulting text
\& }
.Ve
.PP
.Vb 1
\& package main;
.Ve
.PP
.Vb 5
\& ## Create a parser object and have it parse file whose name was
\& ## given on the command-line (use STDIN if no files were given).
\& $parser = new MyParser();
\& $parser->parse_from_filehandle(\e*STDIN) if (@ARGV == 0);
\& for (@ARGV) { $parser->parse_from_file($_); }
.Ve
.SH "REQUIRES"
.IX Header "REQUIRES"
perl5.005, Pod::InputObjects, Exporter, Symbol, Carp
.SH "EXPORTS"
.IX Header "EXPORTS"
Nothing.
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
\&\fBPod::Parser\fR is a base class for creating \s-1POD\s0 filters and translators.
It handles most of the effort involved with parsing the \s-1POD\s0 sections
from an input stream, leaving subclasses free to be concerned only with
performing the actual translation of text.
.PP
\&\fBPod::Parser\fR parses PODs, and makes method calls to handle the various
components of the \s-1POD\s0. Subclasses of \fBPod::Parser\fR override these methods
to translate the \s-1POD\s0 into whatever output format they desire.
.SH "QUICK OVERVIEW"
.IX Header "QUICK OVERVIEW"
To create a \s-1POD\s0 filter for translating \s-1POD\s0 documentation into some other
format, you create a subclass of \fBPod::Parser\fR which typically overrides
just the base class implementation for the following methods:
.IP "\(bu" 2
\&\fB\f(BIcommand()\fB\fR
.IP "\(bu" 2
\&\fB\f(BIverbatim()\fB\fR
.IP "\(bu" 2
\&\fB\f(BItextblock()\fB\fR
.IP "\(bu" 2
\&\fB\f(BIinterior_sequence()\fB\fR
.PP
You may also want to override the \fB\f(BIbegin_input()\fB\fR and \fB\f(BIend_input()\fB\fR
methods for your subclass (to perform any needed per-file and/or
per-document initialization or cleanup).
.PP
If you need to perform any preprocesssing of input before it is parsed
you may want to override one or more of \fB\f(BIpreprocess_line()\fB\fR and/or
\&\fB\f(BIpreprocess_paragraph()\fB\fR.
.PP
Sometimes it may be necessary to make more than one pass over the input
files. If this is the case you have several options. You can make the
first pass using \fBPod::Parser\fR and override your methods to store the
intermediate results in memory somewhere for the \fB\f(BIend_pod()\fB\fR method to
process. You could use \fBPod::Parser\fR for several passes with an
appropriate state variable to control the operation for each pass. If
your input source can't be reset to start at the beginning, you can
store it in some other structure as a string or an array and have that
structure implement a \fB\f(BIgetline()\fB\fR method (which is all that
\&\fB\f(BIparse_from_filehandle()\fB\fR uses to read input).
.PP
Feel free to add any member data fields you need to keep track of things
like current font, indentation, horizontal or vertical position, or
whatever else you like. Be sure to read \*(L"\s-1PRIVATE\s0 \s-1METHODS\s0 \s-1AND\s0 \s-1DATA\s0\*(R"
to avoid name collisions.
.PP
For the most part, the \fBPod::Parser\fR base class should be able to
do most of the input parsing for you and leave you free to worry about
how to intepret the commands and translate the result.
.PP
Note that all we have described here in this quick overview is the
simplest most straightforward use of \fBPod::Parser\fR to do stream-based
parsing. It is also possible to use the \fBPod::Parser::parse_text\fR function
to do more sophisticated tree-based parsing. See \*(L"\s-1TREE\-BASED\s0 \s-1PARSING\s0\*(R".
.SH "PARSING OPTIONS"
.IX Header "PARSING OPTIONS"
A \fIparse-option\fR is simply a named option of \fBPod::Parser\fR with a
value that corresponds to a certain specified behavior. These various
behaviors of \fBPod::Parser\fR may be enabled/disabled by setting
or unsetting one or more \fIparse-options\fR using the \fB\f(BIparseopts()\fB\fR method.
The set of currently accepted parse-options is as follows:
.IP "\fB\-want_nonPODs\fR (default: unset)" 3
.IX Item "-want_nonPODs (default: unset)"
Normally (by default) \fBPod::Parser\fR will only provide access to
the \s-1POD\s0 sections of the input. Input paragraphs that are not part
of the POD-format documentation are not made available to the caller
(not even using \fB\f(BIpreprocess_paragraph()\fB\fR). Setting this option to a
non\-empty, non-zero value will allow \fB\f(BIpreprocess_paragraph()\fB\fR to see
non-POD sections of the input as well as \s-1POD\s0 sections. The \fB\f(BIcutting()\fB\fR
method can be used to determine if the corresponding paragraph is a \s-1POD\s0
paragraph, or some other input paragraph.
.IP "\fB\-process_cut_cmd\fR (default: unset)" 3
.IX Item "-process_cut_cmd (default: unset)"
Normally (by default) \fBPod::Parser\fR handles the \f(CW\*(C`=cut\*(C'\fR \s-1POD\s0 directive
by itself and does not pass it on to the caller for processing. Setting
this option to a non\-empty, non-zero value will cause \fBPod::Parser\fR to
pass the \f(CW\*(C`=cut\*(C'\fR directive to the caller just like any other \s-1POD\s0 command
(and hence it may be processed by the \fB\f(BIcommand()\fB\fR method).
.Sp
\&\fBPod::Parser\fR will still interpret the \f(CW\*(C`=cut\*(C'\fR directive to mean that
\&\*(L"cutting mode\*(R" has been (re)entered, but the caller will get a chance
to capture the actual \f(CW\*(C`=cut\*(C'\fR paragraph itself for whatever purpose
it desires.
.IP "\fB\-warnings\fR (default: unset)" 3
.IX Item "-warnings (default: unset)"
Normally (by default) \fBPod::Parser\fR recognizes a bare minimum of
pod syntax errors and warnings and issues diagnostic messages
for errors, but not for warnings. (Use \fBPod::Checker\fR to do more
thorough checking of \s-1POD\s0 syntax.) Setting this option to a non\-empty,
non-zero value will cause \fBPod::Parser\fR to issue diagnostics for
the few warnings it recognizes as well as the errors.
.PP
Please see \*(L"\fIparseopts()\fR\*(R" for a complete description of the interface
for the setting and unsetting of parse\-options.
.SH "RECOMMENDED SUBROUTINE/METHOD OVERRIDES"
.IX Header "RECOMMENDED SUBROUTINE/METHOD OVERRIDES"
\&\fBPod::Parser\fR provides several methods which most subclasses will probably
want to override. These methods are as follows:
.SH "\fB\fP\f(BIcommand()\fP\fB\fP"
.IX Header "command()"
.Vb 1
\& $parser->command($cmd,$text,$line_num,$pod_para);
.Ve
.PP
This method should be overridden by subclasses to take the appropriate
action when a \s-1POD\s0 command paragraph (denoted by a line beginning with
\&\*(L"=\*(R") is encountered. When such a \s-1POD\s0 directive is seen in the input,
this method is called and is passed:
.ie n .IP "$cmd" 3
.el .IP "\f(CW$cmd\fR" 3
.IX Item "$cmd"
the name of the command for this \s-1POD\s0 paragraph
.ie n .IP "$text" 3
.el .IP "\f(CW$text\fR" 3
.IX Item "$text"
the paragraph text for the given \s-1POD\s0 paragraph command.
.ie n .IP "$line_num" 3
.el .IP "\f(CW$line_num\fR" 3
.IX Item "$line_num"
the line-number of the beginning of the paragraph
.ie n .IP "$pod_para" 3
.el .IP "\f(CW$pod_para\fR" 3
.IX Item "$pod_para"
a reference to a \f(CW\*(C`Pod::Paragraph\*(C'\fR object which contains further
information about the paragraph command (see Pod::InputObjects
for details).
.PP
\&\fBNote\fR that this method \fIis\fR called for \f(CW\*(C`=pod\*(C'\fR paragraphs.
.PP
The base class implementation of this method simply treats the raw \s-1POD\s0
command as normal block of paragraph text (invoking the \fB\f(BItextblock()\fB\fR
method with the command paragraph).
.SH "\fB\fP\f(BIverbatim()\fP\fB\fP"
.IX Header "verbatim()"
.Vb 1
\& $parser->verbatim($text,$line_num,$pod_para);
.Ve
.PP
This method may be overridden by subclasses to take the appropriate
action when a block of verbatim text is encountered. It is passed the
following parameters:
.ie n .IP "$text" 3
.el .IP "\f(CW$text\fR" 3
.IX Item "$text"
the block of text for the verbatim paragraph
.ie n .IP "$line_num" 3
.el .IP "\f(CW$line_num\fR" 3
.IX Item "$line_num"
the line-number of the beginning of the paragraph
.ie n .IP "$pod_para" 3
.el .IP "\f(CW$pod_para\fR" 3
.IX Item "$pod_para"
a reference to a \f(CW\*(C`Pod::Paragraph\*(C'\fR object which contains further
information about the paragraph (see Pod::InputObjects
for details).
.PP
The base class implementation of this method simply prints the textblock
(unmodified) to the output filehandle.
.SH "\fB\fP\f(BItextblock()\fP\fB\fP"
.IX Header "textblock()"
.Vb 1
\& $parser->textblock($text,$line_num,$pod_para);
.Ve
.PP
This method may be overridden by subclasses to take the appropriate
action when a normal block of \s-1POD\s0 text is encountered (although the base
class method will usually do what you want). It is passed the following
parameters:
.ie n .IP "$text" 3
.el .IP "\f(CW$text\fR" 3
.IX Item "$text"
the block of text for the a \s-1POD\s0 paragraph
.ie n .IP "$line_num" 3
.el .IP "\f(CW$line_num\fR" 3
.IX Item "$line_num"
the line-number of the beginning of the paragraph
.ie n .IP "$pod_para" 3
.el .IP "\f(CW$pod_para\fR" 3
.IX Item "$pod_para"
a reference to a \f(CW\*(C`Pod::Paragraph\*(C'\fR object which contains further
information about the paragraph (see Pod::InputObjects
for details).
.PP
In order to process interior sequences, subclasses implementations of
this method will probably want to invoke either \fB\f(BIinterpolate()\fB\fR or
\&\fB\f(BIparse_text()\fB\fR, passing it the text block \f(CW$text\fR, and the corresponding
line number in \f(CW$line_num\fR, and then perform any desired processing upon
the returned result.
.PP
The base class implementation of this method simply prints the text block
as it occurred in the input stream).
.SH "\fB\fP\f(BIinterior_sequence()\fP\fB\fP"
.IX Header "interior_sequence()"
.Vb 1
\& $parser->interior_sequence($seq_cmd,$seq_arg,$pod_seq);
.Ve
.PP
This method should be overridden by subclasses to take the appropriate
action when an interior sequence is encountered. An interior sequence is
an embedded command within a block of text which appears as a command
name (usually a single uppercase character) followed immediately by a
string of text which is enclosed in angle brackets. This method is
passed the sequence command \f(CW$seq_cmd\fR and the corresponding text
\&\f(CW$seq_arg\fR. It is invoked by the \fB\f(BIinterpolate()\fB\fR method for each interior
sequence that occurs in the string that it is passed. It should return
the desired text string to be used in place of the interior sequence.
The \f(CW$pod_seq\fR argument is a reference to a \f(CW\*(C`Pod::InteriorSequence\*(C'\fR
object which contains further information about the interior sequence.
Please see Pod::InputObjects for details if you need to access this
additional information.
.PP
Subclass implementations of this method may wish to invoke the
\&\fB\f(BInested()\fB\fR method of \f(CW$pod_seq\fR to see if it is nested inside
some other interior-sequence (and if so, which kind).
.PP
The base class implementation of the \fB\f(BIinterior_sequence()\fB\fR method
simply returns the raw text of the interior sequence (as it occurred
in the input) to the caller.
.SH "OPTIONAL SUBROUTINE/METHOD OVERRIDES"
.IX Header "OPTIONAL SUBROUTINE/METHOD OVERRIDES"
\&\fBPod::Parser\fR provides several methods which subclasses may want to override
to perform any special pre/post\-processing. These methods do \fInot\fR have to
be overridden, but it may be useful for subclasses to take advantage of them.
.SH "\fB\fP\f(BInew()\fP\fB\fP"
.IX Header "new()"
.Vb 1
\& my $parser = Pod::Parser->new();
.Ve
.PP
This is the constructor for \fBPod::Parser\fR and its subclasses. You
\&\fIdo not\fR need to override this method! It is capable of constructing
subclass objects as well as base class objects, provided you use
any of the following constructor invocation styles:
.PP
.Vb 3
\& my $parser1 = MyParser->new();
\& my $parser2 = new MyParser();
\& my $parser3 = $parser2->new();
.Ve
.PP
where \f(CW\*(C`MyParser\*(C'\fR is some subclass of \fBPod::Parser\fR.
.PP
Using the syntax \f(CW\*(C`MyParser::new()\*(C'\fR to invoke the constructor is \fInot\fR
recommended, but if you insist on being able to do this, then the
subclass \fIwill\fR need to override the \fB\f(BInew()\fB\fR constructor method. If
you do override the constructor, you \fImust\fR be sure to invoke the
\&\fB\f(BIinitialize()\fB\fR method of the newly blessed object.
.PP
Using any of the above invocations, the first argument to the
constructor is always the corresponding package name (or object
reference). No other arguments are required, but if desired, an
associative array (or hash\-table) my be passed to the \fB\f(BInew()\fB\fR
constructor, as in:
.PP
.Vb 2
\& my $parser1 = MyParser->new( MYDATA => $value1, MOREDATA => $value2 );
\& my $parser2 = new MyParser( -myflag => 1 );
.Ve
.PP
All arguments passed to the \fB\f(BInew()\fB\fR constructor will be treated as
key/value pairs in a hash\-table. The newly constructed object will be
initialized by copying the contents of the given hash-table (which may
have been empty). The \fB\f(BInew()\fB\fR constructor for this class and all of its
subclasses returns a blessed reference to the initialized object (hash\-table).
.SH "\fB\fP\f(BIinitialize()\fP\fB\fP"
.IX Header "initialize()"
.Vb 1
\& $parser->initialize();
.Ve
.PP
This method performs any necessary object initialization. It takes no
arguments (other than the object instance of course, which is typically
copied to a local variable named \f(CW$self\fR). If subclasses override this
method then they \fImust\fR be sure to invoke \f(CW\*(C`$self\->SUPER::initialize()\*(C'\fR.
.SH "\fB\fP\f(BIbegin_pod()\fP\fB\fP"
.IX Header "begin_pod()"
.Vb 1
\& $parser->begin_pod();
.Ve
.PP
This method is invoked at the beginning of processing for each \s-1POD\s0
document that is encountered in the input. Subclasses should override
this method to perform any per-document initialization.
.SH "\fB\fP\f(BIbegin_input()\fP\fB\fP"
.IX Header "begin_input()"
.Vb 1
\& $parser->begin_input();
.Ve
.PP
This method is invoked by \fB\f(BIparse_from_filehandle()\fB\fR immediately \fIbefore\fR
processing input from a filehandle. The base class implementation does
nothing, however, subclasses may override it to perform any per-file
initializations.
.PP
Note that if multiple files are parsed for a single \s-1POD\s0 document
(perhaps the result of some future \f(CW\*(C`=include\*(C'\fR directive) this method
is invoked for every file that is parsed. If you wish to perform certain
initializations once per document, then you should use \fB\f(BIbegin_pod()\fB\fR.
.SH "\fB\fP\f(BIend_input()\fP\fB\fP"
.IX Header "end_input()"
.Vb 1
\& $parser->end_input();
.Ve
.PP
This method is invoked by \fB\f(BIparse_from_filehandle()\fB\fR immediately \fIafter\fR
processing input from a filehandle. The base class implementation does
nothing, however, subclasses may override it to perform any per-file
cleanup actions.
.PP
Please note that if multiple files are parsed for a single \s-1POD\s0 document
(perhaps the result of some kind of \f(CW\*(C`=include\*(C'\fR directive) this method
is invoked for every file that is parsed. If you wish to perform certain
cleanup actions once per document, then you should use \fB\f(BIend_pod()\fB\fR.
.SH "\fB\fP\f(BIend_pod()\fP\fB\fP"
.IX Header "end_pod()"
.Vb 1
\& $parser->end_pod();
.Ve
.PP
This method is invoked at the end of processing for each \s-1POD\s0 document
that is encountered in the input. Subclasses should override this method
to perform any per-document finalization.
.SH "\fB\fP\f(BIpreprocess_line()\fP\fB\fP"
.IX Header "preprocess_line()"
.Vb 1
\& $textline = $parser->preprocess_line($text, $line_num);
.Ve
.PP
This method should be overridden by subclasses that wish to perform
any kind of preprocessing for each \fIline\fR of input (\fIbefore\fR it has
been determined whether or not it is part of a \s-1POD\s0 paragraph). The
parameter \f(CW$text\fR is the input line; and the parameter \f(CW$line_num\fR is
the line number of the corresponding text line.
.PP
The value returned should correspond to the new text to use in its
place. If the empty string or an undefined value is returned then no
further processing will be performed for this line.
.PP
Please note that the \fB\f(BIpreprocess_line()\fB\fR method is invoked \fIbefore\fR
the \fB\f(BIpreprocess_paragraph()\fB\fR method. After all (possibly preprocessed)
lines in a paragraph have been assembled together and it has been
determined that the paragraph is part of the \s-1POD\s0 documentation from one
of the selected sections, then \fB\f(BIpreprocess_paragraph()\fB\fR is invoked.
.PP
The base class implementation of this method returns the given text.
.SH "\fB\fP\f(BIpreprocess_paragraph()\fP\fB\fP"
.IX Header "preprocess_paragraph()"
.Vb 1
\& $textblock = $parser->preprocess_paragraph($text, $line_num);
.Ve
.PP
This method should be overridden by subclasses that wish to perform any
kind of preprocessing for each block (paragraph) of \s-1POD\s0 documentation
that appears in the input stream. The parameter \f(CW$text\fR is the \s-1POD\s0
paragraph from the input file; and the parameter \f(CW$line_num\fR is the
line number for the beginning of the corresponding paragraph.
.PP
The value returned should correspond to the new text to use in its
place If the empty string is returned or an undefined value is
returned, then the given \f(CW$text\fR is ignored (not processed).
.PP
This method is invoked after gathering up all the lines in a paragraph
and after determining the cutting state of the paragraph,
but before trying to further parse or interpret them. After
\&\fB\f(BIpreprocess_paragraph()\fB\fR returns, the current cutting state (which
is returned by \f(CW\*(C`$self\->cutting()\*(C'\fR) is examined. If it evaluates
to true then input text (including the given \f(CW$text\fR) is cut (not
processed) until the next \s-1POD\s0 directive is encountered.
.PP
Please note that the \fB\f(BIpreprocess_line()\fB\fR method is invoked \fIbefore\fR
the \fB\f(BIpreprocess_paragraph()\fB\fR method. After all (possibly preprocessed)
lines in a paragraph have been assembled together and either it has been
determined that the paragraph is part of the \s-1POD\s0 documentation from one
of the selected sections or the \f(CW\*(C`\-want_nonPODs\*(C'\fR option is true,
then \fB\f(BIpreprocess_paragraph()\fB\fR is invoked.
.PP
The base class implementation of this method returns the given text.
.SH "METHODS FOR PARSING AND PROCESSING"
.IX Header "METHODS FOR PARSING AND PROCESSING"
\&\fBPod::Parser\fR provides several methods to process input text. These
methods typically won't need to be overridden (and in some cases they
can't be overridden), but subclasses may want to invoke them to exploit
their functionality.
.SH "\fB\fP\f(BIparse_text()\fP\fB\fP"
.IX Header "parse_text()"
.Vb 3
\& $ptree1 = $parser->parse_text($text, $line_num);
\& $ptree2 = $parser->parse_text({%opts}, $text, $line_num);
\& $ptree3 = $parser->parse_text(\e%opts, $text, $line_num);
.Ve
.PP
This method is useful if you need to perform your own interpolation
of interior sequences and can't rely upon \fBinterpolate\fR to expand
them in simple bottom-up order.
.PP
The parameter \f(CW$text\fR is a string or block of text to be parsed
for interior sequences; and the parameter \f(CW$line_num\fR is the
line number curresponding to the beginning of \f(CW$text\fR.
.PP
\&\fB\f(BIparse_text()\fB\fR will parse the given text into a parse-tree of \*(L"nodes.\*(R"
and interior\-sequences. Each \*(L"node\*(R" in the parse tree is either a
text\-string, or a \fBPod::InteriorSequence\fR. The result returned is a
parse-tree of type \fBPod::ParseTree\fR. Please see Pod::InputObjects
for more information about \fBPod::InteriorSequence\fR and \fBPod::ParseTree\fR.
.PP
If desired, an optional hash-ref may be specified as the first argument
to customize certain aspects of the parse-tree that is created and
returned. The set of recognized option keywords are:
.IP "\fB\-expand_seq\fR => \fIcode-ref\fR|\fImethod-name\fR" 3
.IX Item "-expand_seq => code-ref|method-name"
Normally, the parse-tree returned by \fB\f(BIparse_text()\fB\fR will contain an
unexpanded \f(CW\*(C`Pod::InteriorSequence\*(C'\fR object for each interior-sequence
encountered. Specifying \fB\-expand_seq\fR tells \fB\f(BIparse_text()\fB\fR to \*(L"expand\*(R"
every interior-sequence it sees by invoking the referenced function
(or named method of the parser object) and using the return value as the
expanded result.
.Sp
If a subroutine reference was given, it is invoked as:
.Sp
.Vb 1
\& &$code_ref( $parser, $sequence )
.Ve
.Sp
and if a method-name was given, it is invoked as:
.Sp
.Vb 1
\& $parser->method_name( $sequence )
.Ve
.Sp
where \f(CW$parser\fR is a reference to the parser object, and \f(CW$sequence\fR
is a reference to the interior-sequence object.
[\fI\s-1NOTE\s0\fR: If the \fB\f(BIinterior_sequence()\fB\fR method is specified, then it is
invoked according to the interface specified in \*(L"\fIinterior_sequence()\fR\*(R"].
.IP "\fB\-expand_text\fR => \fIcode-ref\fR|\fImethod-name\fR" 3
.IX Item "-expand_text => code-ref|method-name"
Normally, the parse-tree returned by \fB\f(BIparse_text()\fB\fR will contain a
text-string for each contiguous sequence of characters outside of an
interior\-sequence. Specifying \fB\-expand_text\fR tells \fB\f(BIparse_text()\fB\fR to
\&\*(L"preprocess\*(R" every such text-string it sees by invoking the referenced
function (or named method of the parser object) and using the return value
as the preprocessed (or \*(L"expanded\*(R") result. [Note that if the result is
an interior\-sequence, then it will \fInot\fR be expanded as specified by the
\&\fB\-expand_seq\fR option; Any such recursive expansion needs to be handled by
the specified callback routine.]
.Sp
If a subroutine reference was given, it is invoked as:
.Sp
.Vb 1
\& &$code_ref( $parser, $text, $ptree_node )
.Ve
.Sp
and if a method-name was given, it is invoked as:
.Sp
.Vb 1
\& $parser->method_name( $text, $ptree_node )
.Ve
.Sp
where \f(CW$parser\fR is a reference to the parser object, \f(CW$text\fR is the
text-string encountered, and \f(CW$ptree_node\fR is a reference to the current
node in the parse-tree (usually an interior-sequence object or else the
top-level node of the parse\-tree).
.IP "\fB\-expand_ptree\fR => \fIcode-ref\fR|\fImethod-name\fR" 3
.IX Item "-expand_ptree => code-ref|method-name"
Rather than returning a \f(CW\*(C`Pod::ParseTree\*(C'\fR, pass the parse-tree as an
argument to the referenced subroutine (or named method of the parser
object) and return the result instead of the parse-tree object.
.Sp
If a subroutine reference was given, it is invoked as:
.Sp
.Vb 1
\& &$code_ref( $parser, $ptree )
.Ve
.Sp
and if a method-name was given, it is invoked as:
.Sp
.Vb 1
\& $parser->method_name( $ptree )
.Ve
.Sp
where \f(CW$parser\fR is a reference to the parser object, and \f(CW$ptree\fR
is a reference to the parse-tree object.
.SH "\fB\fP\f(BIinterpolate()\fP\fB\fP"
.IX Header "interpolate()"
.Vb 1
\& $textblock = $parser->interpolate($text, $line_num);
.Ve
.PP
This method translates all text (including any embedded interior sequences)
in the given text string \f(CW$text\fR and returns the interpolated result. The
parameter \f(CW$line_num\fR is the line number corresponding to the beginning
of \f(CW$text\fR.
.PP
\&\fB\f(BIinterpolate()\fB\fR merely invokes a private method to recursively expand
nested interior sequences in bottom-up order (innermost sequences are
expanded first). If there is a need to expand nested sequences in
some alternate order, use \fBparse_text\fR instead.
.SH "\fB\fP\f(BIparse_from_filehandle()\fP\fB\fP"
.IX Header "parse_from_filehandle()"
.Vb 1
\& $parser->parse_from_filehandle($in_fh,$out_fh);
.Ve
.PP
This method takes an input filehandle (which is assumed to already be
opened for reading) and reads the entire input stream looking for blocks
(paragraphs) of \s-1POD\s0 documentation to be processed. If no first argument
is given the default input filehandle \f(CW\*(C`STDIN\*(C'\fR is used.
.PP
The \f(CW$in_fh\fR parameter may be any object that provides a \fB\f(BIgetline()\fB\fR
method to retrieve a single line of input text (hence, an appropriate
wrapper object could be used to parse PODs from a single string or an
array of strings).
.PP
Using \f(CW\*(C`$in_fh\->getline()\*(C'\fR, input is read line-by-line and assembled
into paragraphs or \*(L"blocks\*(R" (which are separated by lines containing
nothing but whitespace). For each block of \s-1POD\s0 documentation
encountered it will invoke a method to parse the given paragraph.
.PP
If a second argument is given then it should correspond to a filehandle where
output should be sent (otherwise the default output filehandle is
\&\f(CW\*(C`STDOUT\*(C'\fR if no output filehandle is currently in use).
.PP
\&\fB\s-1NOTE:\s0\fR For performance reasons, this method caches the input stream at
the top of the stack in a local variable. Any attempts by clients to
change the stack contents during processing when in the midst executing
of this method \fIwill not affect\fR the input stream used by the current
invocation of this method.
.PP
This method does \fInot\fR usually need to be overridden by subclasses.
.SH "\fB\fP\f(BIparse_from_file()\fP\fB\fP"
.IX Header "parse_from_file()"
.Vb 1
\& $parser->parse_from_file($filename,$outfile);
.Ve
.PP
This method takes a filename and does the following:
.IP "\(bu" 2
opens the input and output files for reading
(creating the appropriate filehandles)
.IP "\(bu" 2
invokes the \fB\f(BIparse_from_filehandle()\fB\fR method passing it the
corresponding input and output filehandles.
.IP "\(bu" 2
closes the input and output files.
.PP
If the special input filename \*(L"\-\*(R" or \*(L"<&STDIN\*(R" is given then the \s-1STDIN\s0
filehandle is used for input (and no open or close is performed). If no
input filename is specified then \*(L"\-\*(R" is implied.
.PP
If a second argument is given then it should be the name of the desired
output file. If the special output filename \*(L"\-\*(R" or \*(L">&STDOUT\*(R" is given
then the \s-1STDOUT\s0 filehandle is used for output (and no open or close is
performed). If the special output filename \*(L">&STDERR\*(R" is given then the
\&\s-1STDERR\s0 filehandle is used for output (and no open or close is
performed). If no output filehandle is currently in use and no output
filename is specified, then \*(L"\-\*(R" is implied.
.PP
This method does \fInot\fR usually need to be overridden by subclasses.
.SH "ACCESSOR METHODS"
.IX Header "ACCESSOR METHODS"
Clients of \fBPod::Parser\fR should use the following methods to access
instance data fields:
.SH "\fB\fP\f(BIerrorsub()\fP\fB\fP"
.IX Header "errorsub()"
.Vb 3
\& $parser->errorsub("method_name");
\& $parser->errorsub(\e&warn_user);
\& $parser->errorsub(sub { print STDERR, @_ });
.Ve
.PP
Specifies the method or subroutine to use when printing error messages
about \s-1POD\s0 syntax. The supplied method/subroutine \fImust\fR return \s-1TRUE\s0 upon
successful printing of the message. If \f(CW\*(C`undef\*(C'\fR is given, then the \fBwarn\fR
builtin is used to issue error messages (this is the default behavior).
.PP
.Vb 5
\& my $errorsub = $parser->errorsub()
\& my $errmsg = "This is an error message!\en"
\& (ref $errorsub) and &{$errorsub}($errmsg)
\& or (defined $errorsub) and $parser->$errorsub($errmsg)
\& or warn($errmsg);
.Ve
.PP
Returns a method name, or else a reference to the user-supplied subroutine
used to print error messages. Returns \f(CW\*(C`undef\*(C'\fR if the \fBwarn\fR builtin
is used to issue error messages (this is the default behavior).
.SH "\fB\fP\f(BIcutting()\fP\fB\fP"
.IX Header "cutting()"
.Vb 1
\& $boolean = $parser->cutting();
.Ve
.PP
Returns the current \f(CW\*(C`cutting\*(C'\fR state: a boolean-valued scalar which
evaluates to true if text from the input file is currently being \*(L"cut\*(R"
(meaning it is \fInot\fR considered part of the \s-1POD\s0 document).
.PP
.Vb 1
\& $parser->cutting($boolean);
.Ve
.PP
Sets the current \f(CW\*(C`cutting\*(C'\fR state to the given value and returns the
result.
.SH "\fB\fP\f(BIparseopts()\fP\fB\fP"
.IX Header "parseopts()"
When invoked with no additional arguments, \fBparseopts\fR returns a hashtable
of all the current parsing options.
.PP
.Vb 3
\& ## See if we are parsing non-POD sections as well as POD ones
\& my %opts = $parser->parseopts();
\& $opts{'-want_nonPODs}' and print "-want_nonPODs\en";
.Ve
.PP
When invoked using a single string, \fBparseopts\fR treats the string as the
name of a parse-option and returns its corresponding value if it exists
(returns \f(CW\*(C`undef\*(C'\fR if it doesn't).
.PP
.Vb 3
\& ## Did we ask to see '=cut' paragraphs?
\& my $want_cut = $parser->parseopts('-process_cut_cmd');
\& $want_cut and print "-process_cut_cmd\en";
.Ve
.PP
When invoked with multiple arguments, \fBparseopts\fR treats them as
key/value pairs and the specified parse-option names are set to the
given values. Any unspecified parse-options are unaffected.
.PP
.Vb 2
\& ## Set them back to the default
\& $parser->parseopts(-warnings => 0);
.Ve
.PP
When passed a single hash\-ref, \fBparseopts\fR uses that hash to completely
reset the existing parse\-options, all previous parse-option values
are lost.
.PP
.Vb 2
\& ## Reset all options to default
\& $parser->parseopts( { } );
.Ve
.PP
See \*(L"\s-1PARSING\s0 \s-1OPTIONS\s0\*(R" for more information on the name and meaning of each
parse-option currently recognized.
.SH "\fB\fP\f(BIoutput_file()\fP\fB\fP"
.IX Header "output_file()"
.Vb 1
\& $fname = $parser->output_file();
.Ve
.PP
Returns the name of the output file being written.
.SH "\fB\fP\f(BIoutput_handle()\fP\fB\fP"
.IX Header "output_handle()"
.Vb 1
\& $fhandle = $parser->output_handle();
.Ve
.PP
Returns the output filehandle object.
.SH "\fB\fP\f(BIinput_file()\fP\fB\fP"
.IX Header "input_file()"
.Vb 1
\& $fname = $parser->input_file();
.Ve
.PP
Returns the name of the input file being read.
.SH "\fB\fP\f(BIinput_handle()\fP\fB\fP"
.IX Header "input_handle()"
.Vb 1
\& $fhandle = $parser->input_handle();
.Ve
.PP
Returns the current input filehandle object.
.SH "PRIVATE METHODS AND DATA"
.IX Header "PRIVATE METHODS AND DATA"
\&\fBPod::Parser\fR makes use of several internal methods and data fields
which clients should not need to see or use. For the sake of avoiding
name collisions for client data and methods, these methods and fields
are briefly discussed here. Determined hackers may obtain further
information about them by reading the \fBPod::Parser\fR source code.
.PP
Private data fields are stored in the hash-object whose reference is
returned by the \fB\f(BInew()\fB\fR constructor for this class. The names of all
private methods and data-fields used by \fBPod::Parser\fR begin with a
prefix of \*(L"_\*(R" and match the regular expression \f(CW\*(C`/^_\ew+$/\*(C'\fR.
.SH "TREE-BASED PARSING"
.IX Header "TREE-BASED PARSING"
If straightforward stream-based parsing wont meet your needs (as is
likely the case for tasks such as translating PODs into structured
markup languages like \s-1HTML\s0 and \s-1XML\s0) then you may need to take the
tree-based approach. Rather than doing everything in one pass and
calling the \fB\f(BIinterpolate()\fB\fR method to expand sequences into text, it
may be desirable to instead create a parse-tree using the \fB\f(BIparse_text()\fB\fR
method to return a tree-like structure which may contain an ordered
list of children (each of which may be a text\-string, or a similar
tree-like structure).
.PP
Pay special attention to \*(L"\s-1METHODS\s0 \s-1FOR\s0 \s-1PARSING\s0 \s-1AND\s0 \s-1PROCESSING\s0\*(R" and
to the objects described in Pod::InputObjects. The former describes
the gory details and parameters for how to customize and extend the
parsing behavior of \fBPod::Parser\fR. \fBPod::InputObjects\fR provides
several objects that may all be used interchangeably as parse\-trees. The
most obvious one is the \fBPod::ParseTree\fR object. It defines the basic
interface and functionality that all things trying to be a \s-1POD\s0 parse-tree
should do. A \fBPod::ParseTree\fR is defined such that each \*(L"node\*(R" may be a
text\-string, or a reference to another parse\-tree. Each \fBPod::Paragraph\fR
object and each \fBPod::InteriorSequence\fR object also supports the basic
parse-tree interface.
.PP
The \fB\f(BIparse_text()\fB\fR method takes a given paragraph of text, and
returns a parse-tree that contains one or more children, each of which
may be a text\-string, or an InteriorSequence object. There are also
callback-options that may be passed to \fB\f(BIparse_text()\fB\fR to customize
the way it expands or transforms interior\-sequences, as well as the
returned result. These callbacks can be used to create a parse-tree
with custom-made objects (which may or may not support the parse-tree
interface, depending on how you choose to do it).
.PP
If you wish to turn an entire \s-1POD\s0 document into a parse\-tree, that process
is fairly straightforward. The \fB\f(BIparse_text()\fB\fR method is the key to doing
this successfully. Every paragraph-callback (i.e. the polymorphic methods
for \fB\f(BIcommand()\fB\fR, \fB\f(BIverbatim()\fB\fR, and \fB\f(BItextblock()\fB\fR paragraphs) takes
a \fBPod::Paragraph\fR object as an argument. Each paragraph object has a
\&\fB\f(BIparse_tree()\fB\fR method that can be used to get or set a corresponding
parse\-tree. So for each of those paragraph-callback methods, simply call
\&\fB\f(BIparse_text()\fB\fR with the options you desire, and then use the returned
parse-tree to assign to the given paragraph object.
.PP
That gives you a parse-tree for each paragraph \- so now all you need is
an ordered list of paragraphs. You can maintain that yourself as a data
element in the object/hash. The most straightforward way would be simply
to use an array\-ref, with the desired set of custom \*(L"options\*(R" for each
invocation of \fBparse_text\fR. Let's assume the desired option-set is
given by the hash \f(CW%options\fR. Then we might do something like the
following:
.PP
.Vb 1
\& package MyPodParserTree;
.Ve
.PP
.Vb 1
\& @ISA = qw( Pod::Parser );
.Ve
.PP
.Vb 1
\& ...
.Ve
.PP
.Vb 4
\& sub begin_pod {
\& my $self = shift;
\& $self->{'-paragraphs'} = []; ## initialize paragraph list
\& }
.Ve
.PP
.Vb 6
\& sub command {
\& my ($parser, $command, $paragraph, $line_num, $pod_para) = @_;
\& my $ptree = $parser->parse_text({%options}, $paragraph, ...);
\& $pod_para->parse_tree( $ptree );
\& push @{ $self->{'-paragraphs'} }, $pod_para;
\& }
.Ve
.PP
.Vb 4
\& sub verbatim {
\& my ($parser, $paragraph, $line_num, $pod_para) = @_;
\& push @{ $self->{'-paragraphs'} }, $pod_para;
\& }
.Ve
.PP
.Vb 6
\& sub textblock {
\& my ($parser, $paragraph, $line_num, $pod_para) = @_;
\& my $ptree = $parser->parse_text({%options}, $paragraph, ...);
\& $pod_para->parse_tree( $ptree );
\& push @{ $self->{'-paragraphs'} }, $pod_para;
\& }
.Ve
.PP
.Vb 1
\& ...
.Ve
.PP
.Vb 5
\& package main;
\& ...
\& my $parser = new MyPodParserTree(...);
\& $parser->parse_from_file(...);
\& my $paragraphs_ref = $parser->{'-paragraphs'};
.Ve
.PP
Of course, in this module\-author's humble opinion, I'd be more inclined to
use the existing \fBPod::ParseTree\fR object than a simple array. That way
everything in it, paragraphs and sequences, all respond to the same core
interface for all parse-tree nodes. The result would look something like:
.PP
.Vb 1
\& package MyPodParserTree2;
.Ve
.PP
.Vb 1
\& ...
.Ve
.PP
.Vb 4
\& sub begin_pod {
\& my $self = shift;
\& $self->{'-ptree'} = new Pod::ParseTree; ## initialize parse-tree
\& }
.Ve
.PP
.Vb 5
\& sub parse_tree {
\& ## convenience method to get/set the parse-tree for the entire POD
\& (@_ > 1) and $_[0]->{'-ptree'} = $_[1];
\& return $_[0]->{'-ptree'};
\& }
.Ve
.PP
.Vb 6
\& sub command {
\& my ($parser, $command, $paragraph, $line_num, $pod_para) = @_;
\& my $ptree = $parser->parse_text({<<options>>}, $paragraph, ...);
\& $pod_para->parse_tree( $ptree );
\& $parser->parse_tree()->append( $pod_para );
\& }
.Ve
.PP
.Vb 4
\& sub verbatim {
\& my ($parser, $paragraph, $line_num, $pod_para) = @_;
\& $parser->parse_tree()->append( $pod_para );
\& }
.Ve
.PP
.Vb 6
\& sub textblock {
\& my ($parser, $paragraph, $line_num, $pod_para) = @_;
\& my $ptree = $parser->parse_text({<<options>>}, $paragraph, ...);
\& $pod_para->parse_tree( $ptree );
\& $parser->parse_tree()->append( $pod_para );
\& }
.Ve
.PP
.Vb 1
\& ...
.Ve
.PP
.Vb 6
\& package main;
\& ...
\& my $parser = new MyPodParserTree2(...);
\& $parser->parse_from_file(...);
\& my $ptree = $parser->parse_tree;
\& ...
.Ve
.PP
Now you have the entire \s-1POD\s0 document as one great big parse\-tree. You
can even use the \fB\-expand_seq\fR option to \fBparse_text\fR to insert
whole different kinds of objects. Just don't expect \fBPod::Parser\fR
to know what to do with them after that. That will need to be in your
code. Or, alternatively, you can insert any object you like so long as
it conforms to the \fBPod::ParseTree\fR interface.
.PP
One could use this to create subclasses of \fBPod::Paragraphs\fR and
\&\fBPod::InteriorSequences\fR for specific commands (or to create your own
custom node-types in the parse\-tree) and add some kind of \fB\f(BIemit()\fB\fR
method to each custom node/subclass object in the tree. Then all you'd
need to do is recursively walk the tree in the desired order, processing
the children (most likely from left to right) by formatting them if
they are text\-strings, or by calling their \fB\f(BIemit()\fB\fR method if they
are objects/references.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Pod::InputObjects, Pod::Select
.PP
\&\fBPod::InputObjects\fR defines \s-1POD\s0 input objects corresponding to
command paragraphs, parse\-trees, and interior\-sequences.
.PP
\&\fBPod::Select\fR is a subclass of \fBPod::Parser\fR which provides the ability
to selectively include and/or exclude sections of a \s-1POD\s0 document from being
translated based upon the current heading, subheading, subsubheading, etc.
.SH "AUTHOR"
.IX Header "AUTHOR"
Brad Appleton <bradapp@enteract.com>
.PP
Based on code for \fBPod::Text\fR written by
Tom Christiansen <tchrist@mox.perl.com>
|