NAME

Devel::Graph - Turn Perl code into a Graph::Flowchart object

SYNOPSIS

use Devel::Graph;

my $graph = Devel::Graph->graph( \'$a = 9 if $b == 1' );

print $graph->as_ascii();

DESCRIPTION

This module decomposes Perl code into blocks and generates a Graph::Flowchart object out of these. The resulting object represents the code in a flowchart manner and it can return you a Graph::Easy object.

This in turn can be converted it into all output formats currently supported by Graph::Easy, namely HTML, SVG, ASCII text etc.

Parsing

The parsing is done by PPI, so everything that is supported properly by PPI should work.

Note: Not all Perl constructs are implemented yet, especially loops, and more strange features like <$a = 9 if $b == 9> (no () around the condition) are buggy and/or incomplete.

Customizing the flowchart

Per default, the flowchart will have certain properties, like bold start/end blocks, diamond-shaped if-blocks and so on. You can change these by setting class attributes on the returned graph object:

use Devel::Graph;
my $g = Devel::Graph->graph( '$a = 9 if $b == 1' );

$g->set_attribute('node.if', 'fill', 'red');    # if blocks: red
$g->set_attribute('node.for', 'fill', 'blue');  # for blocks: blue
$g->set_attribute('edge.true', 'style', 'bold');# true edges: bold
print $g->as_html_file();

Subclasses for node include if, for, start, end, continue etc. For a list of all possible classes see Graph::Flowchart, and for a list of all possible attributes and their values, see Graph::Easy.

EXPORT

Exports nothing.

METHODS

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

graph()

my $graph = Devel::Graph->graph( \$code );
my $graph = Devel::Graph->graph( $filename );

Takes Perl code in $code (as string or code ref) and returns a flowchart as Graph::Easy object.

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

my $flow = Devel::Graph->new();
$flow->decompose( $code );
$flow->finish( $code );
my $graph = $grapher->as_graph();

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

new()

my $flow = Devel::Graph->new();

Creates a new Devel::Graph object.

decompose()

$flow->decompose( \$code );		# \'$a = 1;'
$flow->decompose( $filename );		# 'lib/Package.pm'

Takes Perl code (code ref in $code) or Perl file (filename in $code) and decomposes it into blocks and updates the internal structures with a flowchart representing this code.

If called more than one time, the code will be added to the flowchart. To get a new, empty flowchart, use reset().

finish()

$flow->finish();

Finish the flowchart by attaching an end node to the current node.

reset()

$flow->reset();

Reset the internal state of the object, so that decompose() will create a new flowchart.

as_graph()

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

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

as_ascii()

print $flow->as_ascii();

Return the flow chart as ASCII art. Shortcut for $grapher-as_graph->as_ascii()>.

as_flowchart()

my $chart = $flow->as_flowchart();

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

SEE ALSO

Graph::Easy, Graph::Flowchart, PPI.

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. See the LICENSE file for information.

AUTHOR

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