extra code in pp_concat, Take 2
[p5sagit/p5-mst-13.2.git] / pod / podchecker.PL
CommitLineData
360aca43 1#!/usr/local/bin/perl
2
3use Config;
4use File::Basename qw(&basename &dirname);
933fea7f 5use Cwd;
360aca43 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 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 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"
b4bc034f 21$file .= '.com' if $^O eq 'VMS';
360aca43 22
23open OUT,">$file" or die "Can't create $file: $!";
24
25print "Extracting $file (with variable substitutions)\n";
26
27# In this section, perl variables will be expanded during extraction.
28# You can use $Config{...} to use Configure variables.
29
30print OUT <<"!GROK!THIS!";
31$Config{'startperl'}
32 eval 'exec perl -S \$0 "\$@"'
33 if 0;
34!GROK!THIS!
35
36# In the following, perl variables are not expanded during extraction.
37
38print OUT <<'!NO!SUBS!';
39#############################################################################
40# podchecker -- command to invoke the podchecker function in Pod::Checker
41#
92e3d63a 42# Copyright (c) 1998-2000 by Bradford Appleton. All rights reserved.
360aca43 43# This file is part of "PodParser". PodParser is free software;
44# you can redistribute it and/or modify it under the same terms
45# as Perl itself.
46#############################################################################
47
48use strict;
e3237417 49#use diagnostics;
360aca43 50
51=head1 NAME
52
53podchecker - check the syntax of POD format documentation files
54
55=head1 SYNOPSIS
56
e3237417 57B<podchecker> [B<-help>] [B<-man>] [B<-(no)warnings>] [I<file>S< >...]
360aca43 58
59=head1 OPTIONS AND ARGUMENTS
60
61=over 8
62
63=item B<-help>
64
65Print a brief help message and exit.
66
67=item B<-man>
68
69Print the manual page and exit.
70
e3237417 71=item B<-warnings> B<-nowarnings>
72
92e3d63a 73Turn on/off printing of warnings. Repeating B<-warnings> increases the
74warning level, i.e. more warnings are printed. Currently increasing to
75level two causes flagging of unescaped "E<lt>,E<gt>" characters.
e3237417 76
360aca43 77=item I<file>
78
79The pathname of a POD file to syntax-check (defaults to standard input).
80
81=back
82
83=head1 DESCRIPTION
84
85B<podchecker> will read the given input files looking for POD
86syntax errors in the POD documentation and will print any errors
87it find to STDERR. At the end, it will print a status message
88indicating the number of errors found.
89
92e3d63a 90Directories are ignored, an appropriate warning message is printed.
91
360aca43 92B<podchecker> invokes the B<podchecker()> function exported by B<Pod::Checker>
93Please see L<Pod::Checker/podchecker()> for more details.
94
e3237417 95=head1 RETURN VALUE
96
97B<podchecker> returns a 0 (zero) exit status if all specified
98POD files are ok.
99
100=head1 ERRORS
101
102B<podchecker> returns the exit status 1 if at least one of
103the given POD files has syntax errors.
104
105The status 2 indicates that at least one of the specified
106files does not contain I<any> POD commands.
107
108Status 1 overrides status 2. If you want unambigouus
109results, call B<podchecker> with one single argument only.
110
360aca43 111=head1 SEE ALSO
112
113L<Pod::Parser> and L<Pod::Checker>
114
e3237417 115=head1 AUTHORS
360aca43 116
7d8277e2 117Please report bugs using L<http://rt.cpan.org>.
118
e3237417 119Brad Appleton E<lt>bradapp@enteract.comE<gt>,
7d8277e2 120Marek Rouchal E<lt>marekr@cpan.orgE<gt>
360aca43 121
122Based on code for B<Pod::Text::pod2text(1)> written by
123Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
124
125=cut
126
127
128use Pod::Checker;
129use Pod::Usage;
130use Getopt::Long;
131
132## Define options
92e3d63a 133my %options;
360aca43 134
135## Parse options
92e3d63a 136GetOptions(\%options, qw(help man warnings+ nowarnings)) || pod2usage(2);
360aca43 137pod2usage(1) if ($options{help});
138pod2usage(-verbose => 2) if ($options{man});
139
92e3d63a 140if($options{nowarnings}) {
141 $options{warnings} = 0;
142}
143elsif(!defined $options{warnings}) {
144 $options{warnings} = 1; # default is warnings on
145}
146
360aca43 147## Dont default to STDIN if connected to a terminal
148pod2usage(2) if ((@ARGV == 0) && (-t STDIN));
149
150## Invoke podchecker()
e3237417 151my $status = 0;
92e3d63a 152@ARGV = qw(-) unless(@ARGV);
c23d1eb0 153for my $podfile (@ARGV) {
154 if($podfile eq '-') {
155 $podfile = "<&STDIN";
92e3d63a 156 }
c23d1eb0 157 elsif(-d $podfile) {
158 warn "podchecker: Warning: Ignoring directory '$podfile'\n";
92e3d63a 159 next;
160 }
c23d1eb0 161 my $errors = podchecker($podfile, undef, '-warnings' => $options{warnings});
162 if($errors > 0) {
e3237417 163 # errors occurred
c23d1eb0 164 printf STDERR ("%s has %d pod syntax %s.\n",
165 $podfile, $errors, ($errors == 1) ? "error" : "errors");
e3237417 166 $status = 1;
167 }
c23d1eb0 168 elsif($errors < 0) {
169 print STDERR "$podfile does not contain any pod commands.\n";
e3237417 170 # no pod found
171 $status = 2 unless($status);
172 }
c23d1eb0 173 else {
174 print STDERR "$podfile pod syntax OK.\n";
175 }
360aca43 176}
e3237417 177exit $status;
360aca43 178
179!NO!SUBS!
180
181close OUT or die "Can't close $file: $!";
182chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
183exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
933fea7f 184chdir $origdir;