Last active
August 29, 2015 14:03
-
-
Save tokubass/2dc55f41cc278c18c911 to your computer and use it in GitHub Desktop.
PPIで特定ディレクトリ内だけの継承関係グラフ化(依存モジュールエラーは嫌だ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use PPI; | |
use File::PackageIndexer; | |
use IO::All; | |
use Graph::Easy; | |
use Encode; | |
my $dir = shift; | |
my $isa_relationship = {}; | |
my $indexer = File::PackageIndexer->new; | |
for my $io_file (io($dir)->deep->all_files) { | |
my $Document = PPI::Document->new($io_file->name); | |
my $pkgs = $indexer->parse($Document); | |
for my $pkg (keys %$pkgs) { | |
$pkgs->{$pkg} = $pkgs->{$pkg}->{isa}; | |
} | |
$isa_relationship = { %$pkgs, %$isa_relationship }; | |
} | |
my $graph = Graph::Easy->new; | |
for my $child_pkg (keys %$isa_relationship) { | |
if ( my @parent_pkgs = @{$isa_relationship->{$child_pkg}} ) { | |
for my $parent_pkg (@parent_pkgs) { | |
$graph->add_edge($child_pkg,$parent_pkg); | |
unless ($isa_relationship->{$parent_pkg}) { | |
set_color_attr_of_node($graph->node($parent_pkg), 'yellow'); | |
} | |
} | |
}else{ | |
set_color_attr_of_node($graph->node($child_pkg), 'red'); | |
} | |
} | |
sub set_color_attr_of_node { | |
my ($node, $color) = @_; | |
return unless $node; | |
$node->set_attribute('fill', $color); | |
} | |
print encode_utf8($graph->as_html_file); | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment