Plan 9 from Bell Labs’s /usr/web/sources/contrib/gabidiaz/root/sys/man/2perl/Pod::Usage

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  | will give a
.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
.\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
.    de IX
.    tm Index:\\$1\t\\n%\t"\\$2"
..
.    nr % 0
.    rr F
.\}
.\"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Pod::Usage 3"
.TH Pod::Usage 3 "2002-11-24" "perl v5.8.0" "Perl Programmers Reference Guide"
.SH "NAME"
Pod::Usage, pod2usage() \- print a usage message from embedded pod documentation
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\&  use Pod::Usage
.Ve
.PP
.Vb 4
\&  my $message_text  = "This text precedes the usage message.";
\&  my $exit_status   = 2;          ## The exit status to use
\&  my $verbose_level = 0;          ## The verbose level to use
\&  my $filehandle    = \e*STDERR;   ## The filehandle to write to
.Ve
.PP
.Vb 1
\&  pod2usage($message_text);
.Ve
.PP
.Vb 1
\&  pod2usage($exit_status);
.Ve
.PP
.Vb 4
\&  pod2usage( { -message => $message_text ,
\&               -exitval => $exit_status  ,  
\&               -verbose => $verbose_level,  
\&               -output  => $filehandle } );
.Ve
.PP
.Vb 4
\&  pod2usage(   -msg     => $message_text ,
\&               -exitval => $exit_status  ,  
\&               -verbose => $verbose_level,  
\&               -output  => $filehandle   );
.Ve
.SH "ARGUMENTS"
.IX Header "ARGUMENTS"
\&\fBpod2usage\fR should be given either a single argument, or a list of
arguments corresponding to an associative array (a \*(L"hash\*(R"). When a single
argument is given, it should correspond to exactly one of the following:
.IP "\(bu" 4
A string containing the text of a message to print \fIbefore\fR printing
the usage message
.IP "\(bu" 4
A numeric value corresponding to the desired exit status
.IP "\(bu" 4
A reference to a hash
.PP
If more than one argument is given then the entire argument list is
assumed to be a hash.  If a hash is supplied (either as a reference or
as a list) it should contain one or more elements with the following
keys:
.ie n .IP """\-message""" 4
.el .IP "\f(CW\-message\fR" 4
.IX Item "-message"
.PD 0
.ie n .IP """\-msg""" 4
.el .IP "\f(CW\-msg\fR" 4
.IX Item "-msg"
.PD
The text of a message to print immediately prior to printing the
program's usage message. 
.ie n .IP """\-exitval""" 4
.el .IP "\f(CW\-exitval\fR" 4
.IX Item "-exitval"
The desired exit status to pass to the \fB\f(BIexit()\fB\fR function.
This should be an integer, or else the string \*(L"\s-1NOEXIT\s0\*(R" to
indicate that control should simply be returned without
terminating the invoking process.
.ie n .IP """\-verbose""" 4
.el .IP "\f(CW\-verbose\fR" 4
.IX Item "-verbose"
The desired level of \*(L"verboseness\*(R" to use when printing the usage
message. If the corresponding value is 0, then only the \*(L"\s-1SYNOPSIS\s0\*(R"
section of the pod documentation is printed. If the corresponding value
is 1, then the \*(L"\s-1SYNOPSIS\s0\*(R" section, along with any section entitled
\&\*(L"\s-1OPTIONS\s0\*(R", \*(L"\s-1ARGUMENTS\s0\*(R", or \*(L"\s-1OPTIONS\s0 \s-1AND\s0 \s-1ARGUMENTS\s0\*(R" is printed.  If the
corresponding value is 2 or more then the entire manpage is printed.
.ie n .IP """\-output""" 4
.el .IP "\f(CW\-output\fR" 4
.IX Item "-output"
A reference to a filehandle, or the pathname of a file to which the
usage message should be written. The default is \f(CW\*(C`\e*STDERR\*(C'\fR unless the
exit value is less than 2 (in which case the default is \f(CW\*(C`\e*STDOUT\*(C'\fR).
.ie n .IP """\-input""" 4
.el .IP "\f(CW\-input\fR" 4
.IX Item "-input"
A reference to a filehandle, or the pathname of a file from which the
invoking script's pod documentation should be read.  It defaults to the
file indicated by \f(CW$0\fR (\f(CW$PROGRAM_NAME\fR for users of \fIEnglish.pm\fR).
.ie n .IP """\-pathlist""" 4
.el .IP "\f(CW\-pathlist\fR" 4
.IX Item "-pathlist"
A list of directory paths. If the input file does not exist, then it
will be searched for in the given directory list (in the order the
directories appear in the list). It defaults to the list of directories
implied by \f(CW$ENV{PATH}\fR. The list may be specified either by a reference
to an array, or by a string of directory paths which use the same path
separator as \f(CW$ENV{PATH}\fR on your system (e.g., \f(CW\*(C`:\*(C'\fR for Unix, \f(CW\*(C`;\*(C'\fR for
MSWin32 and \s-1DOS\s0).
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
\&\fBpod2usage\fR will print a usage message for the invoking script (using
its embedded pod documentation) and then exit the script with the
desired exit status. The usage message printed may have any one of three
levels of \*(L"verboseness\*(R": If the verbose level is 0, then only a synopsis
is printed. If the verbose level is 1, then the synopsis is printed
along with a description (if present) of the command line options and
arguments. If the verbose level is 2, then the entire manual page is
printed.
.PP
Unless they are explicitly specified, the default values for the exit
status, verbose level, and output stream to use are determined as
follows:
.IP "\(bu" 4
If neither the exit status nor the verbose level is specified, then the
default is to use an exit status of 2 with a verbose level of 0.
.IP "\(bu" 4
If an exit status \fIis\fR specified but the verbose level is \fInot\fR, then the
verbose level will default to 1 if the exit status is less than 2 and
will default to 0 otherwise.
.IP "\(bu" 4
If an exit status is \fInot\fR specified but verbose level \fIis\fR given, then
the exit status will default to 2 if the verbose level is 0 and will
default to 1 otherwise.
.IP "\(bu" 4
If the exit status used is less than 2, then output is printed on
\&\f(CW\*(C`STDOUT\*(C'\fR.  Otherwise output is printed on \f(CW\*(C`STDERR\*(C'\fR.
.PP
Although the above may seem a bit confusing at first, it generally does
\&\*(L"the right thing\*(R" in most situations.  This determination of the default
values to use is based upon the following typical Unix conventions:
.IP "\(bu" 4
An exit status of 0 implies \*(L"success\*(R". For example, \fB\f(BIdiff\fB\|(1)\fR exits
with a status of 0 if the two files have the same contents.
.IP "\(bu" 4
An exit status of 1 implies possibly abnormal, but non\-defective, program
termination.  For example, \fB\f(BIgrep\fB\|(1)\fR exits with a status of 1 if
it did \fInot\fR find a matching line for the given regular expression.
.IP "\(bu" 4
An exit status of 2 or more implies a fatal error. For example, \fB\f(BIls\fB\|(1)\fR
exits with a status of 2 if you specify an illegal (unknown) option on
the command line.
.IP "\(bu" 4
Usage messages issued as a result of bad command-line syntax should go
to \f(CW\*(C`STDERR\*(C'\fR.  However, usage messages issued due to an explicit request
to print usage (like specifying \fB\-help\fR on the command line) should go
to \f(CW\*(C`STDOUT\*(C'\fR, just in case the user wants to pipe the output to a pager
(such as \fB\f(BImore\fB\|(1)\fR).
.IP "\(bu" 4
If program usage has been explicitly requested by the user, it is often
desireable to exit with a status of 1 (as opposed to 0) after issuing
the user-requested usage message.  It is also desireable to give a
more verbose description of program usage in this case.
.PP
\&\fBpod2usage\fR doesn't force the above conventions upon you, but it will
use them by default if you don't expressly tell it to do otherwise.  The
ability of \fB\f(BIpod2usage()\fB\fR to accept a single number or a string makes it
convenient to use as an innocent looking error message handling function:
.PP
.Vb 2
\&    use Pod::Usage;
\&    use Getopt::Long;
.Ve
.PP
.Vb 4
\&    ## Parse options
\&    GetOptions("help", "man", "flag1")  ||  pod2usage(2);
\&    pod2usage(1)  if ($opt_help);
\&    pod2usage(-verbose => 2)  if ($opt_man);
.Ve
.PP
.Vb 2
\&    ## Check for too many filenames
\&    pod2usage("$0: Too many files given.\en")  if (@ARGV > 1);
.Ve
.PP
Some user's however may feel that the above \*(L"economy of expression\*(R" is
not particularly readable nor consistent and may instead choose to do
something more like the following:
.PP
.Vb 2
\&    use Pod::Usage;
\&    use Getopt::Long;
.Ve
.PP
.Vb 4
\&    ## Parse options
\&    GetOptions("help", "man", "flag1")  ||  pod2usage(-verbose => 0);
\&    pod2usage(-verbose => 1)  if ($opt_help);
\&    pod2usage(-verbose => 2)  if ($opt_man);
.Ve
.PP
.Vb 3
\&    ## Check for too many filenames
\&    pod2usage(-verbose => 2, -message => "$0: Too many files given.\en")
\&        if (@ARGV > 1);
.Ve
.PP
As with all things in Perl, \fIthere's more than one way to do it\fR, and
\&\fB\f(BIpod2usage()\fB\fR adheres to this philosophy.  If you are interested in
seeing a number of different ways to invoke \fBpod2usage\fR (although by no
means exhaustive), please refer to \*(L"\s-1EXAMPLES\s0\*(R".
.SH "EXAMPLES"
.IX Header "EXAMPLES"
Each of the following invocations of \f(CW\*(C`pod2usage()\*(C'\fR will print just the
\&\*(L"\s-1SYNOPSIS\s0\*(R" section to \f(CW\*(C`STDERR\*(C'\fR and will exit with a status of 2:
.PP
.Vb 1
\&    pod2usage();
.Ve
.PP
.Vb 1
\&    pod2usage(2);
.Ve
.PP
.Vb 1
\&    pod2usage(-verbose => 0);
.Ve
.PP
.Vb 1
\&    pod2usage(-exitval => 2);
.Ve
.PP
.Vb 1
\&    pod2usage({-exitval => 2, -output => \e*STDERR});
.Ve
.PP
.Vb 1
\&    pod2usage({-verbose => 0, -output  => \e*STDERR});
.Ve
.PP
.Vb 1
\&    pod2usage(-exitval => 2, -verbose => 0);
.Ve
.PP
.Vb 1
\&    pod2usage(-exitval => 2, -verbose => 0, -output => \e*STDERR);
.Ve
.PP
Each of the following invocations of \f(CW\*(C`pod2usage()\*(C'\fR will print a message
of \*(L"Syntax error.\*(R" (followed by a newline) to \f(CW\*(C`STDERR\*(C'\fR, immediately
followed by just the \*(L"\s-1SYNOPSIS\s0\*(R" section (also printed to \f(CW\*(C`STDERR\*(C'\fR) and
will exit with a status of 2:
.PP
.Vb 1
\&    pod2usage("Syntax error.");
.Ve
.PP
.Vb 1
\&    pod2usage(-message => "Syntax error.", -verbose => 0);
.Ve
.PP
.Vb 1
\&    pod2usage(-msg  => "Syntax error.", -exitval => 2);
.Ve
.PP
.Vb 1
\&    pod2usage({-msg => "Syntax error.", -exitval => 2, -output => \e*STDERR});
.Ve
.PP
.Vb 1
\&    pod2usage({-msg => "Syntax error.", -verbose => 0, -output => \e*STDERR});
.Ve
.PP
.Vb 1
\&    pod2usage(-msg  => "Syntax error.", -exitval => 2, -verbose => 0);
.Ve
.PP
.Vb 4
\&    pod2usage(-message => "Syntax error.",
\&              -exitval => 2,
\&              -verbose => 0,
\&              -output  => \e*STDERR);
.Ve
.PP
Each of the following invocations of \f(CW\*(C`pod2usage()\*(C'\fR will print the
\&\*(L"\s-1SYNOPSIS\s0\*(R" section and any \*(L"\s-1OPTIONS\s0\*(R" and/or \*(L"\s-1ARGUMENTS\s0\*(R" sections to
\&\f(CW\*(C`STDOUT\*(C'\fR and will exit with a status of 1:
.PP
.Vb 1
\&    pod2usage(1);
.Ve
.PP
.Vb 1
\&    pod2usage(-verbose => 1);
.Ve
.PP
.Vb 1
\&    pod2usage(-exitval => 1);
.Ve
.PP
.Vb 1
\&    pod2usage({-exitval => 1, -output => \e*STDOUT});
.Ve
.PP
.Vb 1
\&    pod2usage({-verbose => 1, -output => \e*STDOUT});
.Ve
.PP
.Vb 1
\&    pod2usage(-exitval => 1, -verbose => 1);
.Ve
.PP
.Vb 1
\&    pod2usage(-exitval => 1, -verbose => 1, -output => \e*STDOUT});
.Ve
.PP
Each of the following invocations of \f(CW\*(C`pod2usage()\*(C'\fR will print the
entire manual page to \f(CW\*(C`STDOUT\*(C'\fR and will exit with a status of 1:
.PP
.Vb 1
\&    pod2usage(-verbose  => 2);
.Ve
.PP
.Vb 1
\&    pod2usage({-verbose => 2, -output => \e*STDOUT});
.Ve
.PP
.Vb 1
\&    pod2usage(-exitval  => 1, -verbose => 2);
.Ve
.PP
.Vb 1
\&    pod2usage({-exitval => 1, -verbose => 2, -output => \e*STDOUT});
.Ve
.Sh "Recommended Use"
.IX Subsection "Recommended Use"
Most scripts should print some type of usage message to \f(CW\*(C`STDERR\*(C'\fR when a
command line syntax error is detected. They should also provide an
option (usually \f(CW\*(C`\-H\*(C'\fR or \f(CW\*(C`\-help\*(C'\fR) to print a (possibly more verbose)
usage message to \f(CW\*(C`STDOUT\*(C'\fR. Some scripts may even wish to go so far as to
provide a means of printing their complete documentation to \f(CW\*(C`STDOUT\*(C'\fR
(perhaps by allowing a \f(CW\*(C`\-man\*(C'\fR option). The following complete example
uses \fBPod::Usage\fR in combination with \fBGetopt::Long\fR to do all of these
things:
.PP
.Vb 2
\&    use Getopt::Long;
\&    use Pod::Usage;
.Ve
.PP
.Vb 7
\&    my $man = 0;
\&    my $help = 0;
\&    ## Parse options and print usage if there is a syntax error,
\&    ## or if usage was explicitly requested.
\&    GetOptions('help|?' => \e$help, man => \e$man) or pod2usage(2);
\&    pod2usage(1) if $help;
\&    pod2usage(-verbose => 2) if $man;
.Ve
.PP
.Vb 4
\&    ## If no arguments were given, then allow STDIN to be used only
\&    ## if it's not connected to a terminal (otherwise print usage)
\&    pod2usage("$0: No files given.")  if ((@ARGV == 0) && (-t STDIN));
\&    __END__
.Ve
.PP
.Vb 1
\&    =head1 NAME
.Ve
.PP
.Vb 1
\&    sample - Using GetOpt::Long and Pod::Usage
.Ve
.PP
.Vb 1
\&    =head1 SYNOPSIS
.Ve
.PP
.Vb 1
\&    sample [options] [file ...]
.Ve
.PP
.Vb 3
\&     Options:
\&       -help            brief help message
\&       -man             full documentation
.Ve
.PP
.Vb 1
\&    =head1 OPTIONS
.Ve
.PP
.Vb 1
\&    =over 8
.Ve
.PP
.Vb 1
\&    =item B<-help>
.Ve
.PP
.Vb 1
\&    Print a brief help message and exits.
.Ve
.PP
.Vb 1
\&    =item B<-man>
.Ve
.PP
.Vb 1
\&    Prints the manual page and exits.
.Ve
.PP
.Vb 1
\&    =back
.Ve
.PP
.Vb 1
\&    =head1 DESCRIPTION
.Ve
.PP
.Vb 2
\&    B<This program> will read the given input file(s) and do something
\&    useful with the contents thereof.
.Ve
.PP
.Vb 1
\&    =cut
.Ve
.SH "CAVEATS"
.IX Header "CAVEATS"
By default, \fB\f(BIpod2usage()\fB\fR will use \f(CW$0\fR as the path to the pod input
file.  Unfortunately, not all systems on which Perl runs will set \f(CW$0\fR
properly (although if \f(CW$0\fR isn't found, \fB\f(BIpod2usage()\fB\fR will search
\&\f(CW$ENV{PATH}\fR or else the list specified by the \f(CW\*(C`\-pathlist\*(C'\fR option).
If this is the case for your system, you may need to explicitly specify
the path to the pod docs for the invoking script using something
similar to the following:
.PP
.Vb 1
\&    pod2usage(-exitval => 2, -input => "/path/to/your/pod/docs");
.Ve
.SH "AUTHOR"
.IX Header "AUTHOR"
Brad Appleton <bradapp@enteract.com>
.PP
Based on code for \fB\f(BIPod::Text::pod2text()\fB\fR written by
Tom Christiansen <tchrist@mox.perl.com>
.SH "ACKNOWLEDGEMENTS"
.IX Header "ACKNOWLEDGEMENTS"
Steven McDougall <swmcd@world.std.com> for his help and patience
with re-writing this manpage.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.