⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usage.pm

📁 Astercon2 开源软交换 2.2.0
💻 PM
📖 第 1 页 / 共 2 页
字号:
############################################################################## Pod/Usage.pm -- print usage messages for the running script.## Copyright (C) 1996-2000 by Bradford Appleton. All rights reserved.# This file is part of "PodParser". PodParser is free software;# you can redistribute it and/or modify it under the same terms# as Perl itself.#############################################################################package Pod::Usage;use vars qw($VERSION);$VERSION = 1.33;  ## Current version of this packagerequire  5.005;    ## requires this Perl version or later=head1 NAMEPod::Usage, pod2usage() - print a usage message from embedded pod documentation=head1 SYNOPSIS  use Pod::Usage  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    = \*STDERR;   ## The filehandle to write to  pod2usage($message_text);  pod2usage($exit_status);  pod2usage( { -message => $message_text ,               -exitval => $exit_status  ,                 -verbose => $verbose_level,                 -output  => $filehandle } );  pod2usage(   -msg     => $message_text ,               -exitval => $exit_status  ,                 -verbose => $verbose_level,                 -output  => $filehandle   );  pod2usage(   -verbose => 2,               -noperldoc => 1  )=head1 ARGUMENTSB<pod2usage> should be given either a single argument, or a list ofarguments corresponding to an associative array (a "hash"). When a singleargument is given, it should correspond to exactly one of the following:=over 4=item *A string containing the text of a message to print I<before> printingthe usage message=item *A numeric value corresponding to the desired exit status=item *A reference to a hash=backIf more than one argument is given then the entire argument list isassumed to be a hash.  If a hash is supplied (either as a reference oras a list) it should contain one or more elements with the followingkeys:=over 4=item C<-message>=item C<-msg>The text of a message to print immediately prior to printing theprogram's usage message. =item C<-exitval>The desired exit status to pass to the B<exit()> function.This should be an integer, or else the string "NOEXIT" toindicate that control should simply be returned withoutterminating the invoking process.=item C<-verbose>The desired level of "verboseness" to use when printing the usagemessage. If the corresponding value is 0, then only the "SYNOPSIS"section of the pod documentation is printed. If the corresponding valueis 1, then the "SYNOPSIS" section, along with any section entitled"OPTIONS", "ARGUMENTS", or "OPTIONS AND ARGUMENTS" is printed.  If thecorresponding value is 2 or more then the entire manpage is printed.The special verbosity level 99 requires to also specify the -sectionparameter; then these sections are extracted (see L<Pod::Select>)and printed.=item C<-section>A string representing a selection list for sections to be printedwhen -verbose is set to 99, e.g. C<"NAME|SYNOPSIS|DESCRIPTION|VERSION">.=item C<-output>A reference to a filehandle, or the pathname of a file to which theusage message should be written. The default is C<\*STDERR> unless theexit value is less than 2 (in which case the default is C<\*STDOUT>).=item C<-input>A reference to a filehandle, or the pathname of a file from which theinvoking script's pod documentation should be read.  It defaults to thefile indicated by C<$0> (C<$PROGRAM_NAME> for users of F<English.pm>).=item C<-pathlist>A list of directory paths. If the input file does not exist, then itwill be searched for in the given directory list (in the order thedirectories appear in the list). It defaults to the list of directoriesimplied by C<$ENV{PATH}>. The list may be specified either by a referenceto an array, or by a string of directory paths which use the same pathseparator as C<$ENV{PATH}> on your system (e.g., C<:> for Unix, C<;> forMSWin32 and DOS).=item C<-noperldoc>By default, Pod::Usage will call L<perldoc> when -verbose >= 2 isspecified. This does not work well e.g. if the script was packedwith L<PAR>. The -noperldoc option suppresses the external call toL<perldoc> and uses the simple text formatter (L<Pod::Text>) to output the POD.=back=head1 DESCRIPTIONB<pod2usage> will print a usage message for the invoking script (usingits embedded pod documentation) and then exit the script with thedesired exit status. The usage message printed may have any one of threelevels of "verboseness": If the verbose level is 0, then only a synopsisis printed. If the verbose level is 1, then the synopsis is printedalong with a description (if present) of the command line options andarguments. If the verbose level is 2, then the entire manual page isprinted.Unless they are explicitly specified, the default values for the exitstatus, verbose level, and output stream to use are determined asfollows:=over 4=item *If 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.=item *If an exit status I<is> specified but the verbose level is I<not>, then theverbose level will default to 1 if the exit status is less than 2 andwill default to 0 otherwise.=item *If an exit status is I<not> specified but verbose level I<is> given, thenthe exit status will default to 2 if the verbose level is 0 and willdefault to 1 otherwise.=item *If the exit status used is less than 2, then output is printed onC<STDOUT>.  Otherwise output is printed on C<STDERR>.=backAlthough the above may seem a bit confusing at first, it generally does"the right thing" in most situations.  This determination of the defaultvalues to use is based upon the following typical Unix conventions:=over 4=item *An exit status of 0 implies "success". For example, B<diff(1)> exitswith a status of 0 if the two files have the same contents.=item *An exit status of 1 implies possibly abnormal, but non-defective, programtermination.  For example, B<grep(1)> exits with a status of 1 ifit did I<not> find a matching line for the given regular expression.=item *An exit status of 2 or more implies a fatal error. For example, B<ls(1)>exits with a status of 2 if you specify an illegal (unknown) option onthe command line.=item *Usage messages issued as a result of bad command-line syntax should goto C<STDERR>.  However, usage messages issued due to an explicit requestto print usage (like specifying B<-help> on the command line) should goto C<STDOUT>, just in case the user wants to pipe the output to a pager(such as B<more(1)>).=item *If program usage has been explicitly requested by the user, it is oftendesireable to exit with a status of 1 (as opposed to 0) after issuingthe user-requested usage message.  It is also desireable to give amore verbose description of program usage in this case.=backB<pod2usage> 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 B<pod2usage()> to accept a single number or a string makes itconvenient to use as an innocent looking error message handling function:    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.\n")  if (@ARGV > 1);Some user's however may feel that the above "economy of expression" isnot particularly readable nor consistent and may instead choose to dosomething more like the following:    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.\n")        if (@ARGV > 1);As with all things in Perl, I<there's more than one way to do it>, andB<pod2usage()> adheres to this philosophy.  If you are interested inseeing a number of different ways to invoke B<pod2usage> (although by nomeans exhaustive), please refer to L<"EXAMPLES">.=head1 EXAMPLESEach of the following invocations of C<pod2usage()> will print just the"SYNOPSIS" section to C<STDERR> and will exit with a status of 2:    pod2usage();    pod2usage(2);    pod2usage(-verbose => 0);    pod2usage(-exitval => 2);    pod2usage({-exitval => 2, -output => \*STDERR});    pod2usage({-verbose => 0, -output  => \*STDERR});    pod2usage(-exitval => 2, -verbose => 0);    pod2usage(-exitval => 2, -verbose => 0, -output => \*STDERR);Each of the following invocations of C<pod2usage()> will print a messageof "Syntax error." (followed by a newline) to C<STDERR>, immediatelyfollowed by just the "SYNOPSIS" section (also printed to C<STDERR>) andwill exit with a status of 2:    pod2usage("Syntax error.");    pod2usage(-message => "Syntax error.", -verbose => 0);    pod2usage(-msg  => "Syntax error.", -exitval => 2);    pod2usage({-msg => "Syntax error.", -exitval => 2, -output => \*STDERR});    pod2usage({-msg => "Syntax error.", -verbose => 0, -output => \*STDERR});    pod2usage(-msg  => "Syntax error.", -exitval => 2, -verbose => 0);    pod2usage(-message => "Syntax error.",              -exitval => 2,              -verbose => 0,              -output  => \*STDERR);Each of the following invocations of C<pod2usage()> will print the"SYNOPSIS" section and any "OPTIONS" and/or "ARGUMENTS" sections toC<STDOUT> and will exit with a status of 1:    pod2usage(1);    pod2usage(-verbose => 1);    pod2usage(-exitval => 1);    pod2usage({-exitval => 1, -output => \*STDOUT});    pod2usage({-verbose => 1, -output => \*STDOUT});    pod2usage(-exitval => 1, -verbose => 1);    pod2usage(-exitval => 1, -verbose => 1, -output => \*STDOUT});Each of the following invocations of C<pod2usage()> will print theentire manual page to C<STDOUT> and will exit with a status of 1:    pod2usage(-verbose  => 2);    pod2usage({-verbose => 2, -output => \*STDOUT});    pod2usage(-exitval  => 1, -verbose => 2);    pod2usage({-exitval => 1, -verbose => 2, -output => \*STDOUT});=head2 Recommended Use

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -