B::clearsym
[p5sagit/p5-mst-13.2.git] / pod / podselect.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"
360aca43 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#############################################################################
40# podselect -- command to invoke the podselect function in Pod::Select
41#
42# Derived from Tom Christiansen's pod2text script.
43# (with extensive modifications)
44#
45# Copyright (c) 1996 Bradford Appleton. All rights reserved.
46# This file is part of "PodParser". PodParser is free software;
47# you can redistribute it and/or modify it under the same terms
48# as Perl itself.
49#############################################################################
50
51use strict;
52use diagnostics;
53
54=head1 NAME
55
56podselect - print selected sections of pod documentation on standard output
57
58=head1 SYNOPSIS
59
60B<podselect> [B<-help>] [B<-man>] [B<-section>S< >I<section-spec>]
61[I<file>S< >...]
62
63=head1 OPTIONS AND ARGUMENTS
64
65=over 8
66
67=item B<-help>
68
69Print a brief help message and exit.
70
71=item B<-man>
72
73Print the manual page and exit.
74
75=item B<-section>S< >I<section-spec>
76
77Specify a section to include in the output.
78See L<Pod::Parser/"SECTION SPECIFICATIONS">
79for the format to use for I<section-spec>.
80This option may be given multiple times on the command line.
81
82=item I<file>
83
84The pathname of a file from which to select sections of pod
85documentation (defaults to standard input).
86
87=back
88
89=head1 DESCRIPTION
90
91B<podselect> will read the given input files looking for pod
92documentation and will print out (in raw pod format) all sections that
93match one ore more of the given section specifications. If no section
94specifications are given than all pod sections encountered are output.
95
96B<podselect> invokes the B<podselect()> function exported by B<Pod::Select>
97Please see L<Pod::Select/podselect()> for more details.
98
99=head1 SEE ALSO
100
101L<Pod::Parser> and L<Pod::Select>
102
103=head1 AUTHOR
104
105Brad Appleton E<lt>bradapp@enteract.comE<gt>
106
107Based on code for B<Pod::Text::pod2text(1)> written by
108Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
109
110=cut
111
112use Pod::Select;
113use Pod::Usage;
114use Getopt::Long;
115
116## Define options
117my %options = (
118 "help" => 0,
119 "man" => 0,
120 "sections" => [],
121);
122
123## Parse options
124GetOptions(\%options, "help", "man", "sections|select=s@") || pod2usage(2);
125pod2usage(1) if ($options{help});
126pod2usage(-verbose => 2) if ($options{man});
127
128## Dont default to STDIN if connected to a terminal
129pod2usage(2) if ((@ARGV == 0) && (-t STDIN));
130
131## Invoke podselect().
132if (@{ $options{"sections"} } > 0) {
133 podselect({ -sections => $options{"sections"} }, @ARGV);
134}
135else {
136 podselect(@ARGV);
137}
138
139
140!NO!SUBS!
141
142close OUT or die "Can't close $file: $!";
143chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
144exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
933fea7f 145chdir $origdir;