The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Graph::Easy::Parser - Parse graph from textual description

SYNOPSIS

        # 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( );

DESCRIPTION

Graph::Easy::Parser lets you parse simple textual descriptions of graphs, and constructs a Graph::Easy object from them.

The resulting object can than be used to layout and output the graph.

Input

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.

Output

The output will be a Graph::Easy object, see there for what you can do with it.

EXAMPLES

See Graph::Easy for an extensive list of examples.

METHODS

Graph::Easy::Parser supports the following methods:

new()

        use Graph::Easy::Parser;
        my $parser = Graph::Easy::Parser->new();

Creates a new parser object.

reset()

        $parser->reset();

Reset the status of the parser, clear errors etc.

from_text()

        my $graph = $parser->from_text( $text );

Create a Graph::Easy object from the textual description in $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.

from_file()

        my $graph = $parser->from_file( $filename );

Creates a Graph::Easy object from the textual description in the file $filename.

Returns undef for error, you can find out what the error was with error().

error()

        my $error = $parser->error();

Returns the last error, or the empty string if no error occured.

_parse_attributes()

        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.

EXPORT

Exports nothing.

SEE ALSO

Graph::Easy.

AUTHOR

Copyright (C) 2004 - 2005 by Tels http://bloodgate.com

See the LICENSE file for information.