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