4 use File::Basename qw(&basename &dirname);
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
11 # to ensure Configure will look for $Config{startperl}.
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.
16 $file = basename($0, '.PL');
17 $file .= '.com' if $^O eq 'VMS';
19 open OUT,">$file" or die "Can't create $file: $!";
21 print "Extracting $file (with variable substitutions)\n";
23 # In this section, perl variables will be expanded during extraction.
24 # You can use $Config{...} to use Configure variables.
26 print OUT <<"!GROK!THIS!";
28 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
29 if \$running_under_some_shell;
32 push \@pagers, "$Config{'pager'}" if -x "$Config{'pager'}";
35 # In the following, perl variables are not expanded during extraction.
37 print OUT <<'!NO!SUBS!';
40 # Perldoc revision #1 -- look up a piece of documentation in .pod format that
41 # is embedded in the perl installation tree.
43 # This is not to be confused with Tom Christianson's perlman, which is a
44 # man replacement, written in perl. This perldoc is strictly for reading
45 # the perl manuals, though it too is written in perl.
48 $me = $0; # Editing $0 is unportable
51 Usage: $me [-h] [-v] [-t] [-u] [-m] [-l] [-F] [-X] PageName|ModuleName|ProgramName
55 The -h option prints more help. Also try "perldoc perldoc" to get
56 aquainted with the system.
66 $Is_VMS = $^O eq 'VMS';
67 $Is_MSWin32 = $^O eq 'MSWin32';
68 $Is_Dos = $^O eq 'dos';
72 # Erase evidence of previous errors (if any), so exit status is simple.
75 perldoc [options] PageName|ModuleName|ProgramName...
76 perldoc [options] -f BuiltinFunction
77 perldoc [options] -q FAQRegex
80 -h Display this help message
81 -t Display pod using pod2text instead of pod2man and nroff
82 (-t is the default on win32)
83 -u Display unformatted pod text
84 -m Display module's file in its entirety
85 -l Display the module's file name
86 -F Arguments are file names, not modules
87 -v Verbosely describe what's going on
88 -X use index if present (looks for pod.idx at $Config{archlib})
91 PageName|ModuleName...
92 is the name of a piece of documentation that you want to look at. You
93 may either give a descriptive name of the page (as in the case of
94 `perlfunc') the name of a module, either like `Term::Info',
95 `Term/Info', the partial name of a module, like `info', or
96 `makemaker', or the name of a program, like `perldoc'.
99 is the name of a perl function. Will extract documentation from
103 is a regex. Will search perlfaq[1-9] for and extract any
104 questions that match.
106 Any switches in the PERLDOC environment variable will be used before the
107 command line arguments. The optional pod index file contains a list of
108 filenames, one per line.
113 use Text::ParseWords;
116 unshift(@ARGV,shellwords($ENV{"PERLDOC"}));
118 getopts("mhtluvFf:Xq:") || usage;
120 usage if $opt_h || $opt_h; # avoid -w warning
122 $podidx = "$Config{'archlib'}/pod.idx";
123 $podidx = "" if $opt_X || !-f "pod.idx" && !-r _ && -M _ > 7;
125 if ($opt_t + $opt_u + $opt_m + $opt_l > 1) {
126 usage("only one of -t, -u, -m or -l")
127 } elsif ($Is_MSWin32 || $Is_Dos) {
128 $opt_t = 1 unless $opt_t + $opt_u + $opt_m + $opt_l;
131 if ($opt_t) { require Pod::Text; import Pod::Text; }
134 @pages = ("perlfunc");
136 @pages = ("perlfaq1" .. "perlfaq9");
141 # Does this look like a module or extension directory?
142 if (-f "Makefile.PL") {
143 # Add ., lib and blib/* libs to @INC (if they exist)
145 unshift(@INC, 'lib') if -d 'lib';
146 require ExtUtils::testlib;
152 my($file, $readit) = @_;
153 return 1 if !$readit && $file =~ /\.pod$/i;
168 # on a case-forgiving file system we can simply use -f $file
169 if ($Is_VMS or $Is_MSWin32 or $Is_Dos or $^O eq 'os2') {
170 return $file if -f $file and -r _;
171 warn "Ignored $file: unreadable\n" if -f _;
177 foreach $p (split(/\//, $file)){
182 if ( $p eq $global_target) {
183 $tmp_path = join ('/', @p);
185 for (@global_found) {
186 $path_f = 1 if $_ eq $tmp_path;
188 push (@global_found, $tmp_path) unless $path_f;
189 print STDERR "Found as @p but directory\n" if $opt_v;
191 } elsif (-f _ && -r _) {
194 warn "Ignored $try: unreadable\n";
199 while ($cip=readdir(DIR)) {
200 if (lc $cip eq $lcp){
206 return "" unless $found;
208 return "@p" if -f "@p" and -r _;
209 warn "Ignored $file: unreadable\n" if -f _;
212 return; # is not a file
218 $file = minus_f_nocase($file);
219 return "" unless $file;
220 return $file if $::opt_m;
221 return $file if containspod($file);
227 my($recurse,$s,@dirs) = @_;
229 $s = VMS::Filespec::unixify($s) if $Is_VMS;
230 return $s if -f $s && containspod($s);
231 printf STDERR "Looking for $s in @dirs\n" if $opt_v;
235 $global_target = (split('/', $s))[-1];
236 for ($i=0; $i<@dirs; $i++) {
238 ($dir = VMS::Filespec::unixpath($dir)) =~ s!/$!! if $Is_VMS;
239 if ( ( $ret = check_file "$dir/$s.pod")
240 or ( $ret = check_file "$dir/$s.pm")
241 or ( $ret = check_file "$dir/$s")
243 $ret = check_file "$dir/$s.com")
244 or ( $^O eq 'os2' and
245 $ret = check_file "$dir/$s.cmd")
246 or ( ($Is_MSWin32 or $Is_Dos or $^O eq 'os2') and
247 $ret = check_file "$dir/$s.bat")
248 or ( $ret = check_file "$dir/pod/$s.pod")
249 or ( $ret = check_file "$dir/pod/$s")
256 my @newdirs = map "$dir/$_", grep {
258 not /^auto$/ and # save time! don't search auto dirs
262 next unless @newdirs;
263 @newdirs = map((s/.dir$//,$_)[1],@newdirs) if $Is_VMS;
264 print STDERR "Also looking in @newdirs\n" if $opt_v;
265 push(@dirs,@newdirs);
273 if ($podidx && open(PODIDX, $podidx)) {
276 $searchfor =~ s,::,/,g;
277 print STDERR "Searching for '$searchfor' in $podidx\n" if $opt_v;
280 push(@found, $_) if m,/$searchfor(?:\.(?:pod|pm))?$,i;
285 print STDERR "Searching for $_\n" if $opt_v;
286 # We must look both in @INC for library modules and in PATH
287 # for executables, like h2xs or perldoc itself.
291 push @found, $_ if $opt_m or containspod($_);
297 for ($i = 0; $trn = $ENV{'DCL$PATH'.$i}; $i++) {
298 push(@searchdirs,$trn);
300 push(@dirs,'perl_root:[lib.pod]') # installed pods
302 push(@searchdirs, grep(-d, split($Config{path_sep},
305 @files= searchfor(0,$_,@searchdirs);
308 print STDERR "Found as @files\n" if $opt_v;
310 # no match, try recursive search
312 @searchdirs = grep(!/^\.$/,@INC);
314 @files= searchfor(1,$_,@searchdirs);
316 print STDERR "Loosely found as @files\n" if $opt_v;
318 print STDERR "No documentation found for \"$_\".\n";
320 print STDERR "However, try\n";
321 my $dir = $file = "";
322 for $dir (@global_found) {
323 opendir(DIR, $dir) or die "$!";
324 while ($file = readdir(DIR)) {
325 next if ($file =~ /^\./);
326 $file =~ s/\.(pm|pod)$//;
327 print STDERR "\tperldoc $_\::$file\n";
338 exit ($Is_VMS ? 98962 : 1);
342 print join("\n", @found), "\n";
346 if( ! -t STDOUT ) { $no_tty = 1 }
349 $tmp = "$ENV{TEMP}\\perldoc1.$$";
350 push @pagers, qw( more< less notepad );
351 unshift @pagers, $ENV{PAGER} if $ENV{PAGER};
353 $tmp = 'Sys$Scratch:perldoc.tmp1_'.$$;
354 push @pagers, qw( most more less type/page );
356 $tmp = "$ENV{TEMP}/perldoc1.$$";
358 push @pagers, qw( less.exe more.com< );
359 unshift @pagers, $ENV{PAGER} if $ENV{PAGER};
363 $tmp = POSIX::tmpnam();
365 $tmp = "/tmp/perldoc1.$$";
367 push @pagers, qw( more less pg view cat );
368 unshift @pagers, $ENV{PAGER} if $ENV{PAGER};
370 unshift @pagers, $ENV{PERLDOC_PAGER} if $ENV{PERLDOC_PAGER};
373 foreach $pager (@pagers) {
374 system("$pager @found") or exit;
376 if ($Is_VMS) { eval 'use vmsish qw(status exit); exit $?' }
381 my $perlfunc = shift @found;
382 open(PFUNC, $perlfunc) or die "Can't open $perlfunc: $!";
386 last if /^=head2 Alphabetical Listing of Perl Functions/;
389 # Look for our function
393 if (/^=item\s+\Q$opt_f\E\b/o) {
400 ++$found if /^\w/; # found descriptive text
403 my $lines = $ENV{LINES} || 24;
406 open(FORMATTER, "| pod2text") || die "Can't start filter";
407 print FORMATTER "=over 8\n\n";
408 print FORMATTER @pod;
409 print FORMATTER "=back\n";
411 } elsif (@pod < $lines-2) {
414 foreach $pager (@pagers) {
415 open (PAGER, "| $pager") or next;
417 close(PAGER) or next;
422 die "No documentation for perl function `$opt_f' found\n";
428 local @ARGV = @found; # I'm lazy, sue me.
434 if (/^=head2\s+.*$opt_q/oi) {
436 push @pod, "=head1 Found in $ARGV\n\n" unless $found_in{$ARGV}++;
437 } elsif (/^=head2/) {
446 open(FORMATTER, "| pod2text") || die "Can't start filter";
447 print FORMATTER "=over 8\n\n";
448 print FORMATTER @pod;
449 print FORMATTER "=back\n";
455 die "No documentation for perl function `$opt_f' found\n";
464 Pod::Text::pod2text($_,*TMP);
466 } elsif(not $opt_u) {
467 my $cmd = "pod2man --lax $_ | nroff -man";
468 $cmd .= " | col -x" if $^O =~ /hpux/;
470 unless(($err = $?)) {
477 if( $opt_u or $err or -z $tmp) {
482 $cut = $1 eq 'cut' if /^=(\w+)/;
496 foreach $pager (@pagers) {
497 system("$pager $tmp") or last;
501 1 while unlink($tmp); #Possibly pointless VMSism
509 perldoc - Look up Perl documentation in pod format.
513 B<perldoc> [B<-h>] [B<-v>] [B<-t>] [B<-u>] [B<-m>] [B<-l>] [B<-F>] [B<-X>] PageName|ModuleName|ProgramName
515 B<perldoc> B<-f> BuiltinFunction
519 I<perldoc> looks up a piece of documentation in .pod format that is embedded
520 in the perl installation tree or in a perl script, and displays it via
521 C<pod2man | nroff -man | $PAGER>. (In addition, if running under HP-UX,
522 C<col -x> will be used.) This is primarily used for the documentation for
523 the perl library modules.
525 Your system may also have man pages installed for those modules, in
526 which case you can probably just use the man(1) command.
534 Prints out a brief help message.
538 Describes search for the item in detail.
540 =item B<-t> text output
542 Display docs using plain text converter, instead of nroff. This may be faster,
543 but it won't look as nice.
545 =item B<-u> unformatted
547 Find docs only; skip reformatting by pod2*
551 Display the entire module: both code and unformatted pod documentation.
552 This may be useful if the docs don't explain a function in the detail
553 you need, and you'd like to inspect the code directly; perldoc will find
554 the file for you and simply hand it off for display.
556 =item B<-l> file name only
558 Display the file name of the module found.
560 =item B<-F> file names
562 Consider arguments as file names, no search in directories will be performed.
566 The B<-f> option followed by the name of a perl built in function will
567 extract the documentation of this function from L<perlfunc>.
569 =item B<-X> use an index if present
571 The B<-X> option looks for a entry whose basename matches the name given on the
572 command line in the file C<$Config{archlib}/pod.idx>. The pod.idx file should
573 contain fully qualified filenames, one per line.
575 =item B<PageName|ModuleName|ProgramName>
577 The item you want to look up. Nested modules (such as C<File::Basename>)
578 are specified either as C<File::Basename> or C<File/Basename>. You may also
579 give a descriptive name of a page, such as C<perlfunc>. You make also give a
580 partial or wrong-case name, such as "basename" for "File::Basename", but
581 this will be slower, if there is more then one page with the same partial
582 name, you will only get the first one.
588 Any switches in the C<PERLDOC> environment variable will be used before the
589 command line arguments. C<perldoc> also searches directories
590 specified by the C<PERL5LIB> (or C<PERLLIB> if C<PERL5LIB> is not
591 defined) and C<PATH> environment variables.
592 (The latter is so that embedded pods for executables, such as
593 C<perldoc> itself, are available.) C<perldoc> will use, in order of
594 preference, the pager defined in C<PERLDOC_PAGER>, C<MANPAGER>, or
595 C<PAGER> before trying to find a pager on its own. (C<MANPAGER> is not
596 used if C<perldoc> was told to display plain text or unformatted pod.)
600 Kenneth Albanowski <kjahds@kjahds.com>
602 Minor updates by Andy Dougherty <doughera@lafcol.lafayette.edu>
607 # Version 1.13: Fri Feb 27 16:20:50 EST 1997
608 # Gurusamy Sarathy <gsar@umich.edu>
609 # -doc tweaks for -F and -X options
610 # Version 1.12: Sat Apr 12 22:41:09 EST 1997
611 # Gurusamy Sarathy <gsar@umich.edu>
612 # -various fixes for win32
613 # Version 1.11: Tue Dec 26 09:54:33 EST 1995
614 # Kenneth Albanowski <kjahds@kjahds.com>
615 # -added Charles Bailey's further VMS patches, and -u switch
616 # -added -t switch, with pod2text support
618 # Version 1.10: Thu Nov 9 07:23:47 EST 1995
619 # Kenneth Albanowski <kjahds@kjahds.com>
621 # -added better error recognition (on no found pages, just exit. On
622 # missing nroff/pod2man, just display raw pod.)
623 # -added recursive/case-insensitive matching (thanks, Andreas). This
624 # slows things down a bit, unfortunately. Give a precise name, and
627 # Version 1.01: Tue May 30 14:47:34 EDT 1995
628 # Andy Dougherty <doughera@lafcol.lafayette.edu>
629 # -added pod documentation.
630 # -added PATH searching.
631 # -added searching pod/ subdirectory (mainly to pick up perlfunc.pod
637 # Cache directories read during sloppy match
640 close OUT or die "Can't close $file: $!";
641 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
642 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';