Graph::Easy::Parser - Parse graph from textual description
# creating a graph from a textual description use Graph::Easy::Parser; my $parser = Graph::Easy::Parser->new(); my $graph = $parser->from_text( '[ Bonn ] => [ Berlin ]'. '[ Berlin ] => [ Rostock ]'. ); print $graph->as_ascii( );
Graph::Easy::Parser lets you parse simple textual descriptions of graphs, and constructs a Graph::Easy object from them.
Graph::Easy::Parser
Graph::Easy
The resulting object can than be used to layout and output the graph.
The input consists of text describing the graph.
[ Bonn ] --> [ Berlin ] [ Frankfurt ] <=> [ Dresden ] [ Bonn ] --> [ Frankfurt ] [ Bonn ] ==> [ Frankfurt ]
See Output for how this will be rendered in ASCII art.
The edges between the nodes can have the following styles:
--> line ==> double line ..> dotted - > dashed
In additon the following three directions are possible:
--> connect the node on the left to the node on the right <--> the direction between the nodes goes into both directions at once <-- connect the node on the right to the node on the left
Of course you can combine all three directions with all styles.
The output will be a Graph::Easy object, see there for what you can do with it.
See Graph::Easy for an extensive list of examples.
Graph::Easy::Parser supports the following methods:
use Graph::Easy::Parser; my $parser = Graph::Easy::Parser->new();
Creates a new parser object.
$parser->reset();
Reset the status of the parser, clear errors etc.
my $graph = $parser->from_text( $text );
Create a Graph::Easy object from the textual description in $text.
$text
Returns undef for error, you can find out what the error was with error().
This method will reset any previous error, and thus the $parser object can be re-used to parse different texts by just calling from_text() multiple times.
$parser
from_text()
my $graph = $parser->from_file( $filename );
Creates a Graph::Easy object from the textual description in the file $filename.
$filename
my $error = $parser->error();
Returns the last error, or the empty string if no error occured.
my $attributes = $parser->_parse_attributes( $txt );
Internal usage only. Takes a text like this:
attribute: value; attribute2 : value2;
and returns a hash with the attributes.
Exports nothing.
Graph::Easy.
Copyright (C) 2004 - 2005 by Tels http://bloodgate.com
See the LICENSE file for information.
To install Graph::Easy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Graph::Easy
CPAN shell
perl -MCPAN -e shell install Graph::Easy
For more information on module installation, please visit the detailed CPAN module installation guide.