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