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

📄 long.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 5 页
字号:
	}	elsif ( $try eq 'bundling_override' ) {	    $bundling = $action ? 2 : 0;	}	elsif ( $try eq 'require_order' ) {	    $order = $action ? $REQUIRE_ORDER : $PERMUTE;	}	elsif ( $try eq 'permute' ) {	    $order = $action ? $PERMUTE : $REQUIRE_ORDER;	}	elsif ( $try eq 'pass_through' or $try eq 'passthrough' ) {	    $passthrough = $action;	}	elsif ( $try =~ /^prefix=(.+)$/ && $action ) {	    $genprefix = $1;	    # Turn into regexp. Needs to be parenthesized!	    $genprefix = "(" . quotemeta($genprefix) . ")";	    eval { '' =~ /$genprefix/; };	    die("Getopt::Long: invalid pattern \"$genprefix\"") if $@;	}	elsif ( $try =~ /^prefix_pattern=(.+)$/ && $action ) {	    $genprefix = $1;	    # Parenthesize if needed.	    $genprefix = "(" . $genprefix . ")"	      unless $genprefix =~ /^\(.*\)$/;	    eval { '' =~ m"$genprefix"; };	    die("Getopt::Long: invalid pattern \"$genprefix\"") if $@;	}	elsif ( $try =~ /^long_prefix_pattern=(.+)$/ && $action ) {	    $longprefix = $1;	    # Parenthesize if needed.	    $longprefix = "(" . $longprefix . ")"	      unless $longprefix =~ /^\(.*\)$/;	    eval { '' =~ m"$longprefix"; };	    die("Getopt::Long: invalid long prefix pattern \"$longprefix\"") if $@;	}	elsif ( $try eq 'debug' ) {	    $debug = $action;	}	else {	    die("Getopt::Long: unknown config parameter \"$opt\"")	}    }    $prevconfig;}# Deprecated name.sub config (@) {    Configure (@_);}# Issue a standard message for --version.## The arguments are mostly the same as for Pod::Usage::pod2usage:##  - a number (exit value)#  - a string (lead in message)#  - a hash with options. See Pod::Usage for details.#sub VersionMessage(@) {    # Massage args.    my $pa = setup_pa_args("version", @_);    my $v = $main::VERSION;    my $fh = $pa->{-output} ||      ($pa->{-exitval} eq "NOEXIT" || $pa->{-exitval} < 2) ? \*STDOUT : \*STDERR;    print $fh (defined($pa->{-message}) ? $pa->{-message} : (),	       $0, defined $v ? " version $v" : (),	       "\n",	       "(", __PACKAGE__, "::", "GetOptions",	       " version ",	       defined($Getopt::Long::VERSION_STRING)	         ? $Getopt::Long::VERSION_STRING : $VERSION, ";",	       " Perl version ",	       $] >= 5.006 ? sprintf("%vd", $^V) : $],	       ")\n");    exit($pa->{-exitval}) unless $pa->{-exitval} eq "NOEXIT";}# Issue a standard message for --help.## The arguments are the same as for Pod::Usage::pod2usage:##  - a number (exit value)#  - a string (lead in message)#  - a hash with options. See Pod::Usage for details.#sub HelpMessage(@) {    eval {	require Pod::Usage;	import Pod::Usage;	1;    } || die("Cannot provide help: cannot load Pod::Usage\n");    # Note that pod2usage will issue a warning if -exitval => NOEXIT.    pod2usage(setup_pa_args("help", @_));}# Helper routine to set up a normalized hash ref to be used as# argument to pod2usage.sub setup_pa_args($@) {    my $tag = shift;		# who's calling    # If called by direct binding to an option, it will get the option    # name and value as arguments. Remove these, if so.    @_ = () if @_ == 2 && $_[0] eq $tag;    my $pa;    if ( @_ > 1 ) {	$pa = { @_ };    }    else {	$pa = shift || {};    }    # At this point, $pa can be a number (exit value), string    # (message) or hash with options.    if ( UNIVERSAL::isa($pa, 'HASH') ) {	# Get rid of -msg vs. -message ambiguity.	$pa->{-message} = $pa->{-msg};	delete($pa->{-msg});    }    elsif ( $pa =~ /^-?\d+$/ ) {	$pa = { -exitval => $pa };    }    else {	$pa = { -message => $pa };    }    # These are _our_ defaults.    $pa->{-verbose} = 0 unless exists($pa->{-verbose});    $pa->{-exitval} = 0 unless exists($pa->{-exitval});    $pa;}# Sneak way to know what version the user requested.sub VERSION {    $requested_version = $_[1];    shift->SUPER::VERSION(@_);}package Getopt::Long::CallBack;sub new {    my ($pkg, %atts) = @_;    bless { %atts }, $pkg;}sub name {    my $self = shift;    ''.$self->{name};}use overload  # Treat this object as an oridinary string for legacy API.  '""'	   => \&name,  '0+'	   => sub { 0 },  fallback => 1;1;################ Documentation ################=head1 NAMEGetopt::Long - Extended processing of command line options=head1 SYNOPSIS  use Getopt::Long;  my $data   = "file.dat";  my $length = 24;  my $verbose;  $result = GetOptions ("length=i" => \$length,    # numeric                        "file=s"   => \$data,      # string			"verbose"  => \$verbose);  # flag=head1 DESCRIPTIONThe Getopt::Long module implements an extended getopt function calledGetOptions(). This function adheres to the POSIX syntax for commandline options, with GNU extensions. In general, this means that optionshave long names instead of single letters, and are introduced with adouble dash "--". Support for bundling of command line options, as wasthe case with the more traditional single-letter approach, is providedbut not enabled by default.=head1 Command Line Options, an IntroductionCommand line operated programs traditionally take their arguments fromthe command line, for example filenames or other information that theprogram needs to know. Besides arguments, these programs often takecommand line I<options> as well. Options are not necessary for theprogram to work, hence the name 'option', but are used to modify itsdefault behaviour. For example, a program could do its job quietly,but with a suitable option it could provide verbose information aboutwhat it did.Command line options come in several flavours. Historically, they arepreceded by a single dash C<->, and consist of a single letter.    -l -a -cUsually, these single-character options can be bundled:    -lacOptions can have values, the value is placed after the optioncharacter. Sometimes with whitespace in between, sometimes not:    -s 24 -s24Due to the very cryptic nature of these options, another style wasdeveloped that used long names. So instead of a cryptic C<-l> onecould use the more descriptive C<--long>. To distinguish between abundle of single-character options and a long one, two dashes are usedto precede the option name. Early implementations of long options useda plus C<+> instead. Also, option values could be specified eitherlike    --size=24or    --size 24The C<+> form is now obsolete and strongly deprecated.=head1 Getting Started with Getopt::LongGetopt::Long is the Perl5 successor of C<newgetopt.pl>. This was thefirst Perl module that provided support for handling the new style ofcommand line options, hence the name Getopt::Long. This module alsosupports single-character options and bundling. Single characteroptions may be any alphabetic character, a question mark, and a dash.Long options may consist of a series of letters, digits, and dashes.Although this is currently not enforced by Getopt::Long, multipleconsecutive dashes are not allowed, and the option name must not endwith a dash.To use Getopt::Long from a Perl program, you must include thefollowing line in your Perl program:    use Getopt::Long;This will load the core of the Getopt::Long module and prepare yourprogram for using it. Most of the actual Getopt::Long code is notloaded until you really call one of its functions.In the default configuration, options names may be abbreviated touniqueness, case does not matter, and a single dash is sufficient,even for long option names. Also, options may be placed betweennon-option arguments. See L<Configuring Getopt::Long> for moredetails on how to configure Getopt::Long.=head2 Simple optionsThe most simple options are the ones that take no values. Their merepresence on the command line enables the option. Popular examples are:    --all --verbose --quiet --debugHandling simple options is straightforward:    my $verbose = '';	# option variable with default value (false)    my $all = '';	# option variable with default value (false)    GetOptions ('verbose' => \$verbose, 'all' => \$all);The call to GetOptions() parses the command line arguments that arepresent in C<@ARGV> and sets the option variable to the value C<1> ifthe option did occur on the command line. Otherwise, the optionvariable is not touched. Setting the option value to true is oftencalled I<enabling> the option.The option name as specified to the GetOptions() function is calledthe option I<specification>. Later we'll see that this specificationcan contain more than just the option name. The reference to thevariable is called the option I<destination>.GetOptions() will return a true value if the command line could beprocessed successfully. Otherwise, it will write error messages toSTDERR, and return a false result.=head2 A little bit less simple optionsGetopt::Long supports two useful variants of simple options:I<negatable> options and I<incremental> options.A negatable option is specified with an exclamation mark C<!> after theoption name:    my $verbose = '';	# option variable with default value (false)    GetOptions ('verbose!' => \$verbose);Now, using C<--verbose> on the command line will enable C<$verbose>,as expected. But it is also allowed to use C<--noverbose>, which willdisable C<$verbose> by setting its value to C<0>. Using a suitabledefault value, the program can find out whether C<$verbose> is falseby default, or disabled by using C<--noverbose>.An incremental option is specified with a plus C<+> after theoption name:    my $verbose = '';	# option variable with default value (false)    GetOptions ('verbose+' => \$verbose);Using C<--verbose> on the command line will increment the value ofC<$verbose>. This way the program can keep track of how many times theoption occurred on the command line. For example, each occurrence ofC<--verbose> could increase the verbosity level of the program.=head2 Mixing command line option with other argumentsUsually programs take command line options as well as other arguments,for example, file names. It is good practice to always specify theoptions first, and the other arguments last. Getopt::Long will,however, allow the options and arguments to be mixed and 'filter out'all the options before passing the rest of the arguments to theprogram. To stop Getopt::Long from processing further arguments,insert a double dash C<--> on the command line:    --size 24 -- --allIn this example, C<--all> will I<not> be treated as an option, butpassed to the program unharmed, in C<@ARGV>.=head2 Options with valuesFor options that take values it must be specified whether the optionvalue is required or not, and what kind of value the option expects.Three kinds of values are supported: integer numbers, floating pointnumbers, and strings.If the option value is required, Getopt::Long will take thecommand line argument that follows the option and assign this to theoption variable. If, however, the option value is specified asoptional, this will only be done if that value does not look like avalid command line option itself.    my $tag = '';	# option variable with default value    GetOptions ('tag=s' => \$tag);In the option specification, the option name is followed by an equalssign C<=> and the letter C<s>. The equals sign indicates that thisoption requires a value. The letter C<s> indicates that this value isan arbitrary string. Other possible value types are C<i> for integervalues, and C<f> for floating point values. Using a colon C<:> insteadof the equals sign indicates that the option value is optional. Inthis case, if no suitable value is supplied, string valued options getan empty string C<''> assigned, while numeric options are set to C<0>.=head2 Options with multiple valuesOptions sometimes take several values. For example, a program coulduse multiple directories to search for library files:    --library lib/stdlib --library lib/extlibTo accomplish this behaviour, simply specify an array reference as thedestination for the option:    GetOptions ("library=s" => \@libfiles);Alternatively, you can specify that the option can have multiplevalues by adding a "@", and pass a scalar reference as thedestination:    GetOptions ("library=s@" => \$libfiles);Used with the example above, C<@libfiles> (or C<@$libfiles>) wouldcontain two strings upon completion: C<"lib/srdlib"> andC<"lib/extlib">, in that order. It is also possible to specify thatonly integer or floating point numbers are acceptable values.Often it is useful to allow comma-separated lists of values as well asmultiple occurrences of the options. This is easy using Perl's split()and join() operators:    GetOptions ("library=s" => \@libfiles);    @libfiles = split(/,/,join(',',@libfiles));Of course, it is important to choose the right separator string foreach purpose.Warning: What follows is an experimental feature.Options can take multiple values at once, for example    --coordinates 52.2 16.4 --rgbcolor 255 255 149This can be accomplished by adding a repeat specifier to the optionspecification. Repeat specifiers are very similar to the C<{...}>repeat specifiers that can be used with regular expression patterns.For example, the above command line would be handled as follows:    GetOptions('coordinates=f{2}' => \@coor, 'rgbcolor=i{3}' => \@color);The destination for the option must be an array or array reference.It is also possible to specify the minimal and maximal number ofarguments an option takes. C<foo=s{2,4}> indicates an option thattakes at least two and at most 4 arguments. C<foo=s{,}> indicates oneor more values; C<foo:s{,}> indicates zero or more option values.=head2 Options with hash valuesIf the option destination is a reference to a hash, the option willtake, as value, strings of the form I<key>C<=>I<value>. The value willbe stored with the specified key in the hash.    GetOptions ("define=s" => \%defines);Alternatively you can use:    GetOptions ("define=s%" => \$defines);When used with command line options:    --define os=linux --define vendor=redhatthe hash C<%defines> (or C<%$defines>) will contain two keys, C<"os">with value C<"linux> and C<"vendor"> with value C<"redhat">. It isalso possible to specify that only integer or floating point numbersare acceptable values. The keys are always taken to be strings.=head2 User-defined subroutines to handle optionsUltimate control over what should be done when (actually: each time)an option is encountered on the command line can be achieved bydesignating a reference to a subroutine (or an anonymous subroutine)as the option destination. When GetOptions() encounters the option, itwill call the subroutine with two or three arguments. The firstargument is the name of the option. For a scalar or array destination,the second argument is the value to be stored. For a hash destination,the second arguments is the key to the hash, and the third argumentthe value to be stored. It is up to the subroutine to store the value,or do whatever it thinks is appropriate.

⌨️ 快捷键说明

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