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