Browse files

output graph in PNG format and store file

  • Loading branch information...
1 parent b18dc40 commit 6aa2db975ad5bf729f1b7f30b16b626f0b328d63 franck cuny committed Jul 13, 2009
Showing with 17 additions and 13 deletions.
  1. +3 −0 cpanhq.conf
  2. +13 −7 lib/CPANHQ/Controller/Distribution.pm
  3. +1 −6 root/dist/show.tt
View
3 cpanhq.conf
@@ -3,3 +3,6 @@ name CPANHQ
connect_info dbi:SQLite:dbname=__HOME__/cpanhq.db
connect_info undef
</Model::DB>
+<Controller::Distribution>
+ graph_path __HOME__/root/dist/graph/
+</Controller::Distribution>
View
20 lib/CPANHQ/Controller/Distribution.pm
@@ -50,23 +50,29 @@ sub show : Chained(instance) : PathPart('') : Args(0) {
my $latest = $dist->latest_release;
$latest->_process_meta_yml();
- my $graph = Graph::Easy->new();
+ my $graph = Graph::Easy->new();
+ my $graph_output = File::Spec->catfile(
+ $c->config->{'Controller::Distribution'}->{graph_path},
+ $dist->name . '-' . $latest->version . '.png'
+ );
my $uses = $dist->uses;
my $dist_uses;
while ( my $use = $uses->next ) {
my $name = $use->dist_to->name;
push @$dist_uses, $name;
- $graph->add_edge(
- $latest->distribution->name,
- $name,
- );
+ $graph->add_edge( $latest->distribution->name, $name, );
+ }
+
+ if ( !-f $graph_output ) {
+ if ( open( my $png, '|-', 'dot -Tpng -o ' . $graph_output ) ) {
+ print $png $graph->as_graphviz;
+ close($png);
+ }
}
- my $graph_output = $graph->as_ascii();
$c->stash(
release => $latest,
title => $latest->name,
- graph => $graph_output,
uses => $dist_uses,
);
}
View
7 root/dist/show.tt
@@ -31,13 +31,8 @@
[% author = release.author %]
<p>By <a href="[% c.uri_for( '/author', author.cpanid ) %]">[% author.name %]</a>, released on [% release.release_date.ymd %]</p>
-[% IF graph %]
<h3 id="graph">Graph</h3>
-<pre>
-[% graph %]
-</pre>
-
-[% END %]
+<img src="/dist/graph/[% dist.name %].png" />
<h3 id="packages">Packages</h3>
<ul>

0 comments on commit 6aa2db9

Please sign in to comment.