Re: TAP: allow overriding PostgresNode in get_new_node

From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: TAP: allow overriding PostgresNode in get_new_node
Date: 2017-06-01 02:18:46
Message-ID: CAMsr+YEpQLxXPW-9sd6ey4Ddsm2=xFHB2F2GaHbx6o9HzTksCA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 31 May 2017 at 08:43, Craig Ringer <craig(at)2ndquadrant(dot)com> wrote:
> Hi all
>
> More and more I'm finding it useful to extend PostgresNode for project
> specific helper classes. But PostgresNode::get_new_node is a factory
> that doesn't provide any mechanism for overriding, so you have to
> create a PostgresNode then re-bless it as your desired subclass. Ugly.
>
> The attached patch allows an optional second argument, a class name,
> to be passed to PostgresNode::get_new_node . It's instantiated instead
> of PostgresNode if supplied. Its 'new' constructor must take the same
> arguments.

Note that you can achieve the same effect w/o patching
PostgresNode.pm, albeit in a somewhat ugly manner, by re-blessing the
returned object.

sub get_new_mywhatever_node {
my $self = PostgresNode::get_new_node($name);
$self = bless $self, 'MyWhateverNode';
return $self;
}

so this would be cosmetically nice, but far from functionally vital.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2017-06-01 02:44:20 Re: Create subscription with `create_slot=false` and incorrect slot name
Previous Message Peter Eisentraut 2017-06-01 02:15:50 Re: Re: Alter subscription..SET - NOTICE message is coming for table which is already removed