This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[REPATCH 5.005_61] Re: perldiag.pod omissions
[perl5.git] / pod / podselect.PL
CommitLineData
360aca43
GS
1#!/usr/local/bin/perl
2
3use Config;
4use File::Basename qw(&basename &dirname);
5
6# List explicitly here the variables you want Configure to
7# generate. Metaconfig only looks for shell variables, so you
8# have to mention them as if they were shell variables, not
9# %Config entries. Thus you write
10# $startperl
11# to ensure Configure will look for $Config{startperl}.
12
92c28edd
JH
13# This forces PL files to create target in same directory as PL file.
14# This is so that make depend always knows where to find PL derivatives.
15chdir(dirname($0));
16($file = basename($0)) =~ s/\.PL$//;
17$file =~ s/\.pl$//
18 if ($^O eq 'VMS' or $^O eq 'os2'); # "case-forgiving"
360aca43
GS
19
20open OUT,">$file" or die "Can't create $file: $!";
21
22print "Extracting $file (with variable substitutions)\n";
23
24# In this section, perl variables will be expanded during extraction.
25# You can use $Config{...} to use Configure variables.
26
27print OUT <<"!GROK!THIS!";
28$Config{'startperl'}
29 eval 'exec perl -S \$0 "\$@"'
30 if 0;
31!GROK!THIS!
32
33# In the following, perl variables are not expanded during extraction.
34
35print OUT <<'!NO!SUBS!';
36
37#############################################################################
38# podselect -- command to invoke the podselect function in Pod::Select
39#
40# Derived from Tom Christiansen's pod2text script.
41# (with extensive modifications)
42#
43# Copyright (c) 1996 Bradford Appleton. All rights reserved.
44# This file is part of "PodParser". PodParser is free software;
45# you can redistribute it and/or modify it under the same terms
46# as Perl itself.
47#############################################################################
48
49use strict;
50use diagnostics;
51
52=head1 NAME
53
54podselect - print selected sections of pod documentation on standard output
55
56=head1 SYNOPSIS
57
58B<podselect> [B<-help>] [B<-man>] [B<-section>S< >I<section-spec>]
59[I<file>S< >...]
60
61=head1 OPTIONS AND ARGUMENTS
62
63=over 8
64
65=item B<-help>
66
67Print a brief help message and exit.
68
69=item B<-man>
70
71Print the manual page and exit.
72
73=item B<-section>S< >I<section-spec>
74
75Specify a section to include in the output.
76See L<Pod::Parser/"SECTION SPECIFICATIONS">
77for the format to use for I<section-spec>.
78This option may be given multiple times on the command line.
79
80=item I<file>
81
82The pathname of a file from which to select sections of pod
83documentation (defaults to standard input).
84
85=back
86
87=head1 DESCRIPTION
88
89B<podselect> will read the given input files looking for pod
90documentation and will print out (in raw pod format) all sections that
91match one ore more of the given section specifications. If no section
92specifications are given than all pod sections encountered are output.
93
94B<podselect> invokes the B<podselect()> function exported by B<Pod::Select>
95Please see L<Pod::Select/podselect()> for more details.
96
97=head1 SEE ALSO
98
99L<Pod::Parser> and L<Pod::Select>
100
101=head1 AUTHOR
102
103Brad Appleton E<lt>bradapp@enteract.comE<gt>
104
105Based on code for B<Pod::Text::pod2text(1)> written by
106Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
107
108=cut
109
110use Pod::Select;
111use Pod::Usage;
112use Getopt::Long;
113
114## Define options
115my %options = (
116 "help" => 0,
117 "man" => 0,
118 "sections" => [],
119);
120
121## Parse options
122GetOptions(\%options, "help", "man", "sections|select=s@") || pod2usage(2);
123pod2usage(1) if ($options{help});
124pod2usage(-verbose => 2) if ($options{man});
125
126## Dont default to STDIN if connected to a terminal
127pod2usage(2) if ((@ARGV == 0) && (-t STDIN));
128
129## Invoke podselect().
130if (@{ $options{"sections"} } > 0) {
131 podselect({ -sections => $options{"sections"} }, @ARGV);
132}
133else {
134 podselect(@ARGV);
135}
136
137
138!NO!SUBS!
139
140close OUT or die "Can't close $file: $!";
141chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
142exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';