File Coverage

blib/lib/Search/Typesense/Version.pm
Criterion Covered Total %
statement 19 19 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 1 2 50.0
total 27 28 96.4


line stmt bran cond sub pod time code
1             package Search::Typesense::Version;
2              
3             # ABSTRACT: Version object for the Typesense server version
4              
5 4     4   39 use Moo;
  4         8  
  4         28  
6 4     4   1740 use Carp qw(croak);
  4         26  
  4         255  
7 4         44 use Search::Typesense::Types qw(
8             NonEmptyStr
9             PositiveOrZeroInt
10 4     4   30 );
  4         15  
11              
12             our $VERSION = '0.08';
13              
14             has version_string => (
15             is => 'ro',
16             isa => NonEmptyStr,
17             required => 1,
18             );
19              
20             has [qw/major minor patch/] => (
21             is => 'rwp',
22             isa => PositiveOrZeroInt,
23             init_arg => undef,
24             );
25              
26             sub BUILD {
27 3     3 0 5522 my $self = shift;
28 3         11 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 100       20 unless ( $version =~ /^\d+\.\d+\.\d+$/a ) {
33 1         28 croak("Invalid version string: $version");
34             }
35 2         11 my @version = split /\./ => $version;
36 2         45 $self->_set_major( $version[0] );
37 2         94 $self->_set_minor( $version[1] );
38 2         83 $self->_set_patch( $version[2] );
39             }
40              
41             sub comparator {
42 1     1 1 2169 my $self = shift;
43 1         17 return sprintf "%03d%03d%03d" => $self->major, $self->minor, $self->patch;
44             }
45              
46             1;
47              
48             __END__
49              
50             =pod
51              
52             =encoding UTF-8
53              
54             =head1 NAME
55              
56             Search::Typesense::Version - Version object for the Typesense server version
57              
58             =head1 VERSION
59              
60             version 0.08
61              
62             =head1 DESCRIPTION
63              
64             Do not use directly. This is returned by the C<typesense_version> method from
65             L<Search::Typesense>.
66              
67             =head1 METHODS
68              
69             =head2 C<version_string>
70              
71             my $version = $typesense->typesense_version;
72             my $version_string = $version->version_string;
73              
74             Returns the semantic version string, such as C<0.19.0>.
75              
76             =head2 C<major>
77              
78             my $version = $typesense->typesense_version;
79             my $major = $version->major;
80              
81             Returns the major version number.
82              
83             =head2 C<minor>
84              
85             my $version = $typesense->typesense_version;
86             my $minor = $version->minor;
87              
88             Returns the minor version number.
89              
90             =head2 C<patch>
91              
92             my $version = $typesense->typesense_version;
93             my $patch = $version->patch;
94              
95             Returns the patch version number.
96              
97             =head2 C<comparator>
98              
99             Returns a numeric string suitable for numeric comparisons between versions.
100              
101             =head1 AUTHOR
102              
103             Curtis "Ovid" Poe <ovid@allaroundtheworld.fr>
104              
105             =head1 COPYRIGHT AND LICENSE
106              
107             This software is copyright (c) 2021 by Curtis "Ovid" Poe.
108              
109             This is free software; you can redistribute it and/or modify it under
110             the same terms as the Perl 5 programming language system itself.
111              
112             =cut