🌻 📖 Alien::Build::Version::Basic

NAME

Alien::Build::Version::Basic - Very basic version object for Alien::Build

VERSION

version 2.84

SYNOPSIS

OO interface:

 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

DESCRIPTION

This module provides a very basic class for comparing versions. This is already a crowded space on CPAN. Parts of Alien::Build already use Sort::Versions, which is fine for sorting versions. Sometimes you need to compare to see if versions match exact values, and the best candidates (such as Sort::Versions on CPAN compare 1.2.3.0 and 1.2.3 as being different. This class compares those two as the same.

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.

CONSTRUCTOR

new

 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.

version

 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.

METHODS

as_string

 my $string = $version->as_string;
 my $string = "$version";

Returns the string representation of the version object.

cmp

 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.

SEE ALSO

Sort::Versions

Good, especially if you have to support rpm style versions (like 1.2.3-2-b) or don't care if trailing zeros (1.2.3 vs 1.2.3.0) are treated as different values.

version

Problematic for historical reasons.

AUTHOR

Author: Graham Ollis <plicease@cpan.org>

Contributors:

Diab Jerius (DJERIUS)

Roy Storey (KIWIROY)

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 Písař (ppisar)

Lance Wicks (LANCEW)

Ahmad Fatoum (a3f, ATHREEF)

José Joaquín Atria (JJATRIA)

Duke Leto (LETO)

Shoichi Kaji (SKAJI)

Shawn Laffan (SLAFFAN)

Paul Evans (leonerd, PEVANS)

Håkon Hægland (hakonhagland, HAKONH)

nick nauwelaerts (INPHOBIA)

Florian Weimer

COPYRIGHT AND LICENSE

This software is copyright (c) 2011-2022 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.