--- trunk/lib/Frey/Class/Graph.pm 2009/01/09 18:09:17 971 +++ trunk/lib/Frey/Class/Graph.pm 2009/01/09 19:33:26 972 @@ -3,29 +3,90 @@ extends 'Frey'; with 'Frey::Web'; -#with 'Frey::Storage'; +with 'Frey::File'; +with 'Frey::Storage'; use GraphViz; -has skeleton => ( +has filter => ( + documentation => 'Regex to select classes', + is => 'rw', + isa => 'Str', + default => 'Frey', +); + +has path => ( is => 'rw', isa => 'Str', required => 1, - default => 'skeleton', + default => 'var/introspect/', +); + +has produce_dot => ( + is => 'rw', + isa => 'Bool', ); sub as_markup { my ($self) = @_; - my $g = GraphViz->new(); + my $g = GraphViz->new( + rankdir => 1, # horizontal +# layout => 'neato', # grabs too much memory +# layout => 'twopi', # grabs too much memory +# overlap => 'compress', +# no_overlap => 1, + ); + + our $count = {}; + my $filter = $self->filter; + + foreach my $path ( $self->dir_extension( $self->path, qr{\.(ya?ml)$}) ) { + + 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; + + sub count_label { + my ($self,$package) = @_; + my $label = $package; + $label .= $self->dump( $count->{$package} ); + return $label; + } - $g->add_node( 'foo' ); - $g->add_node( 'bar' ); + next if $filter && $class !~ m{$filter}; - $g->add_edge( 'foo' => 'bar' ); + if ( my $includes = $data->{includes} ) { + foreach my $type ( keys %$includes ) { + foreach my $package ( @{ $includes->{$type} } ) { + + my $usage = $count->{$package}->{$type}->{$class}++; + + my $label = $self->count_label($package); + + next if $filter && $package !~ m{$filter}; + + warn "# $class\t$type\t$package\n$label\n"; + + $g->add_edge( $class => $package, label => $type ); + } + } + } + + } + + warn "# count ",$self->dump( $count ); + + $self->store( 'var/classes.dot', $g->as_text ); + + if ( $self->produce_dot ) { + $self->content_type( 'text/plain' ); + return $g->as_canon; + } $self->content_type( 'image/png' ); return $g->as_png; + } 1;