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

📄 version.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 3 页
字号:
when used as a class method..IP "\(bu" 4Comparison operators.SpBoth \f(CW\*(C`cmp\*(C'\fR and \f(CW\*(C`<=>\*(C'\fR operators perform the same comparison betweenterms (upgrading to a version object automatically).  Perl automaticallygenerates all of the other comparison operators based on those two.In addition to the obvious equalities listed below, appending a singletrailing 0 term does not change the value of a version for comparisonpurposes.  In other words \*(L"v1.2\*(R" and \*(L"1.2.0\*(R" will compare as identical..SpFor example, the following relations hold:.Sp.Vb 7\&  As Number        As String           Truth Value\&  \-\-\-\-\-\-\-\-\-\-\-\-\-    \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-    \-\-\-\-\-\-\-\-\-\-\-\&  $ver >  1.0      $ver gt "1.0"       true\&  $ver <  2.5      $ver lt             true\&  $ver != 1.3      $ver ne "1.3"       true\&  $ver == 1.2      $ver eq "1.2"       false\&  $ver == 1.2.3.4  $ver eq "1.2.3.4"   see discussion below.Ve.SpIt is probably best to chose either the numeric notation or the stringnotation and stick with it, to reduce confusion.  Perl6 version objects\&\fBmay\fR only support numeric comparisons.  See also Quoting..Sp\&\s-1WARNING:\s0 Comparing version with unequal numbers of decimal points (whetherexplicitly or implicitly initialized), may yield unexpected results atfirst glance.  For example, the following inequalities hold:.Sp.Vb 2\&  version\->new(0.96)     > version\->new(0.95); # 0.960.0 > 0.950.0\&  version\->new("0.96.1") < version\->new(0.95); # 0.096.1 < 0.950.0.Ve.SpFor this reason, it is best to use either exclusively \*(L"Numeric Versions\*(R" or\&\*(L"Extended Versions\*(R" with multiple decimal points..IP "\(bu" 4Logical Operators.SpIf you need to test whether a version objecthas been initialized, you can simply test it directly:.Sp.Vb 2\&  $vobj = version\->new($something);\&  if ( $vobj )   # true only if $something was non\-blank.Ve.SpYou can also test whether a version object is an \*(L"Alpha version\*(R", forexample to prevent the use of some feature not present in the mainrelease:.Sp.Vb 3\&  $vobj = version\->new("1.2_3"); # MUST QUOTE\&  ...later...\&  if ( $vobj\->is_alpha )       # True.Ve.Sh "Quoting".IX Subsection "Quoting"Because of the nature of the Perl parsing and tokenizing routines,certain initialization values \fBmust\fR be quoted in order to correctlyparse as the intended version, especially when using the \fIqv()\fR operator.In all cases, a floating point number passed to version\->\fInew()\fR will beidentically converted whether or not the value itself is quoted.  This isnot true for \fIqv()\fR, however, when trailing zeros would be stripped onan unquoted input, which would result in a very different version object..PPIn addition, in order to be compatible with earlier Perl version styles,any use of versions of the form 5.006001 will be translated as v5.6.1.  In other words, a version with a single decimal point will be parsed asimplicitly having three digits between subversions, but only for internalcomparison purposes..PPThe complicating factor is that in bare numbers (i.e. unquoted), theunderscore is a legal numeric character and is automatically strippedby the Perl tokenizer before the version code is called.  However, ifa number containing one or more decimals and an underscore is quoted, i.e.not bare, that is considered a \*(L"Alpha Version\*(R" and the underscore issignificant..PPIf you use a mathematic formula that resolves to a floating point number,you are dependent on Perl's conversion routines to yield the version youexpect.  You are pretty safe by dividing by a power of 10, for example,but other operations are not likely to be what you intend.  For example:.PP.Vb 4\&  $VERSION = version\->new((qw$Revision: 1.4)[1]/10);\&  print $VERSION;          # yields 0.14\&  $V2 = version\->new(100/9); # Integer overflow in decimal number\&  print $V2;               # yields something like 11.111.111.100.Ve.PPPerl 5.8.1 and beyond will be able to automatically quote v\-strings butthat is not possible in earlier versions of Perl.  In other words:.PP.Vb 2\&  $version = version\->new("v2.5.4");  # legal in all versions of Perl\&  $newvers = version\->new(v2.5.4);    # legal only in Perl >= 5.8.1.Ve.Sh "What about v\-strings?".IX Subsection "What about v-strings?"Beginning with Perl 5.6.0, an alternate method to code arbitrary stringsof bytes was introduced, called v\-strings.  They were intended to be aneasy way to enter, for example, Unicode strings (which contain two bytesper character).  Some programs have used them to encode printer controlcharacters (e.g. \s-1CRLF\s0).  They were also intended to be used for \f(CW$VERSION\fR,but their use as such has been problematic from the start..PPThere are two ways to enter v\-strings: a bare number with two or moredecimal points, or a bare number with one or more decimal points and a leading 'v' character (also bare).  For example:.PP.Vb 2\&  $vs1 = 1.2.3; # encoded as \e1\e2\e3\&  $vs2 = v1.2;  # encoded as \e1\e2.Ve.PPHowever, the use of bare v\-strings to initialize version objects is\&\fBstrongly\fR discouraged in all circumstances (especially the leading \&'v' style), since the meaning will change depending on which Perl you are running.  It is better to directly use \*(L"Extended Versions\*(R" to ensure the proper interpretation..PPIf you insist on using bare v\-strings with Perl > 5.6.0, be aware of the following limitations:.PP1) For Perl releases 5.6.0 through 5.8.0, the v\-string code merely guesses, based on some characteristics of v\-strings.  You \fBmust\fR use a three partversion, e.g. 1.2.3 or v1.2.3 in order for this heuristic to be successful..PP2) For Perl releases 5.8.1 and later, v\-strings have changed in the Perlcore to be magical, which means that the version.pm code can automaticallydetermine whether the v\-string encoding was used..PP3) In all cases, a version created using v\-strings will have a stringifiedform that has a leading 'v' character, for the simple reason that sometimesit is impossible to tell whether one was present initially..Sh "Types of Versions Objects".IX Subsection "Types of Versions Objects"There are two types of Version Objects:.IP "\(bu" 4Ordinary versions.SpThese are the versions that normal modules will use.  Can contain asmany subversions as required.  In particular, those using \s-1RCS/CVS\s0 canuse the following:.Sp.Vb 1\&  $VERSION = version\->new(qw$Revision: 2.7 $);.Ve.Spand the current \s-1RCS\s0 Revision for that file will be insertedautomatically.  If the file has been moved to a branch, the Revisionwill have three or more elements; otherwise, it will have only two.This allows you to automatically increment your module version byusing the Revision number from the primary file in a distribution, see\&\*(L"\s-1VERSION_FROM\s0\*(R" in ExtUtils::MakeMaker..IP "\(bu" 4Alpha Versions.SpFor module authors using \s-1CPAN\s0, the convention has been to noteunstable releases with an underscore in the version string, see\&\s-1CPAN\s0.  Alpha releases will test as being newer than the more recentstable release, and less than the next stable release.  For example:.Sp.Vb 1\&  $alphaver = version\->new("12.03_01"); # must be quoted.Ve.Spobeys the relationship.Sp.Vb 1\&  12.03 < $alphaver < 12.04.Ve.SpAlpha versions with a single decimal point will be treated exactly as ifthey were \*(L"Numeric Versions\*(R", for parsing and output purposes.  Theunderscore will be output when an alpha version is stringified, in the sameplace as it was when input..SpAlpha versions with more than a single decimal point will be treated exactly as if they were \*(L"Extended Versions\*(R", and will display without anytrailing (or leading) zeros, in the \*(L"Version Normal\*(R" form.  For example,.Sp.Vb 2\&  $newver = version\->new("12.3.1_1");\&  print $newver; # v12.3.1_1.Ve.Sh "Replacement \s-1UNIVERSAL::VERSION\s0".IX Subsection "Replacement UNIVERSAL::VERSION"In addition to the version objects, this modules also replaces the core\&\s-1UNIVERSAL::VERSION\s0 function with one that uses version objects for itscomparisons.  The return from this operator is always the stringified form,but the warning message generated includes either the stringified form orthe normal form, depending on how it was called..PPFor example:.PP.Vb 2\&  package Foo;\&  $VERSION = 1.2;\&\&  package Bar;\&  $VERSION = "1.3.5"; # works with all Perl\*(Aqs (since it is quoted)\&\&  package main;\&  use version;\&\&  print $Foo::VERSION; # prints 1.2\&\&  print $Bar::VERSION; # prints 1.003005\&\&  eval "use foo 10";\&  print $@; # prints "foo version 10 required..."\&  eval "use foo 1.3.5; # work in Perl 5.6.1 or better\&  print $@; # prints "foo version 1.3.5 required..."\&\&  eval "use bar 1.3.6";\&  print $@; # prints "bar version 1.3.6 required..."\&  eval "use bar 1.004"; # note numeric version\&  print $@; # prints "bar version 1.004 required...".Ve.PP\&\s-1IMPORTANT\s0 \s-1NOTE:\s0 This may mean that code which searches for a specificstring (to determine whether a given module is available) may need to bechanged.  It is always better to use the built-in comparison implicit in\&\f(CW\*(C`use\*(C'\fR or \f(CW\*(C`require\*(C'\fR, rather than manually poking at \f(CW\*(C`class\-\*(C'\fR\s-1VERSION\s0>and then doing a comparison yourself..PPThe replacement \s-1UNIVERSAL::VERSION\s0, when used as a function, like this:.PP.Vb 1\&  print $module\->VERSION;.Ve.PPwill also exclusively return the stringified form.  See Stringificationfor more details..SH "SUBCLASSING".IX Header "SUBCLASSING"This module is specifically designed and tested to be easily subclassed.In practice, you only need to override the methods you want to change, butyou have to take some care when overriding \fInew()\fR (since that is where allof the parsing takes place).  For example, this is a perfect acceptablederived class:.PP.Vb 10\&  package myversion;\&  use base version;\&  sub new { \&      my($self,$n)=@_;\&      my $obj;\&      # perform any special input handling here\&      $obj = $self\->SUPER::new($n);\&      # and/or add additional hash elements here\&      return $obj;\&  }.Ve.PPSee also version::AlphaBeta on \s-1CPAN\s0 for an alternate representation ofversion strings..PP\&\fB\s-1NOTE:\s0\fR Although the qv operator is not a true class method, but rather afunction exported into the caller's namespace, a subclass of version will inherit an \fIimport()\fR function which will perform the correct magic on behalfof the subclass..SH "EXPORT".IX Header "EXPORT"qv \- Extended Version initialization operator.SH "AUTHOR".IX Header "AUTHOR"John Peacock <jpeacock@cpan.org>.SH "SEE ALSO".IX Header "SEE ALSO"perl.

⌨️ 快捷键说明

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