Subject: | suggest make_graph() for subclass use |
Date: | Wed, 06 Sep 2017 17:10:18 +1000 |
To: | bug-Graph-Maker [...] rt.cpan.org |
From: | Kevin Ryde <user42_kevin [...] yahoo.com.au> |
As an idea for a feature, it could be good if Graph::Maker had some
common func which subclasses could use to create their graph, grabbing
the graph_maker parameter if present.
It'd be only a few lines, but all subclasses would use it. Perhaps
something like below. Could put other common parameters there in the
future, though the only such I thought of would be perhaps
graph_class=>'My::Graph::Class' to specify a different graph class by
name, rather than constructor subr.
# Usage: $graph = $self->make_graph(key=>value,...)
# This method is intended for use by subclasses.
# Create and return a graph with given key/value parameters.
# Parameter graph_maker is used (and removed) if given, or Graph.pm otherwise.
sub make_graph {
my ($self, %params) = @_;
my $graph_maker = delete($params{'graph_maker'}) || \&_default_graph_maker;
return $graph_maker->(%params);
}
sub _default_graph_maker {
require Graph;
return Graph->new(@_);
}