Make PostgresVersion code a bit more robust and simple.

per gripe from Alvaro Herrera.
This commit is contained in:
Andrew Dunstan 2021-04-22 15:25:37 -04:00
parent 8aba932251
commit 502dc6df8f

View File

@ -34,7 +34,7 @@ PostgresVersion - class representing PostgreSQL version numbers
=head1 DESCRIPTION =head1 DESCRIPTION
PostgresVersion encapsulated Postgres version numbers, providing parsing PostgresVersion encapsulates Postgres version numbers, providing parsing
of common version formats and comparison operations. of common version formats and comparison operations.
=cut =cut
@ -73,25 +73,22 @@ sub new
my $class = shift; my $class = shift;
my $arg = shift; my $arg = shift;
chomp $arg;
# Accept standard formats, in case caller has handed us the output of a # Accept standard formats, in case caller has handed us the output of a
# postgres command line tool # postgres command line tool
$arg = $1 my $devel;
if ($arg =~ m/\(?PostgreSQL\)? (\d+(?:\.\d+)*(?:devel)?)/); ($arg,$devel) = ($1, $2)
if ($arg =~ m/^(?:\(?PostgreSQL\)? )?(\d+(?:\.\d+)*)(devel)?/);
# Split into an array # Split into an array
my @result = split(/\./, $arg); my @result = split(/\./, $arg);
# Treat development versions as having a minor/micro version one less than # Treat development versions as having a minor/micro version one less than
# the first released version of that branch. # the first released version of that branch.
if ($result[$#result] =~ m/^(\d+)devel$/) push @result, -1 if ($devel);
{
pop(@result);
push(@result, $1, -1);
}
my $res = [@result]; return bless \@result, $class;
bless $res, $class;
return $res;
} }