Re: [HACKERS] TAP: allow overriding PostgresNode in get_new_node - Mailing list pgsql-hackers

From Chapman Flack
Subject Re: [HACKERS] TAP: allow overriding PostgresNode in get_new_node
Date
Msg-id 6976f51f-21bf-1f8f-bc07-0bd8a524095d@anastigmatix.net
Whole thread Raw
In response to Re: [HACKERS] TAP: allow overriding PostgresNode in get_new_node  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: [HACKERS] TAP: allow overriding PostgresNode in get_new_node
List pgsql-hackers
On 06/02/2017 12:50 PM, Robert Haas wrote:
> On Thu, Jun 1, 2017 at 3:36 AM, Michael Paquier
>>
>> +    $pgnclass = 'PostgresNode' unless defined $pgnclass;
>> I'd rather leave any code of this kind for the module maintainers,
> 
> Craig's proposal is a standard Perl idiom, though.

Would it not be even more idiomatic to have the class, if
present, be the first argument? That is:
 my $pgnclass = 'PostgresNode'; $pgnclass = shift if 1 < scalar @_; my $name = shift;

That part's a little weird (an optional FIRST argument?) in order
to preserve compatibility with callers who don't pass a class.

But what it buys you is then if your MyExtraPGNode has PostgresNode
as a base, the familiar idiom
 MyExtraPGNode->get_new_node('foo');

works, as it inserts the class as the first argument.

As a bonus, you then don't need to complicate get_new_node
with a test for (not ($node->isa("PostgresNode"))) because
if it weren't, it wouldn't have inherited get_new_node
so MyExtraPGNode->get_new_node('foo') would have failed.

-Chap



pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: [HACKERS] proposal: PLpgSQL parallel assignemnt
Next
From: Petr Jelinek
Date:
Subject: Re: [HACKERS] logical replication - still unstable after all thesemonths