| 1 | package Search::Typesense::Version; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Version object for the Typesense server version | ||||||||||
| 4 | |||||||||||
| 5 | 4 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use Search::Typesense::Types qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | NonEmptyStr | ||||||||||
| 9 | PositiveOrZeroInt | ||||||||||
| 10 | 4 | ); | |||||||||
| 11 | |||||||||||
| 12 | 4 | our $VERSION = '0.08'; | |||||||||
| 13 | |||||||||||
| 14 | 4 | has version_string => ( | |||||||||
| 15 | is => 'ro', | ||||||||||
| 16 | isa => NonEmptyStr, | ||||||||||
| 17 | required => 1, | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | 4 | has [qw/major minor patch/] => ( | |||||||||
| 21 | is => 'rwp', | ||||||||||
| 22 | isa => PositiveOrZeroInt, | ||||||||||
| 23 | init_arg => undef, | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | 3 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 27 | 3 | my $self = shift; | |||||||||
| 28 | 3 | my $version = $self->version_string; | |||||||||
| 29 | |||||||||||
| 30 | # this isn't quite semver, but it seems to fit what Typesense is doing | ||||||||||
| 31 | # See https://semver.org/ if this breaks | ||||||||||
| 32 | 3 | ▶ | unless ( $version =~ /^\d+\.\d+\.\d+$/a ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 1 | croak("Invalid version string: $version"); | |||||||||
| 34 | } | ||||||||||
| 35 | 2 | my @version = split /\./ => $version; | |||||||||
| 36 | 2 | $self->_set_major( $version[0] ); | |||||||||
| 37 | 2 | $self->_set_minor( $version[1] ); | |||||||||
| 38 | 2 | $self->_set_patch( $version[2] ); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 1 | ▶ | sub comparator { | ||||||||
|
Subroutine
comparator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 42 | 1 | my $self = shift; | |||||||||
| 43 | 1 | return sprintf "%03d%03d%03d" => $self->major, $self->minor, $self->patch; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 4 | 1; | |||||||||
| 47 | |||||||||||
| 48 | __END__ | ||||||||||