/[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 982 by dpavlin, Sat Jan 10 01:27:28 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  has path => (  
22    has filter_class => (
23          is => 'rw',          is => 'rw',
24          isa => 'Str',          isa => 'Bool',
25          required => 1,          default => 1,
26          default => 'var/introspect/',  );
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 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 portrait => (
73            documentation => 'vertical layout',
74            is => 'rw',
75            isa => 'Bool',
76  );  );
77    
78  has produce_dot => (  has produce_dot => (
79            documentation => 'dump .dot text format',
80          is => 'rw',          is => 'rw',
81          isa => 'Bool',          isa => 'Bool',
82  );  );
83    
84    sub introspect_path { 'var/introspect/' };
85    
86  sub as_markup {  sub as_markup {
87          my ($self) = @_;          my ($self) = @_;
88    
89            my $rankdir = $self->portrait;
90    
91          my $g = GraphViz->new(          my $g = GraphViz->new(
92                  rankdir => 1, # horizontal                  rankdir => $rankdir,
93  #               layout => 'neato', # grabs too much memory  #               layout => 'neato', # grabs too much memory
94  #               layout => 'twopi', # grabs too much memory  #               layout => 'twopi', # grabs too much memory
95  #               overlap => 'compress',  #               overlap => 'compress',
96  #               no_overlap => 1,  #               no_overlap => 1,
97    
98                    node => {
99                            shape => 'box',
100                            style =>'filled',
101                            color => 'grey',
102                            fillcolor =>'lightgray',
103                            fontname  => 'verdana',
104                            fontsize  => '12',
105    
106                    },
107                    edge => {
108                            color => 'grey',
109                            fontname  => 'verdana',
110                            fontsize  => '8',
111                            fontcolor => 'grey',
112                    }
113          );          );
114    
115          our $count = {};          my $count;
116          my $filter = $self->filter;          my $filter = $self->filter;
117    
118          foreach my $path ( $self->dir_extension( $self->path, qr{\.(ya?ml)$}) ) {          foreach my $path ( $self->dir_extension( $self->introspect_path, qr{\.(ya?ml)$}) ) {
119    
120                  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;  
121    
122                  sub count_label {                  $count->{$class}++ if $self->show_disconnected;
                         my ($self,$package) = @_;  
                         my $label = $package;  
                         $label .= $self->dump( $count->{$package} );  
                         return $label;  
                 }  
123    
124                  next if $filter && $class !~ m{$filter};                  my $data = $self->load( $path );
125    #               warn "## $class $path ", $self->dump( $data ); # if $self->debug;
                 if ( my $includes = $data->{includes} ) {  
                         foreach my $type ( keys %$includes ) {  
                                 foreach my $package ( @{ $includes->{$type} } ) {  
   
                                         my $usage = $count->{$package}->{$type}->{$class}++;  
126    
127                                          my $label = $self->count_label($package);                  next if $filter && $self->filter_class && $class !~ m{$filter};
128    
129                                          next if $filter && $package !~ m{$filter};                  if ( $self->show_includes && defined $data->{includes} ) {
130                            foreach my $type ( keys %{ $data->{includes} } ) {
131                                    foreach my $package ( @{ $data->{includes}->{$type} } ) {
132                                            next if $filter && $self->filter_includes && $package !~ m{$filter};
133                                            warn "# $class\t$type\t$package\n";
134                                            $g->add_edge( $class => $package, label => $type, color => 'blue' );
135                                            $count->{$class}++;
136                                            $count->{$package}++;
137                                    }
138                            }
139                    }
140    
141                                          warn "# $class\t$type\t$package\n$label\n";                  if ( $self->show_roles && defined $data->{roles} ) {
142                            foreach my $role ( keys %{ $data->{roles} } ) {
143                                    next if $filter && $self->filter_roles && $role !~ m{$filter};
144                                    warn "# $class\trole\t$role\n";
145                                    $g->add_edge( $role => $class, label => 'role', color => 'yellow' );
146    #                               $g->add_node( $role, rank => 'role' );
147                                    $count->{$class}++;
148                                    $count->{$role}++;
149                            }
150                    }
151    
152                                          $g->add_edge( $class => $package, label => $type );                  if ( $self->show_extends && defined $data->{superclass} ) {
153                                  }                          foreach my $extends ( keys %{ $data->{superclass} } ) {
154                                    next if $filter && $self->filter_extends && $extends !~ m{$filter};
155                                    warn "# $class\textends\t$extends\n";
156                                    $g->add_edge( $extends => $class, label => 'extends', color => 'green' );
157                                    $count->{$class}++;
158                                    $count->{$extends}++;
159                          }                          }
160                  }                  }
161    
# Line 77  sub as_markup { Line 163  sub as_markup {
163    
164          warn "# count ",$self->dump( $count );          warn "# count ",$self->dump( $count );
165    
166          $self->store( 'var/classes.dot', $g->as_text );          my $max_count = 1;
167            foreach ( keys %$count ) {
168                    my $v = $count->{$_};
169                    $max_count = $v if $v > $max_count;
170            }
171            warn "# max_count: $max_count";
172    
173            foreach my $node ( keys %$count ) {
174                    my $v = $count->{$node};
175                    my $pcnt = $v / $max_count;
176                    my $color = join(",", ( $pcnt, $pcnt, 0.75 ) );
177    
178                    $g->add_node( $node,
179                            style =>'filled',
180                            color => $color,
181                            fillcolor => $color,
182    #                       label => "$node\n$v",
183                    );
184    
185            }
186    
187          if ( $self->produce_dot ) {          if ( $self->produce_dot ) {
188                  $self->content_type( 'text/plain' );                  $self->content_type( 'text/plain' );
189                    $self->store( 'var/classes.dot', $g->as_canon );
190                  return $g->as_canon;                  return $g->as_canon;
191          }          }
192    

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

  ViewVC Help
Powered by ViewVC 1.1.26