# Original code: "Prettified Perl Inheritance" by Kageneko use strict; use warnings; no strict 'refs'; use GraphViz; my $module = 'Net::FTP'; my $output_jpg_file_name = 'isa'; my %already_loaded = (); # write $output_jpg_file_name.jpg to file my $g = GraphViz->new; ScanModule($g, undef, $module, 0); $g->as_jpeg("$output_jpg_file_name.jpg"); sub ScanModule { my $g = shift; my $parent = shift; my $module = shift; my $depth = shift; my @total = @_; my $loaded = 0; my $label; $loaded = 1 if (exists $already_loaded{$module}); eval "use $module" if (!defined $parent); $g->add_edge($parent => $module) if $depth > 0; $label = $module; unless ($loaded) { my $version = $module->VERSION(); $label .= " (v$version)" if $version; $g->add_node($module, label => $label); my $isa = "${module}::ISA"; my $count = 1; my $total = @$isa; foreach (@$isa) { ScanModule($g, $module, $_, $depth + 1, @total, $count, $total); $count++; } $already_loaded{$module} = $parent; } }