This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pod updates (from David Adler, M J T Guy)
[perl5.git] / pod / podchecker.PL
CommitLineData
360aca43
GS
1#!/usr/local/bin/perl
2
3use Config;
4use File::Basename qw(&basename &dirname);
933fea7f 5use Cwd;
360aca43
GS
6
7# List explicitly here the variables you want Configure to
8# generate. Metaconfig only looks for shell variables, so you
9# have to mention them as if they were shell variables, not
10# %Config entries. Thus you write
11# $startperl
12# to ensure Configure will look for $Config{startperl}.
13
3b5ca523
GS
14# This forces PL files to create target in same directory as PL file.
15# This is so that make depend always knows where to find PL derivatives.
933fea7f 16$origdir = cwd;
3b5ca523
GS
17chdir(dirname($0));
18($file = basename($0)) =~ s/\.PL$//;
19$file =~ s/\.pl$//
933fea7f 20 if ($^O eq 'VMS' or $^O eq 'os2' or $^O eq 'dos'); # "case-forgiving"
360aca43
GS
21
22open OUT,">$file" or die "Can't create $file: $!";
23
24print "Extracting $file (with variable substitutions)\n";
25
26# In this section, perl variables will be expanded during extraction.
27# You can use $Config{...} to use Configure variables.
28
29print OUT <<"!GROK!THIS!";
30$Config{'startperl'}
31 eval 'exec perl -S \$0 "\$@"'
32 if 0;
33!GROK!THIS!
34
35# In the following, perl variables are not expanded during extraction.
36
37print OUT <<'!NO!SUBS!';
38#############################################################################
39# podchecker -- command to invoke the podchecker function in Pod::Checker
40#
27f805f4 41# Copyright (c) 1998-1999 by Bradford Appleton. All rights reserved.
360aca43
GS
42# This file is part of "PodParser". PodParser is free software;
43# you can redistribute it and/or modify it under the same terms
44# as Perl itself.
45#############################################################################
46
47use strict;
e3237417 48#use diagnostics;
360aca43
GS
49
50=head1 NAME
51
52podchecker - check the syntax of POD format documentation files
53
54=head1 SYNOPSIS
55
e3237417 56B<podchecker> [B<-help>] [B<-man>] [B<-(no)warnings>] [I<file>S< >...]
360aca43
GS
57
58=head1 OPTIONS AND ARGUMENTS
59
60=over 8
61
62=item B<-help>
63
64Print a brief help message and exit.
65
66=item B<-man>
67
68Print the manual page and exit.
69
e3237417
GS
70=item B<-warnings> B<-nowarnings>
71
72Turn on/off printing of warnings.
73
360aca43
GS
74=item I<file>
75
76The pathname of a POD file to syntax-check (defaults to standard input).
77
78=back
79
80=head1 DESCRIPTION
81
82B<podchecker> will read the given input files looking for POD
83syntax errors in the POD documentation and will print any errors
84it find to STDERR. At the end, it will print a status message
85indicating the number of errors found.
86
87B<podchecker> invokes the B<podchecker()> function exported by B<Pod::Checker>
88Please see L<Pod::Checker/podchecker()> for more details.
89
e3237417
GS
90=head1 RETURN VALUE
91
92B<podchecker> returns a 0 (zero) exit status if all specified
93POD files are ok.
94
95=head1 ERRORS
96
97B<podchecker> returns the exit status 1 if at least one of
98the given POD files has syntax errors.
99
100The status 2 indicates that at least one of the specified
101files does not contain I<any> POD commands.
102
103Status 1 overrides status 2. If you want unambigouus
104results, call B<podchecker> with one single argument only.
105
360aca43
GS
106=head1 SEE ALSO
107
108L<Pod::Parser> and L<Pod::Checker>
109
e3237417 110=head1 AUTHORS
360aca43 111
e3237417
GS
112Brad Appleton E<lt>bradapp@enteract.comE<gt>,
113Marek Rouchal E<lt>marek@saftsack.fs.uni-bayreuth.deE<gt>
360aca43
GS
114
115Based on code for B<Pod::Text::pod2text(1)> written by
116Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
117
118=cut
119
120
121use Pod::Checker;
122use Pod::Usage;
123use Getopt::Long;
124
125## Define options
126my %options = (
127 "help" => 0,
128 "man" => 0,
e3237417 129 "warnings" => 1,
360aca43
GS
130);
131
132## Parse options
e3237417 133GetOptions(\%options, "help", "man", "warnings!") || pod2usage(2);
360aca43
GS
134pod2usage(1) if ($options{help});
135pod2usage(-verbose => 2) if ($options{man});
136
137## Dont default to STDIN if connected to a terminal
138pod2usage(2) if ((@ARGV == 0) && (-t STDIN));
139
140## Invoke podchecker()
e3237417
GS
141my $status = 0;
142@ARGV = ("<&STDIN") unless(@ARGV);
143for (@ARGV) {
144 my $s = podchecker($_, undef, '-warnings' => $options{warnings});
145 if($s > 0) {
146 # errors occurred
147 $status = 1;
148 }
149 elsif($s < 0) {
150 # no pod found
151 $status = 2 unless($status);
152 }
360aca43 153}
e3237417 154exit $status;
360aca43
GS
155
156!NO!SUBS!
157
158close OUT or die "Can't close $file: $!";
159chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
160exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
933fea7f 161chdir $origdir;