1#!/usr/local/bin/perl
2
3use strict;
4use warnings;
5use Config;
6use File::Basename qw(&basename &dirname);
7use Cwd;
8
9# List explicitly here the variables you want Configure to
10# generate.  Metaconfig only looks for shell variables, so you
11# have to mention them as if they were shell variables, not
12# %Config entries.  Thus you write
13#  $startperl
14# to ensure Configure will look for $Config{startperl}.
15
16# This forces PL files to create target in same directory as PL file.
17# This is so that make depend always knows where to find PL derivatives.
18my $origdir = cwd;
19chdir( dirname($0) );
20my $file = basename( $0, '.PL' );
21$file .= '.com' if $^O eq 'VMS';
22
23open my $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#############################################################################
41# pod2usage -- command to print usage messages from embedded pod docs
42#
43# Copyright (c) 1996-2000 by Bradford Appleton. All rights reserved.
44# Copyright (c) 2001-2016 by Marek Rouchal.
45# This file is part of "Pod-Usage". Pod-Usage is free software;
46# you can redistribute it and/or modify it under the same terms
47# as Perl itself.
48#############################################################################
49
50use strict;
51#use diagnostics;
52
53=head1 NAME
54
55pod2usage - print usage messages from embedded pod docs in files
56
57=head1 SYNOPSIS
58
59=over 12
60
61=item B<pod2usage>
62
63[B<-help>]
64[B<-man>]
65[B<-exit>S< >I<exitval>]
66[B<-output>S< >I<outfile>]
67[B<-verbose> I<level>]
68[B<-pathlist> I<dirlist>]
69[B<-formatter> I<module>]
70[B<-utf8>]
71I<file>
72
73=back
74
75=head1 OPTIONS AND ARGUMENTS
76
77=over 8
78
79=item B<-help>
80
81Print a brief help message and exit.
82
83=item B<-man>
84
85Print this command's manual page and exit.
86
87=item B<-exit> I<exitval>
88
89The exit status value to return.
90
91=item B<-output> I<outfile>
92
93The output file to print to. If the special names "-" or ">&1" or ">&STDOUT"
94are used then standard output is used. If ">&2" or ">&STDERR" is used then
95standard error is used.
96
97=item B<-verbose> I<level>
98
99The desired level of verbosity to use:
100
101    1 : print SYNOPSIS only
102    2 : print SYNOPSIS sections and any OPTIONS/ARGUMENTS sections
103    3 : print the entire manpage (similar to running pod2text)
104
105=item B<-pathlist> I<dirlist>
106
107Specifies one or more directories to search for the input file if it
108was not supplied with an absolute path. Each directory path in the given
109list should be separated by a ':' on Unix (';' on MSWin32 and DOS).
110
111=item B<-formatter> I<module>
112
113Which text formatter to use. Default is L<Pod::Text>, or for very old
114Perl versions L<Pod::PlainText>. An alternative would be e.g.
115L<Pod::Text::Termcap>.
116
117=item B<-utf8>
118
119This option assumes that the formatter (see above) understands the option
120"utf8". It turns on generation of utf8 output.
121
122=item I<file>
123
124The pathname of a file containing pod documentation to be output in
125usage message format. If omitted, standard input is read - but the
126output is then formatted with L<Pod::Text> only - unless a specific
127formatter has been specified with B<-formatter>.
128
129=back
130
131=head1 DESCRIPTION
132
133B<pod2usage> will read the given input file looking for pod
134documentation and will print the corresponding usage message.
135If no input file is specified then standard input is read.
136
137B<pod2usage> invokes the B<pod2usage()> function in the B<Pod::Usage>
138module. Please see L<Pod::Usage/pod2usage()>.
139
140=head1 SEE ALSO
141
142L<Pod::Usage>, L<pod2text>, L<Pod::Text>, L<Pod::Text::Termcap>,
143L<perldoc>
144
145=head1 AUTHOR
146
147Please report bugs using L<http://rt.cpan.org>.
148
149Brad Appleton E<lt>bradapp@enteract.comE<gt>
150
151Based on code for B<pod2text(1)> written by
152Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
153
154=cut
155
156use Getopt::Long;
157
158## Define options
159my %options = ();
160my @opt_specs = (
161    'help',
162    'man',
163    'exit=i',
164    'output=s',
165    'pathlist=s',
166    'formatter=s',
167    'verbose=i',
168    'utf8!'
169);
170
171## Parse options
172GetOptions(\%options, @opt_specs)  ||  pod2usage(2);
173$Pod::Usage::Formatter = $options{formatter} if $options{formatter};
174require Pod::Usage;
175Pod::Usage->import();
176pod2usage(1)  if ($options{help});
177pod2usage(VERBOSE => 2)  if ($options{man});
178
179## Dont default to STDIN if connected to a terminal
180pod2usage(2) if ((@ARGV == 0) && (-t STDIN));
181
182if (@ARGV > 1) {
183    print STDERR "pod2usage: Too many filenames given\n\n";
184    pod2usage(2);
185}
186
187my %usage = ();
188$usage{-input}    = shift(@ARGV) || \*STDIN;
189$usage{-exitval}  = $options{'exit'}      if (defined $options{'exit'});
190$usage{-output}   = $options{'output'}    if (defined $options{'output'});
191$usage{-verbose}  = $options{'verbose'}   if (defined $options{'verbose'});
192$usage{-pathlist} = $options{'pathlist'}  if (defined $options{'pathlist'});
193$usage{-utf8}     = $options{'utf8'}      if (defined $options{'utf8'});
194
195pod2usage(\%usage);
196
197
198!NO!SUBS!
199
200close($OUT) or die "Can't close $file: $!";
201chmod( 0755, $file ) or die "Can't reset permissions for $file: $!\n";
202exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
203chdir($origdir);
204