8 This is a visualization tool to help with
9 understanding large MI hierarchies. It will
10 output a DOT file for rendering with Graphviz.
13 This program is currently very primative, and
14 may break under some circumstances. If you
15 encounter one of those circumstances, please
16 email me about it so that I can improve this
20 In the graphs the green arrows are the ISA,
21 and the red arrows are the C3 dispatch order.
27 @ARGV || die "usage : visualize_c3.pl <class-to-visualize> | <file-to-load> <class-to-visualize> <file-to-output>";
30 if (scalar @ARGV == 1) {
33 die "Could not load '$class' :\n$@" if $@;
36 my $file = shift @ARGV;
40 die "Could not load '$file' :\n$@" if $@;
43 Class::C3->initialize();
45 my @MRO = Class::C3::calculateMRO($class);
49 (join "_" => (split '::' => $class));
52 my $output = "graph test {\n";
55 foreach my $class (@MRO) {
56 my $class_str = get_class_str($class);
57 $output .= "node_${class_str} [ label = \"" . $class . "\" ];\n";
60 foreach my $super (@{"${class}::ISA"}) {
61 $output .= "node_" . get_class_str($super) .
62 " -- node_${class_str}" .
63 " [ dir = back, color = green ];\n";
67 $output .= "node_${class_str} -- node_${prev} [ dir = back, color = red ];\n";
77 open OUT, ">", $OUT || die "could not open '$OUT' for output";