Skip to content

Commit 1e8d89f

Browse files
committed
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.
1 parent 5dc932f commit 1e8d89f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/test/perl/PostgresVersion.pm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ PostgresVersion - class representing PostgreSQL version numbers
3232
# interpolate in a string
3333
my $stringyval = "version: $version";
3434
35+
# get the major version
36+
my $maj = $version->major;
37+
3538
=head1 DESCRIPTION
3639
3740
PostgresVersion encapsulates Postgres version numbers, providing parsing
@@ -133,4 +136,29 @@ sub _stringify
133136
return $self->{str};
134137
}
135138

139+
=pod
140+
141+
=over
142+
143+
=item major([separator => 'char'])
144+
145+
Returns the major version. For versions before 10 the parts are separated by
146+
a dot unless the separator argument is given.
147+
148+
=back
149+
150+
=cut
151+
152+
sub major
153+
{
154+
my ($self, %params) = @_;
155+
my $result = $self->{num}->[0];
156+
if ($result + 0 < 10)
157+
{
158+
my $sep = $params{separator} || '.';
159+
$result .= "$sep$self->{num}->[1]";
160+
}
161+
return $result;
162+
}
163+
136164
1;

0 commit comments

Comments
 (0)