aboutsummaryrefslogtreecommitdiff
path: root/src/test/perl/PostgresVersion.pm
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2021-07-29 05:58:08 -0400
committerAndrew Dunstan <andrew@dunslane.net>2021-07-29 05:58:08 -0400
commit1e8d89f8800e0aaafc66e87e8e5fedf5dbd038cf (patch)
treec01446784380866561c6f70ecd26ebcb55baf656 /src/test/perl/PostgresVersion.pm
parent5dc932f9e7b7d1992abd33d1c519899dd1c30272 (diff)
downloadpostgresql-1e8d89f8800e0aaafc66e87e8e5fedf5dbd038cf.tar.gz
postgresql-1e8d89f8800e0aaafc66e87e8e5fedf5dbd038cf.zip
Add PostgresVersion.pm method to emit the major version string
For versions before 10, this will produce dotted notation unless a separator argument is given, in which case it is used.
Diffstat (limited to 'src/test/perl/PostgresVersion.pm')
-rw-r--r--src/test/perl/PostgresVersion.pm28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/perl/PostgresVersion.pm b/src/test/perl/PostgresVersion.pm
index 4e764c36a55..5ff701ce112 100644
--- a/src/test/perl/PostgresVersion.pm
+++ b/src/test/perl/PostgresVersion.pm
@@ -32,6 +32,9 @@ PostgresVersion - class representing PostgreSQL version numbers
# interpolate in a string
my $stringyval = "version: $version";
+ # get the major version
+ my $maj = $version->major;
+
=head1 DESCRIPTION
PostgresVersion encapsulates Postgres version numbers, providing parsing
@@ -133,4 +136,29 @@ sub _stringify
return $self->{str};
}
+=pod
+
+=over
+
+=item major([separator => 'char'])
+
+Returns the major version. For versions before 10 the parts are separated by
+a dot unless the separator argument is given.
+
+=back
+
+=cut
+
+sub major
+{
+ my ($self, %params) = @_;
+ my $result = $self->{num}->[0];
+ if ($result + 0 < 10)
+ {
+ my $sep = $params{separator} || '.';
+ $result .= "$sep$self->{num}->[1]";
+ }
+ return $result;
+}
+
1;