Improve logic in PostgresVersion.pm
authorAndrew Dunstan <andrew@dunslane.net>
Tue, 27 Apr 2021 12:21:15 +0000 (08:21 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Tue, 27 Apr 2021 12:21:15 +0000 (08:21 -0400)
Handle the situation where perl swaps the order of operands of
the comparison operator. See `perldoc overload` for details:

The third argument is set to TRUE if (and only if) the two
operands have been swapped. Perl may do this to ensure that the
first argument ($self) is an object implementing the overloaded
operation, in line with general object calling conventions.

src/test/perl/PostgresVersion.pm

index 7ce9e62b798dc940f5f0b75c9f64aa4e91641d02..55984ec7e812062ccdaac698758b8171308ac044 100644 (file)
@@ -110,10 +110,12 @@ sub new
 #
 sub _version_cmp
 {
-   my ($a, $b) = @_;
+   my ($a, $b, $swapped) = @_;
 
    $b = __PACKAGE__->new($b) unless blessed($b);
 
+   ($a, $b) = ($b, $a) if $swapped;
+
    my ($an, $bn) = ($a->{num}, $b->{num});
 
    for (my $idx = 0;; $idx++)