1Pod::Simple::PullParserU(s3e)r Contributed Perl DocumentaPtoido:n:Simple::PullParser(3)
2
3
4

NAME

6       Pod::Simple::PullParser -- a pull-parser interface to parsing Pod
7

SYNOPSIS

9        my $parser = SomePodProcessor->new;
10        $parser->set_source( "whatever.pod" );
11        $parser->run;
12
13       Or:
14
15        my $parser = SomePodProcessor->new;
16        $parser->set_source( $some_filehandle_object );
17        $parser->run;
18
19       Or:
20
21        my $parser = SomePodProcessor->new;
22        $parser->set_source( \$document_source );
23        $parser->run;
24
25       Or:
26
27        my $parser = SomePodProcessor->new;
28        $parser->set_source( \@document_lines );
29        $parser->run;
30
31       And elsewhere:
32
33        require 5;
34        package SomePodProcessor;
35        use strict;
36        use base qw(Pod::Simple::PullParser);
37
38        sub run {
39          my $self = shift;
40         Token:
41          while(my $token = $self->get_token) {
42            ...process each token...
43          }
44        }
45

DESCRIPTION

47       This class is for using Pod::Simple to build a Pod processor -- but one
48       that uses an interface based on a stream of token objects, instead of
49       based on events.
50
51       This is a subclass of Pod::Simple and inherits all its methods.
52
53       A subclass of Pod::Simple::PullParser should define a "run" method that
54       calls "$token = $parser->get_token" to pull tokens.
55
56       See the source for Pod::Simple::RTF for an example of a formatter that
57       uses Pod::Simple::PullParser.
58

METHODS

60       my $token = $parser->get_token
61           This returns the next token object (which will be of a subclass of
62           Pod::Simple::PullParserToken), or undef if the parser-stream has
63           hit the end of the document.
64
65       $parser->unget_token( $token )
66       $parser->unget_token( $token1, $token2, ... )
67           This restores the token object(s) to the front of the parser
68           stream.
69
70       The source has to be set before you can parse anything.  The lowest-
71       level way is to call "set_source":
72
73       $parser->set_source( $filename )
74       $parser->set_source( $filehandle_object )
75       $parser->set_source( \$document_source )
76       $parser->set_source( \@document_lines )
77
78       Or you can call these methods, which Pod::Simple::PullParser has
79       defined to work just like Pod::Simple's same-named methods:
80
81       $parser->parse_file(...)
82       $parser->parse_string_document(...)
83       $parser->filter(...)
84       $parser->parse_from_file(...)
85
86       For those to work, the Pod-processing subclass of Pod::Simple::Pull‐
87       Parser has to have defined a $parser->run method -- so it is advised
88       that all Pod::Simple::PullParser subclasses do so.  See the Synopsis
89       above, or the source for Pod::Simple::RTF.
90
91       Authors of formatter subclasses might find these methods useful to call
92       on a parser object that you haven't started pulling tokens from yet:
93
94       my $title_string = $parser->get_title
95           This tries to get the title string out of $parser, by getting some
96           tokens, and scanning them for the title, and then ungetting them so
97           that you can process the token-stream from the beginning.
98
99           For example, suppose you have a document that starts out:
100
101             =head1 NAME
102
103             Hoo::Boy::Wowza -- Stuff B<wow> yeah!
104
105           $parser->get_title on that document will return "Hoo::Boy::Wowza --
106           Stuff wow yeah!".
107
108           In cases where get_title can't find the title, it will return
109           empty-string ("").
110
111       my $title_string = $parser->get_short_title
112           This is just like get_title, except that it returns just the modu‐
113           lename, if the title seems to be of the form "SomeModuleName --
114           description".
115
116           For example, suppose you have a document that starts out:
117
118             =head1 NAME
119
120             Hoo::Boy::Wowza -- Stuff B<wow> yeah!
121
122           then $parser->get_short_title on that document will return
123           "Hoo::Boy::Wowza".
124
125           But if the document starts out:
126
127             =head1 NAME
128
129             Hooboy, stuff B<wow> yeah!
130
131           then $parser->get_short_title on that document will return "Hooboy,
132           stuff wow yeah!".
133
134           If the title can't be found, then get_short_title returns empty-
135           string ("").
136
137       $author_name   = $parser->get_author
138           This works like get_title except that it returns the contents of
139           the "=head1 AUTHOR\n\nParagraph...\n" section, assuming that that
140           section isn't terribly long.
141
142           (This method tolerates "AUTHORS" instead of "AUTHOR" too.)
143
144       $description_name = $parser->get_description
145           This works like get_title except that it returns the contents of
146           the "=head1 PARAGRAPH\n\nParagraph...\n" section, assuming that
147           that section isn't terribly long.
148
149       $version_block = $parser->get_version
150           This works like get_title except that it returns the contents of
151           the "=head1 VERSION\n\n[BIG BLOCK]\n" block.  Note that this does
152           NOT return the module's $VERSION!!
153

NOTE

155       You don't actually have to define a "run" method.  If you're writing a
156       Pod-formatter class, you should define a "run" just so that users can
157       call "parse_file" etc, but you don't have to.
158
159       And if you're not writing a formatter class, but are instead just writ‐
160       ing a program that does something simple with a Pod::PullParser object
161       (and not an object of a subclass), then there's no reason to bother
162       subclassing to add a "run" method.
163

SEE ALSO

165       Pod::Simple
166
167       Pod::Simple::PullParserToken -- and its subclasses Pod::Simple::Pull‐
168       ParserStartToken, Pod::Simple::PullParserTextToken, and Pod::Sim‐
169       ple::PullParserEndToken.
170
171       HTML::TokeParser, which inspired this.
172
174       Copyright (c) 2002 Sean M. Burke.  All rights reserved.
175
176       This library is free software; you can redistribute it and/or modify it
177       under the same terms as Perl itself.
178
179       This program is distributed in the hope that it will be useful, but
180       without any warranty; without even the implied warranty of mer‐
181       chantability or fitness for a particular purpose.
182

AUTHOR

184       Sean M. Burke "sburke@cpan.org"
185
186
187
188perl v5.8.8                       2003-11-02        Pod::Simple::PullParser(3)
Impressum