version::Internal - �����若�吾�с�潟�ŝ����吾�с�壔����勉�������� Perl �����壔�鴻����潟�激�с�
���菴���勐����⓾�勉����若�吾�с�潟�� Perl �����勉�ŝ�若����若�㏍�若����������� �����若�吾�с�潟�ŝ����吾�с�壔����� ��������� version.pm ��勐����������若�粋;�憗����������������潟�若����˨�ゃ����〠����後�������⓾����障����� ��勖侊��勌戎�����˨�ゃ����⓾�� version.pod ��������с����⓾�������������� �����勖����吾�� version.pm ��勉�泣����壔�í�鴻����吾����������������勤¼膣違�̹�√����勉�����篋冴�˨�勉� ��������с�����
(�����若�吾�с�潟�c�☖��?)
�����勉�≪�吾�ャ�若�˨�勛�◒����勉�������������若�吾�с�潟����ɱ垩����壔��1��や札筝���勐����亥�鴻� �����ュ櫝�純� 筝���ゃ�勉�≪�潟����若�鴻�潟�≪�˨����c�☗�阪�����������罩c�勖�贋�医�ゃ�������障����� ��������� Perl ��ʃ昆��������若�吾�с�潟��茵������勉�˩戎��������������勉��絲上����������障�� ��í�壔����㋘�勐�������ц�������������������医����������⓾�勉����若�吾�с�潟�������≦宍�����障�����
絎������˨�壔����若�吾�с�潟�ŝ����吾�с�壔����˨�� 2 腮勰����������障�����
Decimal Versions
(10 ��我�違����若�吾�с��)
�����医����勉�������̬�����������篁紙����勉����若�吾�с�潟�˨�ゃ����⓾�壔��"Decimal Versions" ��� �����с����⓾�������������� ��������壠����亥�剛����ゃ�����筝㏍�˨�≪�潟����若�鴻�潟�≫����ゃ�������ゃ����若�吾�с�潟����˨�帥�障�� ("Decimal Alpha Versions" ���������) ��������≪�潟����若�鴻�潟�≪�勖�後����� 篆������������˨�壔�壔�í�若����������ŝ�������違�ŝ����障��������
Dotted-Decimal Versions
(���������篁���� 10 ��我�違����若�吾�с��)
��障��������������篁������贋�違����������若�違����������勉�с��2 ��や札筝���勐����亥�鴻��篁紙����勰��筝㏍� ��≪�潟����若�鴻�潟�≫����ゃ�������ゃ����勉�с��; "Dotted-Decimal Versions" ��������с�� ��������壔�祉�������í�勉�ŝ�若����潟�純�若�鴻�純�������⓾�с�≪�с��紊���◐����������若�吾�с� (��帥�違�� tar �����<�ゃ�������勌����������������☖戎���������������) ��������☖����㋜���� 篏帥�������⓾����������勉�с����� �����壔�鴻����若����������� qv() ��∽�違��篏睡�������������������勛┏��勉����若�吾�с� ��ŝ����吾�с�壔�������������������障����� �����㏍�� 'v' ���絖���壚����с�壠�������с����������ŝ�������域⑥�����������障�����
�����������勉�<�純�����筝≧�鴻�����罕���勉����若�吾�с�潟�ŝ����吾�с�壔����������������障��; ��ŝ����ŝ�����綽�荀���ŝ�������˨�勉�帥�������í�˨����勖��絖���������壔����若�吾�с�潟� "Normal Form" ��������水�冴����������с��:
$v = version->new(1.002); # 1.002, but compares like 1.2.0
$v = version->new(1.002003); # 1.002003
$v2 = version->new("v1.2.3"); # v1.2.3
��鴻�˨��"Decimal Versions" ��������☗����������������������若�吾�с�括�ɱ垩� ��������˩����������������勉����� (��ゃ�障�����new()
���羝<����������勉�����������絖����) �� ���絖������������障����� "Dotted-Decimal Versions" ��������☗����������������������若�吾�с�括�ɱ垩� "Normal Form" ��������〠��絖���������������障�����
(10 ��我�違����若�吾�с��)
������������ 5.6.0 ������������ Perl ��ʃ昆��勖⑳�儹����勉����若�吾�с�潟�����$VERSION ��鴻�˨�ñ���� ��í�壔����˨�若�˨��荼頲蚊�����篁���勉�≪�吾�ャ�若�������⓾��絲上�������障����� 10 ��我�違����若�吾�с�潟�壩貴���絨���亥�鴻�勉�������̬�������������勉�у����������������障����� �����㏍�� 0 ��� �����鴻�� ���絨障�� 0 ��壩��藥���˩皿絎������������勉�с��3 ��鴻� ���絨���ゃ�壚��篏������若�吾�с�渇����т�������������障����� ��������������潟�������勉�壔��3 罅�������絨���ŝ��罅���違�勌��篏������若�吾�с�� (絨���亥�鴻����� �劻�勖�医��) ��壠����〠��絨障�吾��0��勤申�����˨����c�☀����������障�������������������������壚���� �����若�吾�с�潟�ŝ����吾�с�壔�������勖��莠���勉�������������с����� 箴�������:
# 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
��ュ����ゃ����壔�í�若����������⓾����������̹�≪��������������茵�箴���壠����☎�������ŝ����障����� ���荀���ɾ�劫彰��������⓾����ュ����ゃ��筝���ゃ�勐����亥�鴻�������ゃ����������������障����� ��宴����号����� "Alpha Versions" ��������с����⓾��������������
���荀���ʋ絵���: 筝�菴違�������������˨��10 ��我�違����若�吾�с�潟�у����亥�鴻�勐����� 3 罅����莇������� �����号�医�������������翫�����3 罅�罸���������蚊����������勉�с��1.0003 ��� v1.0.300 ��◐��箴<�с��; Perl ��ʃ昆��� 5.005_03 == 5.5.30 ��勤В������篋������с��膓㊥����������������с����� ��医�ゆ��莠���勉�����������絨障�� 0 ��夌�∴����������障�����
(���������篁���� 10 ��我�違����若�吾�с��)
�����������壩�������違�����綵√����勉����若�吾�с�潟�с��5.6.0 ������紮���障�� Perl ��ʃ昆�� �����若�吾�с�喝就綣����絲上�������障����� Perl 5.10.0 ��������壔����障����祉�主∈絎���� Perl 6 ��с�������������� 絅純�障�����綵√����˨�ŝ����������с����� �����勉�<�純�������奝��絽後�ュ��綣���違����壔�í�若����������⓾�����綽�荀������������� ��障�� 5.8.1 篁ラ����� Perl ��с�� v-���絖���� �����壔�í�若����勛�劫�ュ就綣��������� 篏睡�������������������с����障����������������壠七�������ィ絅���с�����
"Decimal Versions" ��◒����c�⓾�����������篁���� 10 ��我�違����若�吾�с�潟�� 2 ��や札筝��� 絨���亥�鴻�������<�障����� 箴�������:
# 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
筝���㋜����˨�����������篁���� 10 ��我�違����若�吾�с�潟�壩�����蕭������ɾ�怨墾��с����若�吾�с�潟�� ���絎���с����������勌����鴻�� 10 ��我�違����若�吾�с�潟�壚��絎���勛輝筝���с��綣桁�吟����障����� �����若�吾�с�潟�ŝ����吾�с�壔����勉�����筝���ゃ�勤����ñ����ɱ����������<�純�������˨�ゃ����⓾� "New Operator" ��������с����⓾��������������
"Decimal Versions" ������������罕���˨�����������篁���� 10 ��我�違����若�吾�с�潟� "Alpha Versions" ��������☖戎��������������������с����障�����
(10 ��我�� 留�����若�吾�с��)
�����ゃ�� 10 ��我�違����若�吾�с�潟��綽������壔�í�若����������⓾����ŝ�������違�ŝ����ŝ����c����勉�壔�� ��≪�˨����≦就綣����篁���� 10 ��我�違����若�吾�с�� (�����ŝ����≦����亥�鴻��筝����) ���筝�膩��� 篏帥�������⓾�������������с����� ��������壔����� CPAN ��ŝ�ŝ�若�鴻�˩戎��������⓾����������������� CPAN ��� CPANPLUS ��虁�ɱ����≪����������若����勉�������˨�≪�˨����<����若�吾�с�潟����∴�������障����� �����≪�˨����<�ŝ�ŝ�若�鴻��絨���違�勖����号����違��2��������⓾����������肴�������������������� �����若�吾�с�潟�ŝ����吾�с�壔����壠��������絖������壔�í�若����������⓾�������域�ɱ������� ��������������勉����障����� 箴������違��Module::Example ���篁ヤ����� $VERSION 膤糸����� CPAN �� ��ŝ�ŝ�若�鴻����������������障��:
# $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.
10 ��我�違����若�吾�с�潟�勖��絖�������綵√����壔��絽吾�˨����若�吾�с�潟�ŝ����吾�с�壔����勐���������� 篏帥����������勉�����������絖������с�����
(蕭���㋘����˨����吟�ゃ��)
(�����若�吾�с�潟�ŝ����吾�с�壔��)
version.pm provides an overloaded version object that is designed to both encapsulate the author's intended $VERSION assignment as well as make it completely natural to use those objects as if they were numbers (e.g. for comparisons). To do this, a version object contains both the original representation as typed by the author, as well as a parsed representation to ease comparisons. Version objects employ overload methods to simplify code that needs to compare, print, etc the objects.
The internal structure of version objects is a blessed hash with several components:
bless( {
'original' => 'v1.2.3_4',
'alpha' => 1,
'qv' => 1,
'version' => [
1,
2,
3,
4
]
}, 'version' );
- original
-
A faithful representation of the value used to initialize this version object. The only time this will not be precisely the same characters that exist in the source file is if a short dotted-decimal version like v1.2 was used (in which case it will contain 'v1.2'). This form is STRONGLY discouraged, in that it will confuse you and your users.
- qv
-
A boolean that denotes whether this is a decimal or dotted-decimal version. See is_qv.
- alpha
-
A boolean that denotes whether this is an alpha version. NOTE: that the underscore can can only appear in the last position. See is_alpha.
- version
-
An array of non-negative integers that is used for comparison purposes with other version objects.
(篁f�� UNIVERSAL::VERSION)
�����若�吾�с�潟�ŝ����吾�с�壔�������������⓾�������勉�≪�吾�ャ�若�˨�壩��莠���勉�������˨�潟�≪� UNIVERSAL::VERSION ��∽�違�������若�吾�с�潟�ŝ����吾�с�壔�����篏帥�������勉� 臀勉��������������������茵������障����� �����勖��膊�絖�������菴���������������勉�壠幻������膣���ŝ�鴻�˨�í�������〠��絖����������������綵√����с�������� ���������������茘☗����<����祉�若�吾�壔����í�勉����������若�喝�冴�������������˩��絖������⓾�� ���絖�������綵√����� Normal Form ��勉�í�<�������˨�ŝ����障�����
箴�������:
package Foo;
$VERSION = 1.2;
package Bar;
$VERSION = "v1.3.5"; # works with all Perl's (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 Decimal version
print $@; # prints "bar version 1.004 required..."
���荀���ʋ絵���: (筝���������������≪�吾�ャ�若�˨����ñ���櫝�純����í��������羆阪�����������������) ��劫����勖��絖�������罎�膣≪�������������勉�潟�若����壠����眼��綽�荀���������������ŝ����������� �����潟����障����� ��������� class-
VERSION> ���篏帥�c�⓾�������ɱ����ф��莠����茵������������� use
��� require
��ф��藥���˩戎���������腟���粋昭��帥�勖��莠����篏帥����鴻�� 絽吾����ŝ����⓾����障�����
UNIVERSAL::VERSION ��勌撮��睡�í�壔��篁ヤ����勉�������̹�∽�違�������☖戎������������:
print $module->VERSION;
������������絖�������綵√����勉�帥��菴������障����� ��眼�ŝ��荅括完��˨�ゃ����⓾�� Stringification ��������с����⓾��������������
(篏帥����鴻�勤蟹��
(version.pm ���篏帥����≪�吾�ャ�若�˨�勌戎������)
�櫝�純�ʒ��������version.pm ��≪�吾�ャ�若�˨�壩�√����勐����⓾�勉�潟�若�������勌�������с��篆���<�障����� �����������������������ŝ����勉�≪�吾�ャ�若�˨�������若�吾�с�潟�壔�í�鴻����������� $VERSION
��� 絎�臂í�������≪�吾�ャ�若�˨��篏睡�������⓾�������翫�������ャ�c�⓾�������鴻�������������������ゃ�� ��������障����� 茘域����勉��������篁ヤ����勉�≪�吾�ャ�若�˨����ゃ�潟�鴻����若�˨�������⓾��������������篁勐�������障��:
package Example;
use version; $VERSION = qv('1.2.2');
...module code here...
1;
- Decimal versions always work
-
(10 ��我�違����若�吾�с�潟�壠幻������篏�������)
篁ヤ����勐就綣���勉�潟�若��:
use Example 1.002003;
��壠幻���罩c��������篏������障�����
use
��壔�≪�吾�ャ�若�������勖❶��勰����������☖�������������� 羌勐��絨���亥�� (箴�:筝�菴違�� 1.002.003) ���篏帥�c�☀�ɱ��������$VERSION
��勖��莠���� 茵������障����� �����勌����с�壔����ゃ�潟�鴻����若�˨�������⓾�������≪�吾�ャ�若�˨�虁��羆������������潟�若���� 絲障����☗𡉴����������勉�с��罨<�勉�������ŝ����í�若��茵◐ず�����������с��������:Example version 1.002003 (v1.2.3) required--this is only version 1.002002 (v1.2.2)...
- Dotted-Decimal version work sometimes
-
(���������篁���� 10 ��我�違����若�吾�с�潟�壩��������篏�������)
Perl >= 5.6.2 ��с�壔��罨<�勉�������ŝ�潟�若�����篏帥�������������с����障��:
use Example 1.2.3;
��������⓾�����������������������絽吾�� v-���絖���� (筝�荐���� "What about v-strings" ���������) ��� ��泣����若�������⓾����ŝ�������若�吾�с�潟�� Perl ��с����c�⓾�����罩e幻������篏���������с�������� (�����ŝ����<��筝�菴違�勉����í�若�<����祉�若�吾��茵◐ず��������障��)��� �����勐�翫�����
use
��� 2 ��ɾ�勉�勰����� ��医����勉�������̬�������� �����í�������������с����壔����� ��������� Replacement UNIVERSAL::VERSION���羝<��������������������篋�絎���� ��≪����c�⓾����障����� �����������������勉�������� Perl 5.005_04 ��с�壩③��������ŝ����������勉������� ���������篁���� 10 ��我�違����若�吾�с�潟����泣����若�������� Perl ��勉����若�吾�с�潟�˨�������⓾����������� ��潟�若��筝㏍�с�壠幻��� 10 ��我�違����若�吾�с�潟��篏帥����������� 綣激���ィ絅� ��������障�����
(��ŝ����吾�с�壔����<�純�����)
�����若�吾�с�潟�ŝ����吾�с�壔����勐�ñ����˨����c�☀�ɾ�吟�ŝ�ゃ�潟�帥����с�若�鴻�����箴���������������˨�� ��ŝ�若����若�㏍�若�����篏帥�������⓾����障�������� ��医⑥�����ʋ��膊���壠����⓾�������若�鴻�勉����若�吾�с�潟�ŝ����吾�с�壔�����絲障����〠����潟�� ��������ŝ����勉�с��胼�罩≪�������⓾����障����� �����勛����������ŝ�若����若�㏍�若�������������医�ゅ����壠�������������ñ����с����障�������� ������篏���������勛����宴�с����若�吾�с�潟�ŝ����吾�с�壔����� 10 ��我�違�潟�潟����㏍�鴻����т戎������������ ��翫����壔����ŝ����吾�с�壔����<�純�������� numify ��������с����⓾��������������
-
New Operator
(new 羲�膊�絖�)
�����⓾�� OO ��ゃ�潟�帥����с�若�鴻�����罕���˨��new() 羲�膊�絖���壔����若�吾�с�潟�ŝ����吾�с�壔����� �����������������������˩戎��������障����� �����㏍�違�í����潟�井����˨����若�吾�с�潟����ゃ�潟�壔�ŝ�<�潟����������������勖�号����勌����ゃ� CVS 紊���違�� $Revision ���篏帥����������с����� $Revision ��壔����<�ゃ�˨����ŝ����吾����ŝ�˨�潟�����������������������罸���� CVS ��˨����c� ��ɱ�������˨�ゃ�潟�壔�ŝ�<�潟����������障�����
�����勖����純��絎号����̬�������������˨��篁ヤ����勉�潟�若�������ñ����с����障��:
$VERSION = version->new(qw$Revision$);
��������˨��������篁ヤ����勉�潟�若�����篏帥�������������勉�������˨����若�吾�с�潟�ŝ����吾�с�壔����� 篏������������障��:
$VERSION = version->new("v2.7");
荐�������������������罕����茹f����˨��������絖���������������若�吾�с�潟����ɱ����������������冴�������� CVS ������絽吾����若�吾�с�潟�т�������������潟��篆���ゃ�������˨����������壔�í�若����������障����� CVS ���
$Revision$ ��� 10 ��我�違����若�吾�с�潟����夌�違�ŝ�c����号����с�ゃ�潟�壔�ŝ�<�潟����������� (�����ŝ����� 1.9 ��勐����� 1.10 ���膓����) ��勉�с����������� "Dotted-Decimal Versions" �� �����������勉����������宴����ŝ�������違�ŝ����障����������違����������若�吾�с�潟�ŝ����吾�с�壔����壩�√����勉����若�吾�с�潟�ŝ����吾�с�壔����勉�潟����若������� 篏�����櫝�純�с����壔�í�鴻�<�純�������������☖�����������:
$v1 = version->new(12.3); $v2 = version->new($v1);
�����������������������壔�ŝ����吾�с�壔����<�純�������������☖�����������:
$v1 = version->new(12.3); $v2 = $v1->new(12.3);
�����������с�������������������勌����˨�������⓾��$v1 ��� $v2 ��壠��筝���с����� 羈����: ��������違�������ŝ����吾�с�壔�����罨<�勉����������√����勉�ŝ����吾�с�壔�����篏帥�c� 篏������������翫��:
$v2 = $v1->new();
��違�������ŝ����吾�с�壔����壩�√����勉�ŝ����吾�с�壔����勉�壔�㏍�若�潟�˨�� ��ŝ����障�������� �����勌����с�壔��$v2 ��� $v1 ���������腮勰����勛Ã��勉�ŝ����吾�с�壔����˨�ŝ����障�����
-
qv()
��違����������若�吾�с�潟�ŝ����吾�с�壔�����篏������������ャ�勖�号����˨�������壔�鴻����若����������� qv() ��∽�違��篏帥����号�������������障����� ��������壔����ñ���櫝�純�ŝ����ŝ����帥��筝吾�˨����� (��障����壔�鴻����若��) ��勉�帥�с����������������鴻�с�� �ウ絲���˨�壚����� q? 羲�膊�絖� (qq, qw ��ŝ��) �����壚室��⓾����障�������� ��������壔��絨���亥�壕В������綣����莎激�������������ŝ����̥�㏍�������若�吾�с�潟������������������������� �����壔�勖�号����с����� 箴�������:
$v1 = qv(1.2); # v1.2.0 $v2 = qv("1.2"); # also v1.2.0
���荀с�勰��������茖吾�勖�医�ゃ�障����壔�壔�í�若��������������絖������奝��絽娯困�������� 篏睡����с����障����� ���������������絨障�� 0 �����������宴�若�鴻�壔��罩c����鎀������������������˨�壔�í�若�����������綽�荀���� ��������勉�т��紊���с����� �����勛����宴�勉��������qv() ��吾�勐����⓾�勐��������絖���虁8��勖�医�ゃ�勉���������� ��壔�í�若��������������絖����������������������綣激���ィ絅���������障�����
qv()
��∽�違����若�喝�冴����眼�勐�����腥咲����˨����壔�鴻����若�������������勉����蚊����������˨��腥冴� 綣���違�� use version �����若�喝�冴�����:use version ();
�����������壠����� require version ���茵�������:
require version;
��勉��������������茵���c�⓾�������������� 筝≧�鴻�勉�<�純����������� import() ��<�純��������莎桁��������
qv()
��泣����˨�若����潟�� �����壔�鴻����若����������勉����蚊����障����� �����勉�������� version ��勉�泣����壔�í�鴻�с�����������������������腴���<�障����� 荅潟�������� SUBCLASSING ��������с����⓾��������������
篁ラ����勌����с�壔��篁ヤ����� 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 "Decimal Versions" above
-
Normal Form
(罩h�鏄√�
茲���違�勐����亥�� (��壔�í�若����������������勉���櫝�純�с��������v-���絖����) �����������⓾�� ������������ qv() 羲�膊�絖������������☗����������������������若�吾�с�潟�ŝ����吾�с�壔����勉�������˨�� ���絖����������������茵◐憜就綣����罩h����������������夌軒絨����������綵√�� (篏������ŝ�若�㏍��������) ��с�� �����㏍�� 'v' ���篁������☀����������障��:
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"
��☎����������������若�吾�с�潟�勖����潟��篆���ゃ�������˨��罩h��������������茵◐憜就綣���壠��������篏 3 ��ゃ�勌��篏���������������ŝ�������違�ŝ����障�������� 荐�������������������篁ヤ����勉�潟�若����壠幻��̥�������ŝ�����������篆�荐若�������障��:
my $newver = version->new($ver->stringify); if ($newver eq $ver ) # always true {...}
-
Numification
(��医�ゅ��)
�����若�吾�с�潟�ŝ����吾�с�壔�����絲障�������医⑥�����ʋ��膊���壔�������í�˨����с�壠���� 胼�罩≪�������⓾����障��������$obj->numify ��<�純��������篏帥����������с����勉����若�吾�с� ��ŝ����吾�с�壔�����絲上����������医�ゃ����������冴������������櫝�純�с����� �����í�若����������c�潟�違�勉�������˨�������若�吾�с�潟�ŝ����吾�с�壔�����絲上����������医�ゃ�� 茵◐ず�����������˨�壔��筝�篏������若�吾�с�潟�壠����� 3 罅����������篁勐����������障����� 緇���c�⓾��箴����������������篁ヤ����勉�������˨�ŝ����障��:
print $ver->numify; # prints 1.002003004 print $nver->numify; # prints 1.002
���絖�������羲�膊�絖���◒����c�⓾��罩c����������若�吾�с�喝�ゃ��篆����������������������絨障�勉�若�㏍�� 菴遵��������綽�荀���壠�������������障��������
-
Stringification
(���絖�������)
�����若�吾�с�潟�ŝ����吾�с�壔����勖��絖���������勉�������í�˨����壔��
new()
��˨��������qv()
��˨����������̹�≪����������� ��ŝ����吾�с�壔�����篏������������勉�����������������絖���������ŝ����障����������蚊����ゃ�勌��紊���� ��������障����� ��壚����勌��紊���壔����ŝ����吾�с�壔�����qv()
���篏帥�c�☖�������������� ���������絖���� 2 ��ゃ�勐����我�違����ŝ����c�������������㏍�� 'v' �����ŝ����翫�� (�����������壚検��鴻�������ŝ����激�с�潟�с��)���緇ɾ�医�☎�����絲上����������������˨�� ���絖�������綵√����壠����㏍�� 'v' �����ゃ����障�����箴�������:
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
UNIVERSAL::VERSION ��������с����⓾�����������; ��������������壔�í�鴻�<�純������������� 篏帥����������������˨�壩��絖�������綵√�����菴������障�����
���荀���ʋ絵���: 筝�菴違�勤;��˨�壔�����������絖����������絖�������茵◐憗�����絖���������̥��箴<�с�ŝ�� 筝���ゃ�勌��紊������������障����� �����㏍�� 'v' ��ŝ�� ������ 絨���亥�剛����ゃ�������勉����若�吾�с�潟��
qv()
羲�膊�絖���� 篏帥�����������絖���������阪����壩����潟��篆�絖���������������������㏍�� 'v' ���篁������障����� ��������ŝ��荅括完��˨�ゃ����⓾�� qv() 羲�膊�絖���������с����⓾�����������������荀���ʋ絵��� 2: ��������� numify() ��� normal() �����ñ����������������ч��絽吾� ���絖�������荀������������帥�����������������������������薊������鴻��腟������˨�ŝ����障��:
print version->new(version->new("v1.0")->numify)->normal; # v1.0.0
�����勛����宴�壔��numify() 羲�膊�絖���� "v1.0" ���膈�箴<�ʋ��絖���� "1.000000" �� 紊���������������с����� 紊���眼�勉����若�吾�с�潟�ŝ����吾�с�壔����� normal() 綵√����吾�勛�壩③��壩�医�ょ����̥��箴<� "v1.0.0" ���茵◐ず��������障�����
new() ��勌�����腓冴����⓾�������������˨�������ゃ�с����≪��絖���������������若�吾�с� ��ŝ����吾�с�壔�������������ゃ�с����⓾��絨������ŝ�潟����若��篏���������������с����障��:
$v2 = $v1->new($v1);
���������
$v1
���$v2
��壠����◑;�憗��������絖���������̬�潟����障�у�������̥��箴<�с�����
-
Comparison operators
(罸�莠�羲�膊�絖�)
cmp
���<=>
��壚検��鴻�����������罸�莠������������ц�������障�� (��ɱ������� �����若�吾�с�潟�ŝ����吾�с�壔����˨�≪�������違�㋘�若�������障��)��� ��������� 2 ��ゃ����冴�ャ����⓾��Perl ��壚����勖��莠�羲�膊�絖���������☀�ɱ�������̥����������障����� 篁ヤ�������������������⓾����������������ɾ����ゆ�с����������⓾�����絨障�� 0 ��勰�����筝���よ申��������⓾�� 罸�莠������勉����若�吾�с�喝�ゃ�壠����������障�������� 荐�������������������"v1.2" ���"1.2.0" ��勖��莠���壠��筝���◑����ŝ�������障�����箴������違��篁ヤ����勰�≫�����膓㊥����������障��:
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
10 ��我�域��羈�������絖����荐�羈���勉�í�<����������吾����с��������篏帥��膓�������������������羞隙恒��� ��帥�������������˨�壔����������������鴻����с����������� Perl6 ��勉����若�吾�с�潟�ŝ����吾�с�壔����� 10 ��我�井��莠���勉�帥�� ��泣����若�������� ��������������障�������� Quoting ��������с����⓾��������������
茘☗��:(���������������腓榊��������藥���������̹�≪��������) 絨���亥�鴻�勖�違����違�ŝ�������若�吾�с�潟� 罸�莠���壚��荀�������������緇������ŝ��腟������������水�冴����������������障�������� 箴������違��篁ヤ����勰��膈���ゆ�с��������腴���<�障��:
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
�����勛����宴�勉��������"Decimal Versions" ��� "Dotted-Decimal Versions" ��勉�í�<�������� ���篁������˨�������よ����違�勐����亥�鴻��篁������☖戎�����������������鴻����с�����
-
Logical Operators
�����������若�吾�с�潟�ŝ����吾�с�壔����������������������⓾����������í��������腆冴����������������違�� 膂≦����̥�贋・�����鴻����с����障��:
$vobj = version->new($something); if ( $vobj ) # true only if $something was non-blank
��障�����箴������違�<�ゃ�潟�ŝ�ŝ�若�鴻�с�壩��箴���������ŝ��罘���純�勌戎��������蚊����������c�� ��勛����勉�������˨�������若�吾�с�潟�ŝ����吾�с�壔����� "Alpha Versions" ��с����������í�������� 腆冴����������˨�壚札筝���勉�������˨����障��:
$vobj = version->new("1.2_3"); # MUST QUOTE ...later... if ( $vobj->is_alpha ) # True
(��壔�í�若��)
Perl ��������若�鴻�������若�壔�喝�����茵���������㏍�違�í����勌��腟���帥�勉�������������潟����� �����若�吾�с�潟��罩c����������若�鴻�������������˨����鴻�� qv() 羲�膊�絖����篏睡�������������˨�壔�� ��劫����勐�������ゃ�� 綽���� ��壔�í�若�������ŝ�������違�ŝ����障�������� �����⓾�勉�宴�若�鴻�˨�������⓾��version->new() ���羝<��������羌勐��絨���亥�号�違�勐�ゃ�壔�������勐�ゃ�� ��壔�í�若����������⓾�������������ŝ��������������筝����紊������������障����� ������������qv() ��с�壔����壔�í�若����������⓾����ŝ����ュ����ф��絨障�勉�若�㏍�� ��������純�<�⓾����障����翫����˨�壔����勉�������˨�ŝ����������������違�ŝ�� �����若�吾�с�潟�ŝ����吾�с�壔�����腟������������☀����������障�����
��������⓾��篁ュ����� Perl ��勉����若�吾�с�潟�鴻�帥�ゃ�˨��篋������с��篆���ゃ�������˨��5.006001 �� ������綵√����勉����若�吾�с�潟��篏睡����������������� v5.6.1 ��勉��������紊������������障����� 荐�������������������絨���亥�鴻�� 1 ��ゃ�勉����若�吾�с�潟�壔��筝�篏������若�吾�с�渇����˨�� 3 罅��� ��医��������藥�������絖������������������˨����若�鴻�������障�������������勛�勛����壠�����罸�莠���勉�帥�с�����
��������������������⓾�����荀������壔��茖吾�勖�医�� (�����ŝ����<�壔�í�若����������⓾����ŝ��������) ��с� ��≪�潟����若�鴻�潟�≪�壩③綵���� 10 ��我�亥����勖��絖���с����c�⓾�������若�吾�с�潟�潟�若����� ��若�喝�冴�������������� Perl ��勉����若�壔����ゃ�吟�˨����c�☀�ɱ����������ャ����������������������с����� �����������ŝ����������������医�ゃ�� 1 ��や札筝���勐����違����˨����с����⓾�≪�潟����若�鴻�潟�≪�� ��壔�í�若����������⓾�������翫����������ŝ����∴8��勖�医�ゃ�с�壔�ŝ����翫����� "Alpha Version" ��с�������◑����ŝ�������⓾�≪�潟����若�鴻�潟�≪�������鴻�˨�ŝ����障�����
������羌勐��絨���違��羆���障����医�����篏帥�c����翫��������緇������������若�吾�с�潟�������水�冴�������� ��í�������� Perl ��勐�������˨�若����潟�˩��絖���������������˨�ŝ����障����� 箴������� 10 ��勛姦箙���у�蚊����������奝��絽吾��絎������с��������篁���勖��膊���壔��������������緇������� ��ゃ�˨�壔�ŝ����ŝ����с����������� 箴�������:
$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
Perl 5.8.1 篁ラ�����v-���絖���������ɱ�������˨�壔�í�若����с����障����������������壚札����� �����若�吾�с�潟�� Perl ��с�壚���櫝�純�с����� 荐�������������������:
$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
(��泣����壔�í�劫��)
�����勉�≪�吾�ャ�若�˨�夌亜�����˨�泣����壔�í�劫�������с�����������������腆冴�̬┃荐���������鴻�������� �����⓾����障����� 絎������˨�壔��紊���眼����������<�純����������ŝ�若����若�í�ゃ����������������� OK ��с�������� new() �����ŝ�若����若�í�ゃ�������������˨�壩絵������綽�荀���с�� (�����若�鴻�������☀����������� ��贋����ŝ�勉��)��� 箴������違����������壠����������>散���羣���������⓾�����羇丞����壔�í�鴻�с��:
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;
}
�����若�吾�с�恰��絖������勌撮��帥�勤;�憜就綣���˨�ゃ����⓾�� CPAN ��� version::AlphaBeta ��� �����с����⓾��������������
羈����: qv 羲�膊�絖���夌����勉�壔�í�鴻�<�純�������с�壔�ŝ����������������若�喝�冴������� ������腥咲����˨����壔�鴻����若�������������∽�違�с��version ��勉�泣����壔�í�鴻�壔������� ��泣����壔�í�鴻�˩撮�����c�〠③�����������吾����壔��絎�茵������� import() ��∽�違��膓���帥����障�����
(�����壔�鴻����若��)
qv - ���������篁���� 10 ��我�違����若�吾�с�喝��������羲�膊�絖�
John Peacock <jpeacock@cpan.org>
perl.