Tels

NAME

Graph::Regexp - Create graphical flowchart from a regular expression

SYNOPSIS

        # print out ASCII graph
        perl -Mre=debug -e '/just|another|perl|hacker/' 2>&1 | examples/regraph

        # the same, as PNG rendered via dot
        perl -Mre=debug -e '/me|you/' 2>&1 | examples/regraph as_graphviz | dot -Tpng -o me.png

DESCRIPTION

This module takes the debug dump of a regular expression (regexp) as generated by Perl itself, and creates a flowchart from it as a Graph::Easy object.

This in turn can be converted it into all output formats currently supported by Graph::Easy, namely HTML, SVG, ASCII art, Unicode art, graphviz code (which then can be rendered as PNG etc) etc.

Customizing the graph

Per default, the graph will have certain properties, like bold start/end blocks, diamond-shaped branch-blocks and so on. You can change these by setting class attributes on the returned graph object. The class for each node is the same as it appears in the dump, in lowercase:

        start
        exact
        plus
        star
        trie
        curly
        end

etc.

EXPORT

Exports nothing.

METHODS

graph() provides a simple function-style interface, while all other methods are for an object-oriented model.

graph()

        my $graph = Graph::Regexp->graph( $dump );

Takes a regexp dump in $dump (as SCALAR) and returns a Graph::Easy object.

This is a shortcut to avoid the OO interface described below and will be equivalent to:

        my $parser = Graph::Regexp->new();
        $parser->parse( $dump );
        my $graph = $parser->as_graph();

Please see Graph::Easy for further details on what to do with the returned object.

new()

        my $parser = Graph::Regexp->new( $options );

Creates a new Graph::Regexp object.

The optional $options is a hash reference with parameters.

At the moment no options are defined.

option()

        my $option = $parser->option($name);

Return the option with the given name from the Graph::Regexp object.

decompose()

        $parser->decompose( \$txt );            # \'...'
        $parser->decompose( $filename );        # 'regexp_dump.txt'

Takes Regexp dump (scalar ref in $txt) or file (filename in $filename) and creates a graph from it.

parse()

This is an alias for decompose().

reset()

        $parser->reset();

Reset the internal state of the parser object. Called automatically by decompose().

as_graph()

        my $graph = $parser->as_graph();

Return the internal data structure as Graph::Easy object.

as_ascii()

        print $parser->as_ascii();

Return the graph as ASCII art. Shortcut for $parser-as_graph->as_ascii()>.

graph_label()

        my $label = $parser->graph_label();
        $parser->graph_label('/^foo|bar/');

Set or get the label of the graph.

BUGS

Does not yet handle the new things like TRIE.

SEE ALSO

Graph::Easy, Graph::Flowchart

COPYRIGHT AND LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms of the GPL version 2 or later. See the LICENSE file for information.

AUTHOR

Copyright (C) 2006-2008 by Tels http://bloodgate.com