Subject: | classes derived from Graph cannot inherit constructors |
Graph-0.20104 does not fully support derived classes (it fails the 'empty subclass test' described in the perlmodlib manpage). I'm running perl v5.6.1 built for i686-linux.
Currently, a derived class must define stubs for any method returning a Graph object. Methods directed() and undirected() force the object to be either a Graph::Directed or Graph::Undirected instance; this overrides the actual class when constructing objects. The methods affected include new(), copy(), strongly_connected_graph(), TransitiveClosure_Floyd_Warshall(), APSP_Floyd_Warshall(), MST_Kruskal(), and complete().
The attached patch changes directed() and undirected() to allow derived classes to inherit constructor methods.
Example of the problem:
U.pm:
-----
package U; require Graph::Directed; @U::ISA=qw(Graph::Directed); 1
---
perl -e 'use U; print ref(new U)'
gives 'Graph::Directed' instead of 'U'.
--- Base.pm 2004-05-05 22:54:25.000000000 +0200
+++ Base.pm.mod 2004-05-25 09:19:57.000000000 +0200
@@ -214,15 +214,16 @@
my $o = $G->{ D }; # Old directedness.
$G->{ D } = $d;
- if (not $o) {
+ if (defined $o and not $o) {
my @E = $G->edges;
while (my ($u, $v) = splice(@E, 0, 2)) {
$G->add_edge($v, $u);
}
+ return bless $G, 'Graph::Directed'; # Re-bless.
}
- return bless $G, 'Graph::Directed'; # Re-bless.
+ return $G; # Don't re-bless unless needed.
} else {
return $G->undirected(not $d);
}