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
DESCRIPTION
GraphViz2::Parse::Graph6
reads a graph6 or sparse6 format file into a GraphViz2
graph object. These file formats are per
Both formats represent an undirected graph with vertices numbered 0 to n-1. They are made into GraphViz2
vertex names as numbers like "0" to "999".
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 (or default created)
graph
should be undirected. The default is a suitable new emptyGraphViz2
.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 here, or by retrieving the new created graph and adding to it.
node
oredge
defaults should be set before reading withcreate()
since those settings apply only to subsequently added nodes and edges. $graphviz2 = $parse->graph ()
$parse->graph ($graphviz2)
-
Get or set the graph object which
create()
will write into. $parse->create (key=>value, ...)
-
Read a given file or string of graph6 or sparse6 data. The key/value parameters are
file_name => string filename fh => ref to file handle 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. The handle is left positioned ready to read the next graph.The end-of-file
undef
return is given for immediate EOF on an empty file or emptystr
as well asfh
reaching EOF. This is designed to make the three inputs the same (file_name
equivalent to open andfh
, and both equivalent to slurp and contents instr
). An application can consider whether an empty file should mean no graphs or some error.A
$parse
object can be re-used to read successive graphs from the same or difference source. Set a new emptygraph
to write to each time. See examples/graphviz2-geng.pl in the Graph-Graph6 sources for a complete sample program doing this.
SEE ALSO
GraphViz2, GraphViz2::Parse::Yacc
HOME PAGE
http://user42.tuxfamily.org/graph-graph6/index.html
LICENSE
Copyright 2015 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/.