Skip to content

Commit 502dc6d

Browse files
committed
Make PostgresVersion code a bit more robust and simple.
per gripe from Alvaro Herrera.
1 parent 8aba932 commit 502dc6d

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/test/perl/PostgresVersion.pm

+8-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ PostgresVersion - class representing PostgreSQL version numbers
3434
3535
=head1 DESCRIPTION
3636
37-
PostgresVersion encapsulated Postgres version numbers, providing parsing
37+
PostgresVersion encapsulates Postgres version numbers, providing parsing
3838
of common version formats and comparison operations.
3939
4040
=cut
@@ -73,25 +73,22 @@ sub new
7373
my $class = shift;
7474
my $arg = shift;
7575

76+
chomp $arg;
77+
7678
# Accept standard formats, in case caller has handed us the output of a
7779
# postgres command line tool
78-
$arg = $1
79-
if ($arg =~ m/\(?PostgreSQL\)? (\d+(?:\.\d+)*(?:devel)?)/);
80+
my $devel;
81+
($arg,$devel) = ($1, $2)
82+
if ($arg =~ m/^(?:\(?PostgreSQL\)? )?(\d+(?:\.\d+)*)(devel)?/);
8083

8184
# Split into an array
8285
my @result = split(/\./, $arg);
8386

8487
# Treat development versions as having a minor/micro version one less than
8588
# the first released version of that branch.
86-
if ($result[$#result] =~ m/^(\d+)devel$/)
87-
{
88-
pop(@result);
89-
push(@result, $1, -1);
90-
}
89+
push @result, -1 if ($devel);
9190

92-
my $res = [@result];
93-
bless $res, $class;
94-
return $res;
91+
return bless \@result, $class;
9592
}
9693

9794

0 commit comments

Comments
 (0)