blib/lib/GraphViz/ISA.pm

filter: Statementstmt 85.7% 12 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 89.4% 17 / 19 CC 1 SCAR 0.6
CC
1
Cov
86%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package GraphViz::ISA;
6 our $VERSION = '1.100860';
7 # ABSTRACT: Graphing class hierarchies at run-time
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 0 ▶use GraphViz;
Subroutine BEGIN: called CC=1 SCAR=2.6
10 our $AUTOLOAD;
11  
12 sub new {
13 my $this = shift;
14 my $class = ref($this) || $this;
15 my $self = {};
16 bless $self, $class;
17 $self->_init(@_);
18 return $self;
19 }
20  
21 sub _init {
22 my ($self, $that) = @_;
23 my $pkg = ref($that) || $that;
24 $self->{g} = GraphViz->new();
25 my $tree = { $pkg => $self->isatree($pkg) };
26 $self->graph($tree);
27 }
28  
29 sub isatree {
30 my ($self, $pkg) = @_;
31 no strict 'refs';
32 my $isa = *{"$pkg\::ISA"}{ARRAY};
33 return {} unless @$isa;
34 my %out;
35 for my $base (@$isa) {
36 $out{$base} = $self->isatree($base);
37 }
38 return \%out;
39 }
40  
41 sub graph {
42 my ($self, $tree) = @_;
43 return unless keys %$tree;
44 for my $pkg (keys %$tree) {
45 $self->{g}->add_node($pkg);
46 $self->{g}->add_edge($_, $pkg) for keys %{ $tree->{$pkg} };
47 $self->graph($tree->{$pkg});
48 }
49 }
50  
51 sub AUTOLOAD {
52 my $self = shift;
53 my $type = ref($self) or croak "$self is not an object";
54 (my $name = $AUTOLOAD) =~ s/.*:://;
55 return if $name =~ /DESTROY/;
56  
57 # hm, maybe GraphViz knows what to do with it...
58 $self->{g}->$name(@_);
59 }
60 1;
61  
62  
63 __END__
↑ Summary