NAME
GraphViz2::Parse::Graph6 - read graph6 or sparse6 file into a GraphViz2 graph
SYNOPSIS
use GraphViz2::Parse::Graph6;
my $parse = GraphViz2::Parse::Graph6->new;
$parse->create(file_name => 'foo.g6');
my $graphviz2 = $parse->graph; # GraphViz2 object
# or in one chain ...
my $graphviz2 = GraphViz2::Parse::Graph6->new
->create(str => ":Bf\n")
->graph; # GraphViz2 object
DESCRIPTION
GraphViz2::Parse::Graph6
reads a graph6 or sparse6 format file into a GraphViz2
graph object. These file formats are per
The formats represent a graph with vertices numbered 0 to n-1. These are made into GraphViz2
vertex names as numbers like "0" to "99".
graph6 and sparse6 are undirected. sparse6 can have multi-edges and self loops. They are added to the graph with multiple add_edge()
in the usual way.
See Graph::Graph6 for further notes on the formats.
FUNCTIONS
$parse = GraphViz2::Parse::Graph6->new (key=>value, ...)
-
Create and return a new parse object. The only key/value parameter is a graph to read into
graph => GraphViz2 object
The default is to create a suitable undirected
graph
. Currently no options or attributes are set on this default.graph6 and sparse6 have no attributes (only vertex numbers and edges) so it's up to an application to set any desired drawing styles. That can be done by giving a
graph
with options, or by retrieving the$parse->graph
created and adding to it. Note thatnode
oredge
defaults should be set before reading withcreate()
since those settings apply only to subsequently added nodes and edges. Agraph
given should be undirected (which is theGraphViz2
default). $graphviz2 = $parse->graph ()
$parse->graph ($graphviz2)
-
Get or set the graph object which
create()
will write into. $parse->create (key=>value, ...)
-
Read a graph from a file or string of graph6 or sparse6 data. The key/value parameters are
file_name => filename (string) fh => file handle (globref) str => string of graph6 or sparse6
One of these must be given as the input source. The return value is the
$parse
object itself if successful, orundef
at end of file.Invalid file contents or read error call the graph object
log()
method$graphviz2->log(error=>"...")
, which by default is adie
.It's common to have several graphs in a graph6 or sparse6 file, one after the other. They can be read successively by giving
fh
as an open handle to such a file. After a successful read the handle is left positioned at the next graph.The end-of-file
undef
return is given forfh
reaching EOF, or immediate EOF on an empty file or emptystr
. This is designed to make the three inputs the same (file_name
equivalent to open andfh
, or both equivalent to slurp and contents asstr
). An application can consider whether an empty file should mean no graphs or some error.A
$parse
object can be re-used to read further graphs. Set a new emptygraph
to write to each time. See examples/graphviz2-geng.pl for a complete sample program doing this.
BUGS
digraph6 format is accepted by the code here, but the handling of directedness of the resulting GraphViz2
object is not quite right. The intention is for create()
to set directedness of the target graph
, reckoning directedness as being part of the input read, ie. the format graph6, sparse6 or digraph6. But GraphViz2
circa 2.46 takes directedness only when creating the graph, not a later change. For now reading digraph6 works if the application passes in a directed graph
.
SEE ALSO
GraphViz2, GraphViz2::Parse::Yacc
HOME PAGE
http://user42.tuxfamily.org/graph-graph6/index.html
LICENSE
Copyright 2015, 2016, 2017, 2018 Kevin Ryde
Graph-Graph6 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Graph-Graph6 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Graph-Graph6. If not, see http://www.gnu.org/licenses/.