This is a really quick hack. I wanted to see which modules used which in my debugging session. This is exactly what Devel::TraceUse does.
I wanted to be able to see those relationship and be able to doodle on a piece of paper and stuff. So, here goes, thanks to GraphViz:
#!/usr/bin/env perl
use strict;
use warnings;
use GraphViz;
my $png = shift || 'use.png';
my $g = GraphViz->new( rankdir => 1 );
my @stack;
while (<>) {
# first node
/^Modules used from (.*):/ && do {
$g->add_node($1);
@stack = ($1);
};
# all other nodes
/^((?: )+)(\S+),/ && do {
my $idx = length($1) / 2;
$stack[$idx] = $2;
$g->add_node($2);
$g->add_edge( $stack[ $idx - 1 ] => $2 );
};
# ignore all other lines
}
$g->as_png($png);
Re: Graphing module usage (Score:1)
I had done something like that for inheritance graphs (I know, nothing new).
What do you feed this script with?
simple format (Score:1)
#!/usr/bin/env perl
$png = shift || 'use.png';
open O, "| dot -Tpng > $png" or die $!;
print O "digraph g {\n";
while (<>) {
if (/^Modules used from (.*):/) {
@stack = ($1);
} elsif (/^((?: )+)(\S+),/) {
$idx = length($1) / 2;
$stack[$idx] = $2;
print O qq{"$stack[$idx-1] -> $2;\n"};
}
}
pri