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 = '3.14'; 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) } 69sub start_L { $_[0]{'Link'} = $_[1] if $_[1]->{type} eq 'url' } 70sub end_L { 71 if (my $link = delete $_[0]{'Link'}) { 72 # Append the URL to the output unless it's already present. 73 $_[0]{'Thispara'} .= " <$link->{to}>" 74 unless $_[0]{'Thispara'} =~ /\b\E$link->{to}/; 75 } 76} 77 78sub emit_par { 79 my($self, $tweak_indent) = splice(@_,0,2); 80 my $indent = ' ' x ( 2 * $self->{'Indent'} + 4 + ($tweak_indent||0) ); 81 # Yes, 'STRING' x NEGATIVE gives '', same as 'STRING' x 0 82 83 $self->{'Thispara'} =~ tr{\xAD}{}d if Pod::Simple::ASCII; 84 my $out = Text::Wrap::wrap($indent, $indent, $self->{'Thispara'} .= "\n"); 85 $out =~ tr{\xA0}{ } if Pod::Simple::ASCII; 86 print {$self->{'output_fh'}} $out, "\n"; 87 $self->{'Thispara'} = ''; 88 89 return; 90} 91 92# . . . . . . . . . . And then off by its lonesome: 93 94sub end_Verbatim { 95 my $self = shift; 96 if(Pod::Simple::ASCII) { 97 $self->{'Thispara'} =~ tr{\xA0}{ }; 98 $self->{'Thispara'} =~ tr{\xAD}{}d; 99 } 100 101 my $i = ' ' x ( 2 * $self->{'Indent'} + 4); 102 #my $i = ' ' x (4 + $self->{'Indent'}); 103 104 $self->{'Thispara'} =~ s/^/$i/mg; 105 106 print { $self->{'output_fh'} } '', 107 $self->{'Thispara'}, 108 "\n\n" 109 ; 110 $self->{'Thispara'} = ''; 111 return; 112} 113 114#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1151; 116 117 118__END__ 119 120=head1 NAME 121 122Pod::Simple::Text -- format Pod as plaintext 123 124=head1 SYNOPSIS 125 126 perl -MPod::Simple::Text -e \ 127 "exit Pod::Simple::Text->filter(shift)->any_errata_seen" \ 128 thingy.pod 129 130=head1 DESCRIPTION 131 132This class is a formatter that takes Pod and renders it as 133wrapped plaintext. 134 135Its wrapping is done by L<Text::Wrap>, so you can change 136C<$Text::Wrap::columns> as you like. 137 138This is a subclass of L<Pod::Simple> and inherits all its methods. 139 140=head1 SEE ALSO 141 142L<Pod::Simple>, L<Pod::Simple::TextContent>, L<Pod::Text> 143 144=head1 SUPPORT 145 146Questions or discussion about POD and Pod::Simple should be sent to the 147pod-people@perl.org mail list. Send an empty email to 148pod-people-subscribe@perl.org to subscribe. 149 150This module is managed in an open GitHub repository, 151L<http://github.com/theory/pod-simple/>. Feel free to fork and contribute, or 152to clone L<git://github.com/theory/pod-simple.git> and send patches! 153 154Patches against Pod::Simple are welcome. Please send bug reports to 155<bug-pod-simple@rt.cpan.org>. 156 157=head1 COPYRIGHT AND DISCLAIMERS 158 159Copyright (c) 2002 Sean M. Burke. 160 161This library is free software; you can redistribute it and/or modify it 162under the same terms as Perl itself. 163 164This program is distributed in the hope that it will be useful, but 165without any warranty; without even the implied warranty of 166merchantability or fitness for a particular purpose. 167 168=head1 AUTHOR 169 170Pod::Simple was created by Sean M. Burke <sburke@cpan.org>. 171But don't bother him, he's retired. 172 173Pod::Simple is maintained by: 174 175=over 176 177=item * Allison Randal C<allison@perl.org> 178 179=item * Hans Dieter Pearcey C<hdp@cpan.org> 180 181=item * David E. Wheeler C<dwheeler@cpan.org> 182 183=back 184 185=cut 186