use Alien::Build::Version::Basic; my $version = Alien::Build::Version::Basic->new('1.2.3'); if($version > '1.2.2') # true { ... }
Function interface:
use Alien::Build::Version::Basic qw( version ); if(version('1.2.3') > version('1.2.2')) # true { ... } my @sorted = sort map { version($_) } qw( 2.1 1.2.3 1.2.2 ); # will come out in the order 1.2.2, 1.2.3, 2.1
This class is also quite limited, in that it only works with version schemes using a doted version numbers or real numbers with a fixed number of digits. Versions with: dashes, letters, hex digits, or anything else are not supported.
This class overloads both "<=>" and "cmp" to compare the version in the way that you would expect for version numbers. This way you can compare versions like numbers, or sort them using sort.
if(version($v1) > version($v2)) { ... } my @sorted = sort map { version($_) } @unsorted;
it also overloads "" to stringify as whatever string value you passed to the constructor.
my $version = Alien::Build::Version::Basic->new($value);
This is the long form of the constructor, if you don't want to import anything into your namespace.
my $version = version($value);
This is the short form of the constructor, if you are sane. It is NOT exported by default so you will have to explicitly import it.
my $string = $version->as_string; my $string = "$version";
Returns the string representation of the version object.
my $bool = $version->cmp($other); my $bool = $version <=> $other; my $bool = $version cmp $other;
Returns "-1", 0 or 1 just like the regular "<=>" and "cmp" operators. Although $version must be a version object, $other may be either a version object, or a string that could be used to create a valid version object.
Contributors:
Diab Jerius (DJERIUS)
Roy Storey
Ilya Pavlov
David Mertens (run4flat)
Mark Nunberg (mordy, mnunberg)
Christian Walde (Mithaldu)
Brian Wightman (MidLifeXis)
Zaki Mughal (zmughal)
mohawk (mohawk2, ETJ)
Vikas N Kumar (vikasnkumar)
Flavio Poletti (polettix)
Salvador Fandiño (salva)
Gianni Ceccarelli (dakkar)
Pavel Shaydo (zwon, trinitum)
Kang-min Liu (劉康民, gugod)
Nicholas Shipp (nshp)
Juan Julián Merelo Guervós (JJ)
Joel Berger (JBERGER)
Petr Pisar (ppisar)
Lance Wicks (LANCEW)
Ahmad Fatoum (a3f, ATHREEF)
José Joaquín Atria (JJATRIA)
Duke Leto (LETO)
Shoichi Kaji (SKAJI)
Shawn Laffan (SLAFFAN)
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.