Re: [HACKERS] TAP: allow overriding PostgresNode in get_new_node

Поиск
Список
Период
Сортировка
От J Chapman Flack
Тема Re: [HACKERS] TAP: allow overriding PostgresNode in get_new_node
Дата
Msg-id 633123b7-2bfd-cd66-d5cc-c6aa271d47ee@math.purdue.edu
обсуждение исходный текст
Ответ на Re: [HACKERS] TAP: allow overriding PostgresNode in get_new_node  (Robert Haas <robertmhaas@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] Error while creating subscription when server is running in single user mode
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: [HACKERS] proposal: PLpgSQL parallel assignemnt