1
2# A quite dimwitted pod2plaintext that need only know how to format whatever
3# text comes out of Pod::BlackBox's _gen_errata
4
5require 5;
6package Pod::Simple::Checker;
7use strict;
8use Carp ();
9use Pod::Simple::Methody ();
10use Pod::Simple ();
11use vars qw( @ISA $VERSION );
12$VERSION = '3.14';
13@ISA = ('Pod::Simple::Methody');
14BEGIN { *DEBUG = defined(&Pod::Simple::DEBUG)
15          ? \&Pod::Simple::DEBUG
16          : sub() {0}
17      }
18
19use Text::Wrap 98.112902 (); # was 2001.0131, but I don't think we need that
20$Text::Wrap::wrap = 'overflow';
21#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22
23sub any_errata_seen {  # read-only accessor
24  return $_[1]->{'Errata_seen'};
25}
26
27sub new {
28  my $self = shift;
29  my $new = $self->SUPER::new(@_);
30  $new->{'output_fh'} ||= *STDOUT{IO};
31  $new->nix_X_codes(1);
32  $new->nbsp_for_S(1);
33  $new->{'Thispara'} = '';
34  $new->{'Indent'} = 0;
35  $new->{'Indentstring'} = '   ';
36  $new->{'Errata_seen'} = 0;
37  return $new;
38}
39
40#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41
42sub handle_text {  $_[0]{'Errata_seen'} and $_[0]{'Thispara'} .= $_[1] }
43
44sub start_Para  {  $_[0]{'Thispara'} = '' }
45
46sub start_head1 {
47  if($_[0]{'Errata_seen'}) {
48    $_[0]{'Thispara'} = '';
49  } else {
50    if($_[1]{'errata'}) { # start of errata!
51      $_[0]{'Errata_seen'} = 1;
52      $_[0]{'Thispara'} = $_[0]{'source_filename'} ?
53        "$_[0]{'source_filename'} -- " : ''
54    }
55  }
56}
57sub start_head2 {  $_[0]{'Thispara'} = '' }
58sub start_head3 {  $_[0]{'Thispara'} = '' }
59sub start_head4 {  $_[0]{'Thispara'} = '' }
60
61sub start_Verbatim    { $_[0]{'Thispara'} = ''   }
62sub start_item_bullet { $_[0]{'Thispara'} = '* ' }
63sub start_item_number { $_[0]{'Thispara'} = "$_[1]{'number'}. "  }
64sub start_item_text   { $_[0]{'Thispara'} = ''   }
65
66sub start_over_bullet  { ++$_[0]{'Indent'} }
67sub start_over_number  { ++$_[0]{'Indent'} }
68sub start_over_text    { ++$_[0]{'Indent'} }
69sub start_over_block   { ++$_[0]{'Indent'} }
70
71sub   end_over_bullet  { --$_[0]{'Indent'} }
72sub   end_over_number  { --$_[0]{'Indent'} }
73sub   end_over_text    { --$_[0]{'Indent'} }
74sub   end_over_block   { --$_[0]{'Indent'} }
75
76
77# . . . . . Now the actual formatters:
78
79sub end_head1       { $_[0]->emit_par(-4) }
80sub end_head2       { $_[0]->emit_par(-3) }
81sub end_head3       { $_[0]->emit_par(-2) }
82sub end_head4       { $_[0]->emit_par(-1) }
83sub end_Para        { $_[0]->emit_par( 0) }
84sub end_item_bullet { $_[0]->emit_par( 0) }
85sub end_item_number { $_[0]->emit_par( 0) }
86sub end_item_text   { $_[0]->emit_par(-2) }
87
88sub emit_par {
89  return unless $_[0]{'Errata_seen'};
90  my($self, $tweak_indent) = splice(@_,0,2);
91  my $indent = ' ' x ( 2 * $self->{'Indent'} + ($tweak_indent||0) );
92   # Yes, 'STRING' x NEGATIVE gives '', same as 'STRING' x 0
93
94  $self->{'Thispara'} =~ tr{\xAD}{}d if Pod::Simple::ASCII;
95  my $out = Text::Wrap::wrap($indent, $indent, $self->{'Thispara'} .= "\n");
96  $out =~ tr{\xA0}{ } if Pod::Simple::ASCII;
97  print {$self->{'output_fh'}} $out,
98    #"\n"
99  ;
100  $self->{'Thispara'} = '';
101
102  return;
103}
104
105# . . . . . . . . . . And then off by its lonesome:
106
107sub end_Verbatim  {
108  return unless $_[0]{'Errata_seen'};
109  my $self = shift;
110  if(Pod::Simple::ASCII) {
111    $self->{'Thispara'} =~ tr{\xA0}{ };
112    $self->{'Thispara'} =~ tr{\xAD}{}d;
113  }
114
115  my $i = ' ' x ( 2 * $self->{'Indent'} + 4);
116
117  $self->{'Thispara'} =~ s/^/$i/mg;
118
119  print { $self->{'output_fh'} }   '',
120    $self->{'Thispara'},
121    "\n\n"
122  ;
123  $self->{'Thispara'} = '';
124  return;
125}
126
127#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1281;
129
130__END__
131
132=head1 NAME
133
134Pod::Simple::Checker -- check the Pod syntax of a document
135
136=head1 SYNOPSIS
137
138  perl -MPod::Simple::Checker -e \
139   "exit Pod::Simple::Checker->filter(shift)->any_errata_seen" \
140   thingy.pod
141
142=head1 DESCRIPTION
143
144This class is for checking the syntactic validity of Pod.
145It works by basically acting like a simple-minded version of
146L<Pod::Simple::Text> that formats only the "Pod Errors" section
147(if Pod::Simple even generates one for the given document).
148
149This is a subclass of L<Pod::Simple> and inherits all its methods.
150
151=head1 SEE ALSO
152
153L<Pod::Simple>, L<Pod::Simple::Text>, L<Pod::Checker>
154
155=head1 SUPPORT
156
157Questions or discussion about POD and Pod::Simple should be sent to the
158pod-people@perl.org mail list. Send an empty email to
159pod-people-subscribe@perl.org to subscribe.
160
161This module is managed in an open GitHub repository,
162L<http://github.com/theory/pod-simple/>. Feel free to fork and contribute, or
163to clone L<git://github.com/theory/pod-simple.git> and send patches!
164
165Patches against Pod::Simple are welcome. Please send bug reports to
166<bug-pod-simple@rt.cpan.org>.
167
168=head1 COPYRIGHT AND DISCLAIMERS
169
170Copyright (c) 2002 Sean M. Burke.
171
172This library is free software; you can redistribute it and/or modify it
173under the same terms as Perl itself.
174
175This program is distributed in the hope that it will be useful, but
176without any warranty; without even the implied warranty of
177merchantability or fitness for a particular purpose.
178
179=head1 AUTHOR
180
181Pod::Simple was created by Sean M. Burke <sburke@cpan.org>.
182But don't bother him, he's retired.
183
184Pod::Simple is maintained by:
185
186=over
187
188=item * Allison Randal C<allison@perl.org>
189
190=item * Hans Dieter Pearcey C<hdp@cpan.org>
191
192=item * David E. Wheeler C<dwheeler@cpan.org>
193
194=back
195
196=cut
197