Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Pod / Simple / Methody.pm
CommitLineData
3fea05b9 1
2require 5;
3package Pod::Simple::Methody;
4use strict;
5use Pod::Simple ();
6use vars qw(@ISA $VERSION);
7$VERSION = '2.02';
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]
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 COPYRIGHT AND DISCLAIMERS
112
113Copyright (c) 2002 Sean M. Burke. All rights reserved.
114
115This library is free software; you can redistribute it and/or modify it
116under the same terms as Perl itself.
117
118This program is distributed in the hope that it will be useful, but
119without any warranty; without even the implied warranty of
120merchantability or fitness for a particular purpose.
121
122=head1 AUTHOR
123
124Sean M. Burke C<sburke@cpan.org>
125
126=cut
127