/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 972 by dpavlin, Fri Jan 9 19:33:26 2009 UTC revision 1079 by dpavlin, Thu Jun 4 20:30:24 2009 UTC
# Line 12  has filter => ( Line 12  has filter => (
12          documentation => 'Regex to select classes',          documentation => 'Regex to select classes',
13          is => 'rw',          is => 'rw',
14          isa => 'Str',          isa => 'Str',
15          default => 'Frey',          required => 1,
16            default => sub {
17                    '(' . join('|',  map { s{lib/}{}; $_ } sort grep { -d $_ } glob("lib/*") ) . ')'
18            },
19    );
20    
21    
22    has filter_class => (
23            is => 'rw',
24            isa => 'Bool',
25            default => 1,
26    );
27    
28    has filter_extends => (
29            is => 'rw',
30            isa => 'Bool',
31            default => 1,
32    );
33    
34    has filter_includes => (
35            is => 'rw',
36            isa => 'Bool',
37            default => 1,
38  );  );
39    
40  has path => (  has filter_roles => (
41            is => 'rw',
42            isa => 'Bool',
43            default => 1,
44    );
45    
46    
47    has show_extends => (
48            documentation => 'connect to superclasses',
49            is => 'rw',
50            isa => 'Bool',
51    );
52    
53    has show_includes => (
54            documentation => 'use and require connections',
55            is => 'rw',
56            isa => 'Bool',
57            default => 1,
58    );
59    
60    has show_roles => (
61            documentation => 'roles consumers connections',
62            is => 'rw',
63            isa => 'Bool',
64    );
65    
66    has show_disconnected => (
67            is => 'ro',
68            isa => 'Bool',
69    );
70    
71    
72    has layout => (
73            documentation => 'layout algorithm',
74          is => 'rw',          is => 'rw',
75          isa => 'Str',          isa => 'Str',
76          required => 1,          required => 1,
77          default => 'var/introspect/',  );
78    
79    sub layout_available { q/
80    dot             directed graph
81    neato   spring model
82    twopi   radial
83    circo   circular
84    fdp             force directed spring model
85    / }
86    
87    has portrait => (
88            documentation => 'vertical layout',
89            is => 'rw',
90            isa => 'Bool',
91  );  );
92    
93  has produce_dot => (  has produce_dot => (
94            documentation => 'dump .dot text format',
95          is => 'rw',          is => 'rw',
96          isa => 'Bool',          isa => 'Bool',
97  );  );
98    
99    sub introspect_path { 'var/introspect/' };
100    
101  sub as_markup {  sub as_markup {
102          my ($self) = @_;          my ($self) = @_;
103    
104            my $rankdir = $self->portrait;
105    
106          my $g = GraphViz->new(          my $g = GraphViz->new(
107                  rankdir => 1, # horizontal                  rankdir => $rankdir,
108                    layout => $self->layout,
109  #               layout => 'neato', # grabs too much memory  #               layout => 'neato', # grabs too much memory
110  #               layout => 'twopi', # grabs too much memory  #               layout => 'twopi', # grabs too much memory
111  #               overlap => 'compress',  #               overlap => 'compress',
112  #               no_overlap => 1,                  no_overlap => 1,
113    
114                    node => {
115                            shape => 'box',
116                            style =>'filled',
117                            color => 'grey',
118                            fillcolor =>'lightgray',
119                            fontname  => 'verdana',
120                            fontsize  => '12',
121    
122                    },
123                    edge => {
124                            color => 'grey',
125                            fontname  => 'verdana',
126                            fontsize  => '8',
127                            fontcolor => 'grey',
128                    }
129          );          );
130    
131          our $count = {};          my $count;
132          my $filter = $self->filter;          my $filter = $self->filter;
133    
134          foreach my $path ( $self->dir_extension( $self->path, qr{\.(ya?ml)$}) ) {          foreach my $path ( $self->dir_extension( $self->introspect_path, qr{\.(ya?ml)$}) ) {
135    
136                  my $class = $self->strip_path_extension( $path ) || die "can't strip $path";                  my $class = $self->strip_path_extension( $path ) || die "can't strip $path";
                 my $data = $self->load( $path );  
 #               warn "## $class $path ", $self->dump( $data ); # if $self->debug;  
137    
138                  sub count_label {                  $count->{$class}++ if $self->show_disconnected;
                         my ($self,$package) = @_;  
                         my $label = $package;  
                         $label .= $self->dump( $count->{$package} );  
                         return $label;  
                 }  
   
                 next if $filter && $class !~ m{$filter};  
139    
140                  if ( my $includes = $data->{includes} ) {                  my $data = $self->load( $path );
141                          foreach my $type ( keys %$includes ) {  #               warn "## $class $path ", $self->dump( $data ); # if $self->debug;
                                 foreach my $package ( @{ $includes->{$type} } ) {  
   
                                         my $usage = $count->{$package}->{$type}->{$class}++;  
142    
143                                          my $label = $self->count_label($package);                  next if $filter && $self->filter_class && $class !~ m{$filter};
144    
145                                          next if $filter && $package !~ m{$filter};                  if ( $self->show_includes && defined $data->{includes} ) {
146                            foreach my $type ( keys %{ $data->{includes} } ) {
147                                    foreach my $package ( @{ $data->{includes}->{$type} } ) {
148                                            next if $filter && $self->filter_includes && $package !~ m{$filter};
149                                            warn "# $class\t$type\t$package\n";
150                                            $g->add_edge( $class => $package, label => $type, color => 'blue' );
151                                            $count->{$class}++;
152                                            $count->{$package}++;
153                                    }
154                            }
155                    }
156    
157                                          warn "# $class\t$type\t$package\n$label\n";                  if ( $self->show_roles && defined $data->{roles} ) {
158                            foreach my $role ( keys %{ $data->{roles} } ) {
159                                    next if $filter && $self->filter_roles && $role !~ m{$filter};
160                                    warn "# $class\trole\t$role\n";
161                                    $g->add_edge( $role => $class, label => 'role', color => 'yellow' );
162    #                               $g->add_node( $role, rank => 'role' );
163                                    $count->{$class}++;
164                                    $count->{$role}++;
165                            }
166                    }
167    
168                                          $g->add_edge( $class => $package, label => $type );                  if ( $self->show_extends && defined $data->{superclass} ) {
169                                  }                          foreach my $extends ( keys %{ $data->{superclass} } ) {
170                                    next if $filter && $self->filter_extends && $extends !~ m{$filter};
171                                    warn "# $class\textends\t$extends\n";
172                                    $g->add_edge( $extends => $class, label => 'extends', color => 'green' );
173                                    $count->{$class}++;
174                                    $count->{$extends}++;
175                          }                          }
176                  }                  }
177    
# Line 77  sub as_markup { Line 179  sub as_markup {
179    
180          warn "# count ",$self->dump( $count );          warn "# count ",$self->dump( $count );
181    
182          $self->store( 'var/classes.dot', $g->as_text );          my $max_count = 1;
183            foreach ( keys %$count ) {
184                    my $v = $count->{$_};
185                    $max_count = $v if $v > $max_count;
186            }
187            warn "# max_count: $max_count";
188    
189            foreach my $node ( keys %$count ) {
190                    my $v = $count->{$node};
191                    my $pcnt = $v / $max_count;
192                    my $color = join(",", ( $pcnt, $pcnt, 0.75 ) );
193    
194                    $g->add_node( $node,
195                            style =>'filled',
196                            color => $color,
197                            fillcolor => $color,
198    #                       label => "$node\n$v",
199                    );
200    
201            }
202    
203          if ( $self->produce_dot ) {          if ( $self->produce_dot ) {
204                  $self->content_type( 'text/plain' );                  $self->content_type( 'text/plain' );
205                    $self->store( 'var/classes.dot', $g->as_canon );
206                  return $g->as_canon;                  return $g->as_canon;
207          }          }
208    

Legend:
Removed from v.972  
changed lines
  Added in v.1079

  ViewVC Help
Powered by ViewVC 1.1.26