xref: /openbsd-src/gnu/usr.bin/perl/cpan/Pod-Simple/lib/Pod/Simple/Checker.pm (revision 99fd087599a8791921855f21bd7e36130f39aadc)
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.35';
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'} =~ s/$Pod::Simple::shy//g;
95  my $out = Text::Wrap::wrap($indent, $indent, $self->{'Thispara'} .= "\n");
96  $out =~ s/$Pod::Simple::nbsp/ /g;
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  $self->{'Thispara'} =~ s/$Pod::Simple::nbsp/ /g;
111  $self->{'Thispara'} =~ s/$Pod::Simple::shy//g;
112
113  my $i = ' ' x ( 2 * $self->{'Indent'} + 4);
114
115  $self->{'Thispara'} =~ s/^/$i/mg;
116
117  print { $self->{'output_fh'} }   '',
118    $self->{'Thispara'},
119    "\n\n"
120  ;
121  $self->{'Thispara'} = '';
122  return;
123}
124
125#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1261;
127
128__END__
129
130=head1 NAME
131
132Pod::Simple::Checker -- check the Pod syntax of a document
133
134=head1 SYNOPSIS
135
136  perl -MPod::Simple::Checker -e \
137   "exit Pod::Simple::Checker->filter(shift)->any_errata_seen" \
138   thingy.pod
139
140=head1 DESCRIPTION
141
142This class is for checking the syntactic validity of Pod.
143It works by basically acting like a simple-minded version of
144L<Pod::Simple::Text> that formats only the "Pod Errors" section
145(if Pod::Simple even generates one for the given document).
146
147This is a subclass of L<Pod::Simple> and inherits all its methods.
148
149=head1 SEE ALSO
150
151L<Pod::Simple>, L<Pod::Simple::Text>, L<Pod::Checker>
152
153=head1 SUPPORT
154
155Questions or discussion about POD and Pod::Simple should be sent to the
156pod-people@perl.org mail list. Send an empty email to
157pod-people-subscribe@perl.org to subscribe.
158
159This module is managed in an open GitHub repository,
160L<https://github.com/perl-pod/pod-simple/>. Feel free to fork and contribute, or
161to clone L<git://github.com/perl-pod/pod-simple.git> and send patches!
162
163Patches against Pod::Simple are welcome. Please send bug reports to
164<bug-pod-simple@rt.cpan.org>.
165
166=head1 COPYRIGHT AND DISCLAIMERS
167
168Copyright (c) 2002 Sean M. Burke.
169
170This library is free software; you can redistribute it and/or modify it
171under the same terms as Perl itself.
172
173This program is distributed in the hope that it will be useful, but
174without any warranty; without even the implied warranty of
175merchantability or fitness for a particular purpose.
176
177=head1 AUTHOR
178
179Pod::Simple was created by Sean M. Burke <sburke@cpan.org>.
180But don't bother him, he's retired.
181
182Pod::Simple is maintained by:
183
184=over
185
186=item * Allison Randal C<allison@perl.org>
187
188=item * Hans Dieter Pearcey C<hdp@cpan.org>
189
190=item * David E. Wheeler C<dwheeler@cpan.org>
191
192=back
193
194=cut
195