1
2require 5;
3package Pod::Simple::Methody;
4use strict;
5use Pod::Simple ();
6use vars qw(@ISA $VERSION);
7$VERSION = '3.35';
8@ISA = ('Pod::Simple');
9
10# Yes, we could use named variables, but I want this to be impose
11# as little an additional performance hit as possible.
12
13sub _handle_element_start {
14  $_[1] =~ tr/-:./__/;
15  ( $_[0]->can( 'start_' . $_[1] )
16    || return
17  )->(
18    $_[0], $_[2]
19  );
20}
21
22sub _handle_text {
23  ( $_[0]->can( 'handle_text' )
24    || return
25  )->(
26    @_
27  );
28}
29
30sub _handle_element_end {
31  $_[1] =~ tr/-:./__/;
32  ( $_[0]->can( 'end_' . $_[1] )
33    || return
34  )->(
35    $_[0], $_[2]
36  );
37}
38
391;
40
41
42__END__
43
44=head1 NAME
45
46Pod::Simple::Methody -- turn Pod::Simple events into method calls
47
48=head1 SYNOPSIS
49
50 require 5;
51 use strict;
52 package SomePodFormatter;
53 use base qw(Pod::Simple::Methody);
54
55 sub handle_text {
56   my($self, $text) = @_;
57   ...
58 }
59
60 sub start_head1 {
61   my($self, $attrs) = @_;
62   ...
63 }
64 sub end_head1 {
65   my($self) = @_;
66   ...
67 }
68
69...and start_/end_ methods for whatever other events you want to catch.
70
71=head1 DESCRIPTION
72
73This class is of
74interest to people writing Pod formatters based on Pod::Simple.
75
76This class (which is very small -- read the source) overrides
77Pod::Simple's _handle_element_start, _handle_text, and
78_handle_element_end methods so that parser events are turned into method
79calls. (Otherwise, this is a subclass of L<Pod::Simple> and inherits all
80its methods.)
81
82You can use this class as the base class for a Pod formatter/processor.
83
84=head1 METHOD CALLING
85
86When Pod::Simple sees a "=head1 Hi there", for example, it basically does
87this:
88
89  $parser->_handle_element_start( "head1", \%attributes );
90  $parser->_handle_text( "Hi there" );
91  $parser->_handle_element_end( "head1" );
92
93But if you subclass Pod::Simple::Methody, it will instead do this
94when it sees a "=head1 Hi there":
95
96  $parser->start_head1( \%attributes ) if $parser->can('start_head1');
97  $parser->handle_text( "Hi there" )   if $parser->can('handle_text');
98  $parser->end_head1()                 if $parser->can('end_head1');
99
100If Pod::Simple sends an event where the element name has a dash,
101period, or colon, the corresponding method name will have a underscore
102in its place.  For example, "foo.bar:baz" becomes start_foo_bar_baz
103and end_foo_bar_baz.
104
105See the source for Pod::Simple::Text for an example of using this class.
106
107=head1 SEE ALSO
108
109L<Pod::Simple>, L<Pod::Simple::Subclassing>
110
111=head1 SUPPORT
112
113Questions or discussion about POD and Pod::Simple should be sent to the
114pod-people@perl.org mail list. Send an empty email to
115pod-people-subscribe@perl.org to subscribe.
116
117This module is managed in an open GitHub repository,
118L<https://github.com/perl-pod/pod-simple/>. Feel free to fork and contribute, or
119to clone L<git://github.com/perl-pod/pod-simple.git> and send patches!
120
121Patches against Pod::Simple are welcome. Please send bug reports to
122<bug-pod-simple@rt.cpan.org>.
123
124=head1 COPYRIGHT AND DISCLAIMERS
125
126Copyright (c) 2002 Sean M. Burke.
127
128This library is free software; you can redistribute it and/or modify it
129under the same terms as Perl itself.
130
131This program is distributed in the hope that it will be useful, but
132without any warranty; without even the implied warranty of
133merchantability or fitness for a particular purpose.
134
135=head1 AUTHOR
136
137Pod::Simple was created by Sean M. Burke <sburke@cpan.org>.
138But don't bother him, he's retired.
139
140Pod::Simple is maintained by:
141
142=over
143
144=item * Allison Randal C<allison@perl.org>
145
146=item * Hans Dieter Pearcey C<hdp@cpan.org>
147
148=item * David E. Wheeler C<dwheeler@cpan.org>
149
150=back
151
152=cut
153