Diff of /bookchecker [000000] .. [e362d3] Maximize Restore

  Switch to unified view

a b/bookchecker
1
#!/usr/bin/perl
2
    eval 'exec perl -S $0 "$@"'
3
        if 0;
4
#############################################################################
5
# bookchecker -- command to invoke podchecker function in inc/Pod/Checker.pm
6
# 
7
# Modification to add 'inc' to library path and command name
8
# Chris Marshall, 22-Jan-2012.
9
#
10
# Copyright (c) 1998-2000 by Bradford Appleton. All rights reserved.
11
# This file is part of "PodParser". PodParser is free software;
12
# you can redistribute it and/or modify it under the same terms
13
# as Perl itself.
14
#############################################################################
15
16
use strict;
17
use lib ( qw(inc) );
18
19
#use diagnostics;
20
21
=head1 NAME
22
23
podchecker - check the syntax of POD format documentation files
24
25
=head1 SYNOPSIS
26
27
B<podchecker> [B<-help>] [B<-man>] [B<-(no)warnings>] [I<file>S< >...]
28
29
=head1 OPTIONS AND ARGUMENTS
30
31
=over 8
32
33
=item B<-help>
34
35
Print a brief help message and exit.
36
37
=item B<-man>
38
39
Print the manual page and exit.
40
41
=item B<-warnings> B<-nowarnings>
42
43
Turn on/off printing of warnings. Repeating B<-warnings> increases the
44
warning level, i.e. more warnings are printed. Currently increasing to
45
level two causes flagging of unescaped "E<lt>,E<gt>" characters.
46
47
=item I<file>
48
49
The pathname of a POD file to syntax-check (defaults to standard input).
50
51
=back
52
53
=head1 DESCRIPTION
54
55
B<podchecker> will read the given input files looking for POD
56
syntax errors in the POD documentation and will print any errors
57
it find to STDERR. At the end, it will print a status message
58
indicating the number of errors found.
59
60
Directories are ignored, an appropriate warning message is printed.
61
62
B<podchecker> invokes the B<podchecker()> function exported by B<Pod::Checker>
63
Please see L<Pod::Checker/podchecker()> for more details.
64
65
=head1 RETURN VALUE
66
67
B<podchecker> returns a 0 (zero) exit status if all specified
68
POD files are ok.
69
70
=head1 ERRORS
71
72
B<podchecker> returns the exit status 1 if at least one of
73
the given POD files has syntax errors.
74
75
The status 2 indicates that at least one of the specified 
76
files does not contain I<any> POD commands.
77
78
Status 1 overrides status 2. If you want unambiguous
79
results, call B<podchecker> with one single argument only.
80
81
=head1 SEE ALSO
82
83
L<Pod::Parser> and L<Pod::Checker>
84
85
=head1 AUTHORS
86
87
Please report bugs using L<http://rt.cpan.org>.
88
89
Brad Appleton E<lt>bradapp@enteract.comE<gt>,
90
Marek Rouchal E<lt>marekr@cpan.orgE<gt>
91
92
Based on code for B<Pod::Text::pod2text(1)> written by
93
Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
94
95
=cut
96
97
98
use Pod::Checker;
99
use Pod::Usage;
100
use Getopt::Long;
101
102
## Define options
103
my %options;
104
105
## Parse options
106
GetOptions(\%options, qw(help man warnings+ nowarnings))  ||  pod2usage(2);
107
pod2usage(1)  if ($options{help});
108
pod2usage(-verbose => 2)  if ($options{man});
109
110
if($options{nowarnings}) {
111
  $options{warnings} = 0;
112
}
113
elsif(!defined $options{warnings}) {
114
  $options{warnings} = 1; # default is warnings on
115
}
116
117
## Dont default to STDIN if connected to a terminal
118
pod2usage(2) if ((@ARGV == 0) && (-t STDIN));
119
120
## Invoke podchecker()
121
my $status = 0;
122
@ARGV = qw(-) unless(@ARGV);
123
for my $podfile (@ARGV) {
124
    if($podfile eq '-') {
125
      $podfile = '<&STDIN';
126
    }
127
    elsif(-d $podfile) {
128
      warn "podchecker: Warning: Ignoring directory '$podfile'\n";
129
      next;
130
    }
131
    my $errors =
132
      podchecker($podfile, undef, '-warnings' => $options{warnings});
133
    if($errors > 0) {
134
        # errors occurred
135
        $status = 1;
136
        printf STDERR ("%s has %d pod syntax %s.\n",
137
          $podfile, $errors,
138
          ($errors == 1) ? 'error' : 'errors');
139
    }
140
    elsif($errors < 0) {
141
        # no pod found
142
        $status = 2 unless($status);
143
        print STDERR "$podfile does not contain any pod commands.\n";
144
    }
145
    else {
146
        print STDERR "$podfile pod syntax OK.\n";
147
    }
148
}
149
exit $status;
150