📄 version.3
字号:
these must be quoted to preserve the underscore formatting..IP "\(bu" 4Extended Versions.SpAny initial parameter which contains more than one decimal pointand an optional embedded underscore, see \*(L"Extended Versions\*(R". This is what is commonly used in most open source software as the \*(L"external\*(R"version (the one used as part of the tag or tarfile name). The useof the exported \fIqv()\fR function also produces this kind of versionobject..PPBoth of these methods will produce similar version objects, in thatthe default stringification will yield the version \*(L"Normal Form\*(R" only if required:.PP.Vb 3\& $v = version\->new(1.002); # 1.002, but compares like 1.2.0\& $v = version\->new(1.002003); # 1.002003\& $v2 = version\->new("1.2.3"); # v1.2.3.Ve.PPIn specific, version numbers initialized as \*(L"Numeric Versions\*(R" willstringify as they were originally created (i.e. the same string that waspassed to \f(CW\*(C`new()\*(C'\fR. Version numbers initialized as \*(L"Extended Versions\*(R"will be stringified as \*(L"Normal Form\*(R"..Sh "Numeric Versions".IX Subsection "Numeric Versions"These correspond to historical versions of Perl itself prior to 5.6.0,as well as all other modules which follow the Camel rules for the\&\f(CW$VERSION\fR scalar. A numeric version is initialized with what looks likea floating point number. Leading zeros \fBare\fR significant and trailingzeros are implied so that a minimum of three places is maintainedbetween subversions. What this means is that any subversion (digitsto the right of the decimal place) that contains less than three digitswill have trailing zeros added to make up the difference, but only forpurposes of comparison with other version objects. For example:.PP.Vb 7\& # Prints Equivalent to \& $v = version\->new( 1.2); # 1.2 v1.200.0\& $v = version\->new( 1.02); # 1.02 v1.20.0\& $v = version\->new( 1.002); # 1.002 v1.2.0\& $v = version\->new( 1.0023); # 1.0023 v1.2.300\& $v = version\->new( 1.00203); # 1.00203 v1.2.30\& $v = version\->new( 1.002003); # 1.002003 v1.2.3.Ve.PPAll of the preceding examples are true whether or not the input value is quoted. The important feature is that the input value contains only a single decimal. See also \*(L"Alpha Versions\*(R" for how to handle.PP\&\s-1IMPORTANT\s0 \s-1NOTE:\s0 As shown above, if your numeric version contains more than 3 significant digits after the decimal place, it will be split on each multiple of 3, so 1.0003 is equivalent to v1.0.300, due to the need to remain compatible with Perl's own 5.005_03 == 5.5.30 interpretation. Any trailing zeros are ignored for mathematical comparison purposes..Sh "Extended Versions".IX Subsection "Extended Versions"These are the newest form of versions, and correspond to Perl's ownversion style beginning with 5.6.0. Starting with Perl 5.10.0,and most likely Perl 6, this is likely to be the preferred form. Thismethod normally requires that the input parameter be quoted, although Perl's after 5.8.1 can use v\-strings as a special form of quoting, butthis is highly discouraged..PPUnlike \*(L"Numeric Versions\*(R", Extended Versions have more thana single decimal point, e.g.:.PP.Vb 6\& # Prints\& $v = version\->new( "v1.200"); # v1.200.0\& $v = version\->new("v1.20.0"); # v1.20.0\& $v = qv("v1.2.3"); # v1.2.3\& $v = qv("1.2.3"); # v1.2.3\& $v = qv("1.20"); # v1.20.0.Ve.PPIn general, Extended Versions permit the greatest amount of freedomto specify a version, whereas Numeric Versions enforce a certainuniformity. See also \*(L"New Operator\*(R" for an additional method ofinitializing version objects..PPJust like \*(L"Numeric Versions\*(R", Extended Versions can be used as \&\*(L"Alpha Versions\*(R"..Sh "Numeric Alpha Versions".IX Subsection "Numeric Alpha Versions"The one time that a numeric version must be quoted is when a alpha form isused with an otherwise numeric version (i.e. a single decimal point). Thisis commonly used for \s-1CPAN\s0 releases, where \s-1CPAN\s0 or \s-1CPANPLUS\s0 will ignore alphaversions for automatic updating purposes. Since some developers have usedonly two significant decimal places for their non-alpha releases, theversion object will automatically take that into account if the initializeris quoted. For example Module::Example was released to \s-1CPAN\s0 with thefollowing sequence of \f(CW$VERSION\fR's:.PP.Vb 7\& # $VERSION Stringified\& 0.01 0.01\& 0.02 0.02\& 0.02_01 0.02_01\& 0.02_02 0.02_02\& 0.03 0.03\& etc..Ve.PPThe stringified form of numeric versions will always be the same stringthat was used to initialize the version object..Sh "Object Methods".IX Subsection "Object Methods"Overloading has been used with version objects to provide a naturalinterface for their use. All mathematical operations are forbidden,since they don't make any sense for base version objects. Consequently,there is no overloaded numification available. If you want to use aversion object in a numeric context for some reason, see the numifyobject method..IP "\(bu" 4New Operator.SpLike all \s-1OO\s0 interfaces, the \fInew()\fR operator is used to initializeversion objects. One way to increment versions when programming is touse the \s-1CVS\s0 variable \f(CW$Revision\fR, which is automatically incremented by\&\s-1CVS\s0 every time the file is committed to the repository..SpIn order to facilitate this feature, the followingcode can be employed:.Sp.Vb 1\& $VERSION = version\->new(qw$Revision: 2.7 $);.Ve.Spand the version object will be created as if the following codewere used:.Sp.Vb 1\& $VERSION = version\->new("v2.7");.Ve.SpIn other words, the version will be automatically parsed out of thestring, and it will be quoted to preserve the meaning \s-1CVS\s0 normallycarries for versions. The \s-1CVS\s0 \f(CW$Revision\fR$ increments differently fromnumeric versions (i.e. 1.10 follows 1.9), so it must be handled as ifit were a \*(L"Extended Version\*(R"..SpA new version object can be created as a copy of an existing versionobject, either as a class method:.Sp.Vb 2\& $v1 = version\->new(12.3);\& $v2 = version\->new($v1);.Ve.Spor as an object method:.Sp.Vb 2\& $v1 = version\->new(12.3);\& $v2 = $v1\->new(12.3);.Ve.Spand in each case, \f(CW$v1\fR and \f(CW$v2\fR will be identical. \s-1NOTE:\s0 if you createa new object using an existing object like this:.Sp.Vb 1\& $v2 = $v1\->new();.Ve.Spthe new object \fBwill not\fR be a clone of the existing object. In theexample case, \f(CW$v2\fR will be an empty object of the same type as \f(CW$v1\fR..IP "\(bu" 4\&\fIqv()\fR.SpAn alternate way to create a new version object is through the exported\&\fIqv()\fR sub. This is not strictly like other q? operators (like qq, qw),in that the only delimiters supported are parentheses (or spaces). It isthe best way to initialize a short version without triggering the floatingpoint interpretation. For example:.Sp.Vb 2\& $v1 = qv(1.2); # 1.2.0\& $v2 = qv("1.2"); # also 1.2.0.Ve.SpAs you can see, either a bare number or a quoted string can usually be used interchangably, except in the case of a trailing zero, whichmust be quoted to be converted properly. For this reason, it is stronglyrecommended that all initializers to \fIqv()\fR be quoted strings instead ofbare numbers..SpTo prevent the \f(CW\*(C`qv()\*(C'\fR function from being exported to the caller's namespace,either use version with a null parameter:.Sp.Vb 1\& use version ();.Ve.Spor just require version, like this:.Sp.Vb 1\& require version;.Ve.SpBoth methods will prevent the \fIimport()\fR method from firing and exporting the\&\f(CW\*(C`qv()\*(C'\fR sub. This is true of subclasses of version as well, see\&\s-1SUBCLASSING\s0 for details..PPFor the subsequent examples, the following three objects will be used:.PP.Vb 3\& $ver = version\->new("1.2.3.4"); # see "Quoting" below\& $alpha = version\->new("1.2.3_4"); # see "Alpha versions" below\& $nver = version\->new(1.002); # see "Numeric Versions" above.Ve.IP "\(bu" 4Normal Form.SpFor any version object which is initialized with multiple decimalplaces (either quoted or if possible v\-string), or initialized usingthe \fIqv()\fR operator, the stringified representation is returned ina normalized or reduced form (no extraneous zeros), and with a leading 'v':.Sp.Vb 5\& print $ver\->normal; # prints as v1.2.3.4\& print $ver\->stringify; # ditto\& print $ver; # ditto\& print $nver\->normal; # prints as v1.2.0\& print $nver\->stringify; # prints as 1.002, see "Stringification".Ve.SpIn order to preserve the meaning of the processed version, the normalized representation will always contain at least three sub terms.In other words, the following is guaranteed to always be true:.Sp.Vb 3\& my $newver = version\->new($ver\->stringify);\& if ($newver eq $ver ) # always true\& {...}.Ve.IP "\(bu" 4Numification.SpAlthough all mathematical operations on version objects are forbiddenby default, it is possible to retrieve a number which corresponds to the version object through the use of the \f(CW$obj\fR\->numifymethod. For formatting purposes, when displaying a number whichcorresponds a version object, all sub versions are assumed to havethree decimal places. So for example:.Sp.Vb 2\& print $ver\->numify; # prints 1.002003004\& print $nver\->numify; # prints 1.002.Ve.SpUnlike the stringification operator, there is never any need to appendtrailing zeros to preserve the correct version value..IP "\(bu" 4Stringification.SpThe default stringification for version objects returns exactly the samestring as was used to create it, whether you used \f(CW\*(C`new()\*(C'\fR or \f(CW\*(C`qv()\*(C'\fR,with one exception. The sole exception is if the object was created using\&\f(CW\*(C`qv()\*(C'\fR and the initializer did not have two decimal places or a leading\&'v' (both optional), then the stringified form will have a leading 'v'prepended, in order to support round-trip processing..SpFor example:.Sp.Vb 7\& Initialized as Stringifies to\& ============== ==============\& version\->new("1.2") 1.2\& version\->new("v1.2") v1.2\& qv("1.2.3") 1.2.3\& qv("v1.3.5") v1.3.5\& qv("1.2") v1.2 ### exceptional case.Ve.SpSee also \s-1UNIVERSAL::VERSION\s0, as this also returns the stringified form
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -