Re: TAP: allow overriding PostgresNode in get_new_node
J Chapman Flack <jflack@math.purdue.edu>
From: J Chapman Flack <jflack@math.purdue.edu>
To: Robert Haas <robertmhaas@gmail.com>,
Michael Paquier <michael.paquier@gmail.com>
Cc: Craig Ringer <craig@2ndquadrant.com>,
PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2017-06-02T19:47:12Z
Lists: 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
Commits
-
Make PostgresNode easily subclassable
- 54dacc746628 10.0 landed
- 3b7bbee7b661 9.6.4 landed