📄 pod::usage.3
字号:
arguments. If the verbose level is 2, then the entire manual page isprinted..PPUnless they are explicitly specified, the default values for the exitstatus, verbose level, and output stream to use are determined asfollows:.IP "\(bu" 4If neither the exit status nor the verbose level is specified, then thedefault is to use an exit status of 2 with a verbose level of 0..IP "\(bu" 4If an exit status \fIis\fR specified but the verbose level is \fInot\fR, then theverbose level will default to 1 if the exit status is less than 2 andwill default to 0 otherwise..IP "\(bu" 4If an exit status is \fInot\fR specified but verbose level \fIis\fR given, thenthe exit status will default to 2 if the verbose level is 0 and willdefault to 1 otherwise..IP "\(bu" 4If 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..PPAlthough the above may seem a bit confusing at first, it generally does\&\*(L"the right thing\*(R" in most situations. This determination of the defaultvalues to use is based upon the following typical Unix conventions:.IP "\(bu" 4An exit status of 0 implies \*(L"success\*(R". For example, \fB\f(BIdiff\fB\|(1)\fR exitswith a status of 0 if the two files have the same contents..IP "\(bu" 4An exit status of 1 implies possibly abnormal, but non-defective, programtermination. For example, \fB\f(BIgrep\fB\|(1)\fR exits with a status of 1 ifit did \fInot\fR find a matching line for the given regular expression..IP "\(bu" 4An exit status of 2 or more implies a fatal error. For example, \fB\f(BIls\fB\|(1)\fRexits with a status of 2 if you specify an illegal (unknown) option onthe command line..IP "\(bu" 4Usage messages issued as a result of bad command-line syntax should goto \f(CW\*(C`STDERR\*(C'\fR. However, usage messages issued due to an explicit requestto print usage (like specifying \fB\-help\fR on the command line) should goto \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" 4If program usage has been explicitly requested by the user, it is oftendesirable to exit with a status of 1 (as opposed to 0) after issuingthe user-requested usage message. It is also desirable to give amore verbose description of program usage in this case..PP\&\fBpod2usage\fR doesn't force the above conventions upon you, but it willuse them by default if you don't expressly tell it to do otherwise. Theability of \fB\f(BIpod2usage()\fB\fR to accept a single number or a string makes itconvenient to use as an innocent looking error message handling function:.PP.Vb 2\& use Pod::Usage;\& use Getopt::Long;\&\& ## Parse options\& GetOptions("help", "man", "flag1") || pod2usage(2);\& pod2usage(1) if ($opt_help);\& pod2usage(\-verbose => 2) if ($opt_man);\&\& ## Check for too many filenames\& pod2usage("$0: Too many files given.\en") if (@ARGV > 1);.Ve.PPSome user's however may feel that the above \*(L"economy of expression\*(R" isnot particularly readable nor consistent and may instead choose to dosomething more like the following:.PP.Vb 2\& use Pod::Usage;\& use Getopt::Long;\&\& ## Parse options\& GetOptions("help", "man", "flag1") || pod2usage(\-verbose => 0);\& pod2usage(\-verbose => 1) if ($opt_help);\& pod2usage(\-verbose => 2) if ($opt_man);\&\& ## Check for too many filenames\& pod2usage(\-verbose => 2, \-message => "$0: Too many files given.\en")\& if (@ARGV > 1);.Ve.PPAs 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 inseeing a number of different ways to invoke \fBpod2usage\fR (although by nomeans 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();\&\& pod2usage(2);\&\& pod2usage(\-verbose => 0);\&\& pod2usage(\-exitval => 2);\&\& pod2usage({\-exitval => 2, \-output => \e*STDERR});\&\& pod2usage({\-verbose => 0, \-output => \e*STDERR});\&\& pod2usage(\-exitval => 2, \-verbose => 0);\&\& pod2usage(\-exitval => 2, \-verbose => 0, \-output => \e*STDERR);.Ve.PPEach of the following invocations of \f(CW\*(C`pod2usage()\*(C'\fR will print a messageof \*(L"Syntax error.\*(R" (followed by a newline) to \f(CW\*(C`STDERR\*(C'\fR, immediatelyfollowed by just the \*(L"\s-1SYNOPSIS\s0\*(R" section (also printed to \f(CW\*(C`STDERR\*(C'\fR) andwill exit with a status of 2:.PP.Vb 1\& pod2usage("Syntax error.");\&\& pod2usage(\-message => "Syntax error.", \-verbose => 0);\&\& pod2usage(\-msg => "Syntax error.", \-exitval => 2);\&\& pod2usage({\-msg => "Syntax error.", \-exitval => 2, \-output => \e*STDERR});\&\& pod2usage({\-msg => "Syntax error.", \-verbose => 0, \-output => \e*STDERR});\&\& pod2usage(\-msg => "Syntax error.", \-exitval => 2, \-verbose => 0);\&\& pod2usage(\-message => "Syntax error.",\& \-exitval => 2,\& \-verbose => 0,\& \-output => \e*STDERR);.Ve.PPEach 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);\&\& pod2usage(\-verbose => 1);\&\& pod2usage(\-exitval => 1);\&\& pod2usage({\-exitval => 1, \-output => \e*STDOUT});\&\& pod2usage({\-verbose => 1, \-output => \e*STDOUT});\&\& pod2usage(\-exitval => 1, \-verbose => 1);\&\& pod2usage(\-exitval => 1, \-verbose => 1, \-output => \e*STDOUT});.Ve.PPEach of the following invocations of \f(CW\*(C`pod2usage()\*(C'\fR will print theentire manual page to \f(CW\*(C`STDOUT\*(C'\fR and will exit with a status of 1:.PP.Vb 1\& pod2usage(\-verbose => 2);\&\& pod2usage({\-verbose => 2, \-output => \e*STDOUT});\&\& pod2usage(\-exitval => 1, \-verbose => 2);\&\& 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 acommand line syntax error is detected. They should also provide anoption (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 toprovide 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 exampleuses \fBPod::Usage\fR in combination with \fBGetopt::Long\fR to do all of thesethings:.PP.Vb 2\& use Getopt::Long;\& use Pod::Usage;\&\& my $man = 0;\& my $help = 0;\& ## Parse options and print usage if there is a syntax error,\& ## or if usage was explicitly requested.\& GetOptions(\*(Aqhelp|?\*(Aq => \e$help, man => \e$man) or pod2usage(2);\& pod2usage(1) if $help;\& pod2usage(\-verbose => 2) if $man;\&\& ## If no arguments were given, then allow STDIN to be used only\& ## if it\*(Aqs not connected to a terminal (otherwise print usage)\& pod2usage("$0: No files given.") if ((@ARGV == 0) && (\-t STDIN));\& _\|_END_\|_\&\& =head1 NAME\&\& sample \- Using GetOpt::Long and Pod::Usage\&\& =head1 SYNOPSIS\&\& sample [options] [file ...]\&\& Options:\& \-help brief help message\& \-man full documentation\&\& =head1 OPTIONS\&\& =over 8\&\& =item B<\-help>\&\& Print a brief help message and exits.\&\& =item B<\-man>\&\& Prints the manual page and exits.\&\& =back\&\& =head1 DESCRIPTION\&\& B<This program> will read the given input file(s) and do something\& useful with the contents thereof.\&\& =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 inputfile. Unfortunately, not all systems on which Perl runs will set \f(CW$0\fRproperly (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 specifythe path to the pod docs for the invoking script using somethingsimilar to the following:.PP.Vb 1\& pod2usage(\-exitval => 2, \-input => "/path/to/your/pod/docs");.Ve.PPIn the pathological case that a script is called via a relative path\&\fIand\fR the script itself changes the current working directory(see \*(L"chdir\*(R" in perlfunc) \fIbefore\fR calling pod2usage, Pod::Usage willfail even on robust platforms. Don't do that..SH "AUTHOR".IX Header "AUTHOR"Please report bugs using <http://rt.cpan.org>..PPBrad Appleton <bradapp@enteract.com>.PPBased on code for \fB\f(BIPod::Text::pod2text()\fB\fR written byTom Christiansen <tchrist@mox.perl.com>.SH "ACKNOWLEDGMENTS".IX Header "ACKNOWLEDGMENTS"Steven McDougall <swmcd@world.std.com> for his help and patiencewith re-writing this manpage.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -