PostgresNode-get_new_node-can-be-classmethod-v1.patch
text/x-patch
Filename: PostgresNode-get_new_node-can-be-classmethod-v1.patch
Type: text/x-patch
Part: 0
Patch
Format: unified
Series: patch v1
| File | + | − |
|---|---|---|
| src/test/perl/PostgresNode.pm | 11 | 4 |
--- src/test/perl/PostgresNode.pm 2017-06-07 20:15:52.827639829 -0400
+++ src/test/perl/PostgresNode.pm 2017-06-07 20:57:49.205145761 -0400
@@ -853,20 +853,27 @@
=pod
-=item get_new_node(node_name)
+=item get_new_node(node_name) I<or> PostgresNode->get_new_node(node_name)
-Build a new PostgresNode object, assigning a free port number. Standalone
-function that's automatically imported.
+Build a new PostgresNode object, assigning a free port number. This can be
+called either as a standalone function that's automatically imported, or as
+a class method on PostgresNode or any subclass.
Remembers the node, to prevent its port number from being reused for another
node, and to ensure that it gets shut down when the test script exits.
You should generally use this instead of PostgresNode::new(...).
+If you have a subclass of PostgresNode you want created, use the class-method
+form of the call, as in C<MyExtendedPostgresNode->get_new_node(node_name)>.
+The standalone-function form creates an instance of PostgresNode.
+
=cut
sub get_new_node
{
+ my $class = 'PostgresNode';
+ $class = shift if 1 < scalar @_;
my $name = shift;
my $found = 0;
my $port = $last_port_assigned;
@@ -911,7 +918,7 @@
print "# Found free port $port\n";
# Lock port number found by creating a new node
- my $node = new PostgresNode($name, $test_pghost, $port);
+ my $node = $class->new($name, $test_pghost, $port);
# Add node to list of nodes
push(@all_nodes, $node);