Created
February 10, 2009 23:24
-
-
Save kzys/61684 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
use strict; | |
use warnings; | |
use Class::Sniff; | |
sub package_of { | |
my ($path) = @_; | |
if ($path !~ m|/?lib/(.*)\.pm$|) { | |
die; | |
} | |
my $result = $1; | |
$result =~ s|/|::|g; | |
return $result; | |
} | |
sub new_methods { | |
my ($sniffer) = @_; | |
my %count_of; | |
for my $method ($sniffer->methods) { | |
$count_of{$method}++; | |
} | |
my $klass = $sniffer->target_class; | |
for my $method (keys %{ $sniffer->exported->{ $klass } }) { | |
$count_of{$method}--; | |
} | |
grep { $_ } map { | |
my $method = $_; | |
($count_of{$method} > 0)? $method : undef; | |
} (keys %count_of); | |
} | |
my @sniffs = map { | |
my $package = package_of($_); | |
eval "use $package"; | |
Class::Sniff->new({ class => $package }); | |
} @ARGV; | |
my $labels = join "\n", map { | |
my @methods = new_methods($_); | |
my $label = '{\N\n|' . join('\l', sort @methods) . '\l}'; | |
$label =~ s/"/\\"/g; | |
sprintf('"%s" [label="%s"]', $_->target_class, $label); | |
} @sniffs; | |
my $sniff = pop @sniffs; | |
my $graphviz = $sniff->combine_graphs(@sniffs)->as_graphviz; | |
# it's dirty... | |
$graphviz =~ s/}/$labels }/g; | |
$graphviz =~ s/shape=box/shape=record/g; | |
print $graphviz; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment