Graph::Regexp - Create graphical flowchart from a regular expression
# 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
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.
Graph::Easy
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.
Exports nothing.
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.
my $parser = Graph::Regexp->new( $options );
Creates a new Graph::Regexp object.
Graph::Regexp
The optional $options is a hash reference with parameters.
$options
At the moment no options are defined.
my $option = $parser->option($name);
Return the option with the given name from the Graph::Regexp object.
$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.
$txt
$filename
This is an alias for decompose().
decompose()
$parser->reset();
Reset the internal state of the parser object. Called automatically by decompose().
my $graph = $parser->as_graph();
Return the internal data structure as Graph::Easy object.
print $parser->as_ascii();
Return the graph as ASCII art. Shortcut for $parser-as_graph->as_ascii()>.
$parser-
my $label = $parser->graph_label(); $parser->graph_label('/^foo|bar/');
Set or get the label of the graph.
Does not yet handle the new things like TRIE.
Graph::Easy, Graph::Flowchart
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.
Copyright (C) 2006-2008 by Tels http://bloodgate.com
To install Graph::Regexp, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Graph::Regexp
CPAN shell
perl -MCPAN -e shell install Graph::Regexp
For more information on module installation, please visit the detailed CPAN module installation guide.