Upgrade to Test::Simple 0.64_03
[p5sagit/p5-mst-13.2.git] / lib / Pod / Simple / Text.pm
CommitLineData
351625bd 1
2require 5;
3package Pod::Simple::Text;
4use strict;
5use Carp ();
6use Pod::Simple::Methody ();
7use Pod::Simple ();
8use vars qw( @ISA $VERSION $FREAKYMODE);
9$VERSION = '2.02';
10@ISA = ('Pod::Simple::Methody');
11BEGIN { *DEBUG = defined(&Pod::Simple::DEBUG)
12 ? \&Pod::Simple::DEBUG
13 : sub() {0}
14 }
15
16use Text::Wrap 98.112902 ();
17$Text::Wrap::wrap = 'overflow';
18#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19
20sub new {
21 my $self = shift;
22 my $new = $self->SUPER::new(@_);
23 $new->{'output_fh'} ||= *STDOUT{IO};
24 $new->accept_target_as_text(qw( text plaintext plain ));
25 $new->nix_X_codes(1);
26 $new->nbsp_for_S(1);
27 $new->{'Thispara'} = '';
28 $new->{'Indent'} = 0;
29 $new->{'Indentstring'} = ' ';
30 return $new;
31}
32
33#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34
35sub handle_text { $_[0]{'Thispara'} .= $_[1] }
36
37sub start_Para { $_[0]{'Thispara'} = '' }
38sub start_head1 { $_[0]{'Thispara'} = '' }
39sub start_head2 { $_[0]{'Thispara'} = '' }
40sub start_head3 { $_[0]{'Thispara'} = '' }
41sub start_head4 { $_[0]{'Thispara'} = '' }
42
43sub start_Verbatim { $_[0]{'Thispara'} = '' }
44sub start_item_bullet { $_[0]{'Thispara'} = $FREAKYMODE ? '' : '* ' }
45sub start_item_number { $_[0]{'Thispara'} = $FREAKYMODE ? '' : "$_[1]{'number'}. " }
46sub start_item_text { $_[0]{'Thispara'} = '' }
47
48sub start_over_bullet { ++$_[0]{'Indent'} }
49sub start_over_number { ++$_[0]{'Indent'} }
50sub start_over_text { ++$_[0]{'Indent'} }
51sub start_over_block { ++$_[0]{'Indent'} }
52
53sub end_over_bullet { --$_[0]{'Indent'} }
54sub end_over_number { --$_[0]{'Indent'} }
55sub end_over_text { --$_[0]{'Indent'} }
56sub end_over_block { --$_[0]{'Indent'} }
57
58
59# . . . . . Now the actual formatters:
60
61sub end_head1 { $_[0]->emit_par(-4) }
62sub end_head2 { $_[0]->emit_par(-3) }
63sub end_head3 { $_[0]->emit_par(-2) }
64sub end_head4 { $_[0]->emit_par(-1) }
65sub end_Para { $_[0]->emit_par( 0) }
66sub end_item_bullet { $_[0]->emit_par( 0) }
67sub end_item_number { $_[0]->emit_par( 0) }
68sub end_item_text { $_[0]->emit_par(-2) }
69
70sub emit_par {
71 my($self, $tweak_indent) = splice(@_,0,2);
72 my $indent = ' ' x ( 2 * $self->{'Indent'} + 4 + ($tweak_indent||0) );
73 # Yes, 'STRING' x NEGATIVE gives '', same as 'STRING' x 0
74
75 $self->{'Thispara'} =~ tr{\xAD}{}d if Pod::Simple::ASCII;
76 my $out = Text::Wrap::wrap($indent, $indent, $self->{'Thispara'} .= "\n");
77 $out =~ tr{\xA0}{ } if Pod::Simple::ASCII;
78 print {$self->{'output_fh'}} $out, "\n";
79 $self->{'Thispara'} = '';
80
81 return;
82}
83
84# . . . . . . . . . . And then off by its lonesome:
85
86sub end_Verbatim {
87 my $self = shift;
88 if(Pod::Simple::ASCII) {
89 $self->{'Thispara'} =~ tr{\xA0}{ };
90 $self->{'Thispara'} =~ tr{\xAD}{}d;
91 }
92
93 my $i = ' ' x ( 2 * $self->{'Indent'} + 4);
94 #my $i = ' ' x (4 + $self->{'Indent'});
95
96 $self->{'Thispara'} =~ s/^/$i/mg;
97
98 print { $self->{'output_fh'} } '',
99 $self->{'Thispara'},
100 "\n\n"
101 ;
102 $self->{'Thispara'} = '';
103 return;
104}
105
106#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1071;
108
109
110__END__
111
112=head1 NAME
113
114Pod::Simple::Text -- format Pod as plaintext
115
116=head1 SYNOPSIS
117
118 perl -MPod::Simple::Text -e \
119 "exit Pod::Simple::Text->filter(shift)->any_errata_seen" \
120 thingy.pod
121
122=head1 DESCRIPTION
123
124This class is a formatter that takes Pod and renders it as
125wrapped plaintext.
126
127Its wrapping is done by L<Text::Wrap>, so you can change
128C<$Text::Wrap::columns> as you like.
129
130This is a subclass of L<Pod::Simple> and inherits all its methods.
131
132=head1 SEE ALSO
133
134L<Pod::Simple>, L<Pod::Simple::TextContent>, L<Pod::Text>
135
136=head1 COPYRIGHT AND DISCLAIMERS
137
138Copyright (c) 2002 Sean M. Burke. All rights reserved.
139
140This library is free software; you can redistribute it and/or modify it
141under the same terms as Perl itself.
142
143This program is distributed in the hope that it will be useful, but
144without any warranty; without even the implied warranty of
145merchantability or fitness for a particular purpose.
146
147=head1 AUTHOR
148
149Sean M. Burke C<sburke@cpan.org>
150
151=cut
152