mysql => Pg
[bioperl-live.git] / maintenance / pod.pl
blobdf1fae62327366e284051baaba51c3f4c41cffe9
1 #!/usr/bin/perl
3 =head1 NAME
5 pod.pl - check the POD documentation syntax in modules and scripts
7 =head1 SYNOPSIS
9 B<pod.pl> [B<-d|--dir> path ] [B<-v|--verbose>] B<-b|--blankline>
10 [B<-?|-h|--help>]
12 =head1 DESCRIPTION
14 Checks Plain Old Documentation (POD) with highest possible stringency
15 in every bioperl module and script in CVS modules 'core' and 'run'.
17 Amounts to same as running
19 podchecker -warnings -warnings
21 on every file.
23 =head2 Results
25 The results are written into file '/tmp/bioperl_pod_check' and
26 displayed after the run. The output is filtered not to show
27 confirmations of correct syntax. The result file is not removed.
29 The aim is to have as few warnings, and no errors, as possible. Links
30 to web URLs give a warning but that seems to be spurious, so they are
31 filtered out. Currently there are a few cases of "multiple occurrence
32 of link target" in several modules which are harmless.
34 =head1 SEE ALSO
36 L<podchecker>, L<Pod::Checker>
38 =cut
40 use File::Find;
41 use Pod::Checker;
42 use Getopt::Long;
43 use strict;
45 sub podcheck;
46 sub blankline;
49 ## Directories to check
51 my @dirs = qw( ../Bio/ ../scripts . );
53 # command line options
54 my ($verbose, $blankline, $dir, $help) = (0, undef, undef, undef);
55 GetOptions(
56 'v|verbose' => \$verbose,
57 'dir:s' => \$dir,
58 'blankline' => \$blankline,
59 'h|help|?' => sub{ exec('perldoc',$0); exit(0) }
62 # setup
63 my $tmpfile = '/tmp/bioperl_pod_check';
64 our %POD_CHECKER_OPTIONS = ( '-warnings' => 2 );
65 our %FIND_OPTIONS = ( wanted => \&podcheck, no_chdir => 1 );
67 # run
68 open (F, ">$tmpfile") || die "can't open file $tmpfile: $!";
69 $FIND_OPTIONS{wanted} = \&blankline if $blankline;
71 if ($dir) {
72 find \%FIND_OPTIONS, $dir;
73 } else {
74 find \%FIND_OPTIONS, @dirs;
76 close F;
77 open (F, "grep -v OK $tmpfile|") || die "can't open file $tmpfile: $!";
78 while (<F>) { print unless /http/ and /non-escaped/ }
81 # this is where the action is
82 sub podcheck {
83 return unless /\.PLS$/ or /\.p[ml]$/ ;
84 return unless -e $_;
85 print "$_\n" if $verbose;
86 my $checker = Pod::Checker->new( %POD_CHECKER_OPTIONS );
87 $checker->parse_from_file($_, \*F);
88 print "$_\tno POD\n" if $checker->num_errors() < 0;
91 =head1 OPTIONS
93 =over 3
95 =item B<-d | --dir> path
97 Overides the default directories to check by one directory 'path' and
98 all its subdirectories.
100 =item B<-b | --blankline>
102 Checks POD command paragraphs (lines starting with '=' character) for
103 preceding nonblank lines. These lines are printed out with '++'.
105 Also, if verbose is turned on, it will report on lines whitespace
106 characters which prevent paragrafs to be recognised by older POD
107 parsers (marked with '+'). Modern perlpod parsers (5.6.0 and later, I
108 suppose) allow for whitespace lines surrounding command lines, but
109 since bioperl still supports older versions, these lines should be
110 cleaned to contain only '\n' and no space or tab characters.
113 See: L<perlpodspec>
116 =cut
118 sub blankline {
119 return unless /\.PLS$/ or /\.p[ml]$/ ;
120 return unless -e $_;
121 my $file = $_;
122 open (F, $_) or warn "can't open file $_: $!" && return;
123 local $/="";
124 while (<F>) {
125 print "$file: +|$1|\n" if /[ \t]\n(=[a-z][^\n]+$)/m and $verbose;
126 print "$file: ++|$1|\n" if /\w\n(=[a-z][^\n]+$)/m and $verbose;
127 print "$file:|$1|+\n" if /(^=[a-z][^\n]+)\n[\t ]/m;
128 #print "$file:|$1|++\n" if /(^=[^\n]+)\n\w/m;
130 close F;
133 __END__
135 =item B<-v | --verbose>
137 Show the progress through files during the POD checking.
139 =item B<-? | -h | --help>
141 This help text.
143 =back
145 =head1 FEEDBACK
147 =head2 Mailing Lists
149 User feedback is an integral part of the evolution of this and other
150 Bioperl modules. Send your comments and suggestions preferably to
151 the Bioperl mailing list. Your participation is much appreciated.
153 bioperl-l@bioperl.org - General discussion
154 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
156 =head2 Reporting Bugs
158 Report bugs to the Bioperl bug tracking system to help us keep track
159 of the bugs and their resolution. Bug reports can be submitted via the
160 web:
162 https://redmine.open-bio.org/projects/bioperl/
164 =head1 AUTHOR - Heikki Lehvaslaiho
166 Email heikki-at-bioperl-dot-org
168 =cut
171 # find . -name '*.pm' -print | xargs perl -e '$/=""; while (<>) {$n = $1 if /^package\s+([\w:]+)/; print "$n:|$1|" if /(\s\s^=[^\n]+$)/m ; }' ;
173 # find . -name '*.pm' -print | xargs perl -e '$/=""; while (<>) {$n = $1 if /^package\s+([\w:]+)/; print "$n:|$1|\n" if /(^=[^\n]+\n[\t ])/m ; }' ;