/[Frey]/trunk/lib/Frey/Class/Graph.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/Class/Graph.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 974 - (show annotations)
Fri Jan 9 19:48:30 2009 UTC (15 years, 3 months ago) by dpavlin
File size: 1964 byte(s)
implement rules links, but it's too much clutter
1 package Frey::Class::Graph;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6 with 'Frey::File';
7 with 'Frey::Storage';
8
9 use GraphViz;
10
11 has filter => (
12 documentation => 'Regex to select classes',
13 is => 'rw',
14 isa => 'Str',
15 default => 'Frey',
16 );
17
18 has path => (
19 is => 'rw',
20 isa => 'Str',
21 required => 1,
22 default => 'var/introspect/',
23 );
24
25 has produce_dot => (
26 is => 'rw',
27 isa => 'Bool',
28 );
29
30 sub as_markup {
31 my ($self) = @_;
32
33 my $g = GraphViz->new(
34 rankdir => 1, # horizontal
35 # layout => 'neato', # grabs too much memory
36 # layout => 'twopi', # grabs too much memory
37 # overlap => 'compress',
38 # no_overlap => 1,
39 );
40
41 our $count = {};
42 my $filter = $self->filter;
43
44 foreach my $path ( $self->dir_extension( $self->path, qr{\.(ya?ml)$}) ) {
45
46 my $class = $self->strip_path_extension( $path ) || die "can't strip $path";
47 my $data = $self->load( $path );
48 # warn "## $class $path ", $self->dump( $data ); # if $self->debug;
49
50 sub count_label {
51 my ($self,$package) = @_;
52 my $label = $package;
53 $label .= $self->dump( $count->{$package} );
54 return $label;
55 }
56
57 next if $filter && $class !~ m{$filter};
58
59 if ( my $includes = $data->{includes} ) {
60 foreach my $type ( keys %$includes ) {
61 foreach my $package ( @{ $includes->{$type} } ) {
62
63 my $usage = $count->{$package}->{$type}->{$class}++;
64
65 my $label = $self->count_label($package);
66
67 next if $filter && $package !~ m{$filter};
68
69 warn "# $class\t$type\t$package\n$label\n";
70
71 $g->add_edge( $class => $package, label => $type );
72 }
73 }
74 }
75
76 =for later
77
78 foreach my $role ( keys %{ $data->{roles} } ) {
79 next if $filter && $role !~ m{$filter};
80 $g->add_edge( $role => $class, label => 'role' );
81 }
82
83 =cut
84
85 }
86
87 warn "# count ",$self->dump( $count );
88
89
90 if ( $self->produce_dot ) {
91 $self->content_type( 'text/plain' );
92 $self->store( 'var/classes.dot', $g->as_canon );
93 return $g->as_canon;
94 }
95
96 $self->content_type( 'image/png' );
97 return $g->as_png;
98
99 }
100
101 1;

  ViewVC Help
Powered by ViewVC 1.1.26