aboutsummaryrefslogtreecommitdiff
path: root/src/test/perl/PostgresVersion.pm
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2021-04-22 15:25:37 -0400
committerAndrew Dunstan <andrew@dunslane.net>2021-04-22 15:27:05 -0400
commit502dc6df8f6eeba06812ce09488efc7e684f5ec9 (patch)
tree1b74ab107b99a8202ceaa2304efa0f3926cfbf41 /src/test/perl/PostgresVersion.pm
parent8aba9322511f718f12b618470d8c07f0ee5f0700 (diff)
downloadpostgresql-502dc6df8f6eeba06812ce09488efc7e684f5ec9.tar.gz
postgresql-502dc6df8f6eeba06812ce09488efc7e684f5ec9.zip
Make PostgresVersion code a bit more robust and simple.
per gripe from Alvaro Herrera.
Diffstat (limited to 'src/test/perl/PostgresVersion.pm')
-rw-r--r--src/test/perl/PostgresVersion.pm19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/test/perl/PostgresVersion.pm b/src/test/perl/PostgresVersion.pm
index 14750365acf..3f3744ccfa9 100644
--- a/src/test/perl/PostgresVersion.pm
+++ b/src/test/perl/PostgresVersion.pm
@@ -34,7 +34,7 @@ PostgresVersion - class representing PostgreSQL version numbers
=head1 DESCRIPTION
-PostgresVersion encapsulated Postgres version numbers, providing parsing
+PostgresVersion encapsulates Postgres version numbers, providing parsing
of common version formats and comparison operations.
=cut
@@ -73,25 +73,22 @@ sub new
my $class = shift;
my $arg = shift;
+ chomp $arg;
+
# Accept standard formats, in case caller has handed us the output of a
# postgres command line tool
- $arg = $1
- if ($arg =~ m/\(?PostgreSQL\)? (\d+(?:\.\d+)*(?:devel)?)/);
+ my $devel;
+ ($arg,$devel) = ($1, $2)
+ if ($arg =~ m/^(?:\(?PostgreSQL\)? )?(\d+(?:\.\d+)*)(devel)?/);
# Split into an array
my @result = split(/\./, $arg);
# Treat development versions as having a minor/micro version one less than
# the first released version of that branch.
- if ($result[$#result] =~ m/^(\d+)devel$/)
- {
- pop(@result);
- push(@result, $1, -1);
- }
+ push @result, -1 if ($devel);
- my $res = [@result];
- bless $res, $class;
- return $res;
+ return bless \@result, $class;
}