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.43'; 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::huge = 'overflow'; 18 19#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 20 21sub new { 22 my $self = shift; 23 my $new = $self->SUPER::new(@_); 24 $new->{'output_fh'} ||= *STDOUT{IO}; 25 $new->accept_target_as_text(qw( text plaintext plain )); 26 $new->nix_X_codes(1); 27 $new->nbsp_for_S(1); 28 $new->{'Thispara'} = ''; 29 $new->{'Indent'} = 0; 30 $new->{'Indentstring'} = ' '; 31 return $new; 32} 33 34#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 35 36sub handle_text { $_[0]{'Thispara'} .= $_[1] } 37 38sub start_Para { $_[0]{'Thispara'} = '' } 39sub start_head1 { $_[0]{'Thispara'} = '' } 40sub start_head2 { $_[0]{'Thispara'} = '' } 41sub start_head3 { $_[0]{'Thispara'} = '' } 42sub start_head4 { $_[0]{'Thispara'} = '' } 43 44sub start_Verbatim { $_[0]{'Thispara'} = '' } 45sub start_item_bullet { $_[0]{'Thispara'} = $FREAKYMODE ? '' : '* ' } 46sub start_item_number { $_[0]{'Thispara'} = $FREAKYMODE ? '' : "$_[1]{'number'}. " } 47sub start_item_text { $_[0]{'Thispara'} = '' } 48 49sub start_over_bullet { ++$_[0]{'Indent'} } 50sub start_over_number { ++$_[0]{'Indent'} } 51sub start_over_text { ++$_[0]{'Indent'} } 52sub start_over_block { ++$_[0]{'Indent'} } 53 54sub end_over_bullet { --$_[0]{'Indent'} } 55sub end_over_number { --$_[0]{'Indent'} } 56sub end_over_text { --$_[0]{'Indent'} } 57sub end_over_block { --$_[0]{'Indent'} } 58 59 60# . . . . . Now the actual formatters: 61 62sub end_head1 { $_[0]->emit_par(-4) } 63sub end_head2 { $_[0]->emit_par(-3) } 64sub end_head3 { $_[0]->emit_par(-2) } 65sub end_head4 { $_[0]->emit_par(-1) } 66sub end_Para { $_[0]->emit_par( 0) } 67sub end_item_bullet { $_[0]->emit_par( 0) } 68sub end_item_number { $_[0]->emit_par( 0) } 69sub end_item_text { $_[0]->emit_par(-2) } 70sub start_L { $_[0]{'Link'} = $_[1] if $_[1]->{type} eq 'url' } 71sub end_L { 72 if (my $link = delete $_[0]{'Link'}) { 73 # Append the URL to the output unless it's already present. 74 $_[0]{'Thispara'} .= " <$link->{to}>" 75 unless $_[0]{'Thispara'} =~ /\b\Q$link->{to}/; 76 } 77} 78 79sub emit_par { 80 my($self, $tweak_indent) = splice(@_,0,2); 81 my $indent = ' ' x ( 2 * $self->{'Indent'} + 4 + ($tweak_indent||0) ); 82 # Yes, 'STRING' x NEGATIVE gives '', same as 'STRING' x 0 83 84 $self->{'Thispara'} =~ s/$Pod::Simple::shy//g; 85 my $out = Text::Wrap::wrap($indent, $indent, $self->{'Thispara'} .= "\n"); 86 $out =~ s/$Pod::Simple::nbsp/ /g; 87 print {$self->{'output_fh'}} $out, "\n"; 88 $self->{'Thispara'} = ''; 89 90 return; 91} 92 93# . . . . . . . . . . And then off by its lonesome: 94 95sub end_Verbatim { 96 my $self = shift; 97 $self->{'Thispara'} =~ s/$Pod::Simple::nbsp/ /g; 98 $self->{'Thispara'} =~ s/$Pod::Simple::shy//g; 99 100 my $i = ' ' x ( 2 * $self->{'Indent'} + 4); 101 #my $i = ' ' x (4 + $self->{'Indent'}); 102 103 $self->{'Thispara'} =~ s/^/$i/mg; 104 105 print { $self->{'output_fh'} } '', 106 $self->{'Thispara'}, 107 "\n\n" 108 ; 109 $self->{'Thispara'} = ''; 110 return; 111} 112 113#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1141; 115 116 117__END__ 118 119=head1 NAME 120 121Pod::Simple::Text -- format Pod as plaintext 122 123=head1 SYNOPSIS 124 125 perl -MPod::Simple::Text -e \ 126 "exit Pod::Simple::Text->filter(shift)->any_errata_seen" \ 127 thingy.pod 128 129=head1 DESCRIPTION 130 131This class is a formatter that takes Pod and renders it as 132wrapped plaintext. 133 134Its wrapping is done by L<Text::Wrap>, so you can change 135C<$Text::Wrap::columns> as you like. 136 137This is a subclass of L<Pod::Simple> and inherits all its methods. 138 139=head1 SEE ALSO 140 141L<Pod::Simple>, L<Pod::Simple::TextContent>, L<Pod::Text> 142 143=head1 SUPPORT 144 145Questions or discussion about POD and Pod::Simple should be sent to the 146pod-people@perl.org mail list. Send an empty email to 147pod-people-subscribe@perl.org to subscribe. 148 149This module is managed in an open GitHub repository, 150L<https://github.com/perl-pod/pod-simple/>. Feel free to fork and contribute, or 151to clone L<git://github.com/perl-pod/pod-simple.git> and send patches! 152 153Patches against Pod::Simple are welcome. Please send bug reports to 154<bug-pod-simple@rt.cpan.org>. 155 156=head1 COPYRIGHT AND DISCLAIMERS 157 158Copyright (c) 2002 Sean M. Burke. 159 160This library is free software; you can redistribute it and/or modify it 161under the same terms as Perl itself. 162 163This program is distributed in the hope that it will be useful, but 164without any warranty; without even the implied warranty of 165merchantability or fitness for a particular purpose. 166 167=head1 AUTHOR 168 169Pod::Simple was created by Sean M. Burke <sburke@cpan.org>. 170But don't bother him, he's retired. 171 172Pod::Simple is maintained by: 173 174=over 175 176=item * Allison Randal C<allison@perl.org> 177 178=item * Hans Dieter Pearcey C<hdp@cpan.org> 179 180=item * David E. Wheeler C<dwheeler@cpan.org> 181 182=back 183 184=cut 185