Permalink
Browse files

Merge branch 'master' of git@github.com:bricas/cpanhq

  • Loading branch information...
2 parents 7d39244 + b18dc40 commit 3be39cb2d3e41b51652c450aa8593aab5eb9c481 @shlomif shlomif committed Jul 17, 2009
View
@@ -21,6 +21,7 @@ requires 'DBIx::Class';
requires 'DBIx::Class::TimeStamp';
requires 'File::Spec';
requires 'File::Temp';
+requries 'Graph::Easy';
requires 'List::Util';
requires 'LWPx::ParanoidAgent';
requires 'Net::OpenID::Consumer';
@@ -4,6 +4,7 @@ use strict;
use warnings;
use parent 'Catalyst::Controller';
+use Graph::Easy;
__PACKAGE__->config->{namespace} = 'dist';
@@ -43,12 +44,31 @@ The L<Catalyst> show method.
=cut
-sub show :Chained(instance) :PathPart('') :Args(0) {
- my( $self, $c ) = @_;
- my $dist = $c->stash->{ dist };
+sub show : Chained(instance) : PathPart('') : Args(0) {
+ my ( $self, $c ) = @_;
+ my $dist = $c->stash->{dist};
my $latest = $dist->latest_release;
$latest->_process_meta_yml();
- $c->stash( release => $latest, title => $latest->name );
+
+ my $graph = Graph::Easy->new();
+
+ 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,
+ );
+ }
+ my $graph_output = $graph->as_ascii();
+ $c->stash(
+ release => $latest,
+ title => $latest->name,
+ graph => $graph_output,
+ uses => $dist_uses,
+ );
}
=head2 $self->version($c, $version)
@@ -67,6 +67,14 @@ __PACKAGE__->has_many(
packages => 'CPANHQ::Storage::Package',
'distribution_id'
);
+__PACKAGE__->has_many(
+ uses => 'CPANHQ::Storage::Requires',
+ 'dist_from'
+);
+__PACKAGE__->has_many(
+ used_by => 'CPANHQ::Storage::Requires',
+ 'dist_to'
+);
=head2 $self->latest_release()
@@ -5,7 +5,7 @@ use warnings;
=head1 NAME
-CPANHQ::Storage::Keyword - a class representing a CPAN license
+CPANHQ::Storage::Keyword - a class representing a CPAN keyword
=head1 SYNOPSIS
@@ -130,6 +130,7 @@ __PACKAGE__->belongs_to( author => 'CPANHQ::Storage::Author', 'author_id' );
__PACKAGE__->belongs_to( license => 'CPANHQ::Storage::License', 'license_id' );
__PACKAGE__->add_unique_constraint( [ qw( distribution_id version ) ] );
+
=head2 $release->name()
Returns the distribution name and version.
@@ -264,6 +265,18 @@ sub _process_meta_yml {
}
}
+ if ( defined( my $deps = $meta_yml->{'requires'} ) ) {
+ foreach my $dep_name (keys %$deps) {
+ $dep_name =~ s/::/-/g;
+ my $dep =
+ $self->result_source->schema->resultset('Distribution')
+ ->find( { name => $dep_name } );
+ next unless $dep;
+ $self->result_source->schema->resultset('Requires')
+ ->new( { dist_from => $self->distribution->id, dist_to => $dep->id, } )
+ ->insert;
+ }
+ }
$self->update();
return;
@@ -0,0 +1,69 @@
+package CPANHQ::Storage::Requires;
+
+use strict;
+use warnings;
+
+use base qw( DBIx::Class );
+
+=head1 NAME
+
+CPANHQ::Storage::Requires - a class representing a CPAN dependencies
+
+=head1 SYNOPSIS
+
+ my $schema = CPANHQ->model("DB");
+
+ my $keywords_rs = $schema->resultset('Requires');
+
+ my $keyword = $keywords_rs->find({
+ dist_from => 1234,
+ });
+
+ print $keyword->dist_to->name();
+
+=head1 DESCRIPTION
+
+This is the requires schema class for L<CPANHQ>.
+
+=head1 METHODS
+
+=cut
+__PACKAGE__->load_components( qw( Core ) );
+__PACKAGE__->table( 'requires' );
+
+__PACKAGE__->add_columns(
+ id => {
+ data_type => 'bigint',
+ is_auto_increment => 1,
+ is_nullable => 0,
+ },
+ dist_from => {
+ data_type => 'bigint',
+ is_nullable => 0,
+ },
+ dist_to => {
+ data_type => 'bigint',
+ is_nullable => 0,
+ },
+);
+
+__PACKAGE__->set_primary_key( 'id' );
+__PACKAGE__->belongs_to( dist_from => 'CPANHQ::Storage::Distribution' );
+__PACKAGE__->belongs_to( dist_to => 'CPANHQ::Storage::Distribution' );
+
+=head1 SEE ALSO
+
+L<CPANHQ::Storage>, L<CPANHQ>, L<DBIx::Class>
+
+=head1 AUTHOR
+
+Franck Cuny E<lt>franck@lumberjaph.netE<gt>
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
View
@@ -6,7 +6,8 @@
<b>Abstract:</b> [% HTML.escape(release.abstract) %]
</li>
<li>
-<a href="[% HTML.escape(release.homepage) %]" rel="nofollow"><b>Homepage</b></a>
+<a href="[% HTML.escape(release.homepage) %]" rel="nofollow"><b>Homepage</b></a>,
+<a href="http://wiki.catalyzed.org/cpan-modules/[% release.distribution.name %]" rel="nofollow"><b>Wiki</b></a>
</li>
<li>
<b>License:</b>
@@ -20,25 +21,38 @@
</li>
<li>
<b>Tags:</b>
-[% # TODO : Get rid of the last trailing comma ",".
- # TODO : make it more DBIx-Class-y.
-%]
[% FOREACH tag_proto = release.distribution.author_keywords %]
[%- tag = tag_proto.keyword.string_id -%]
-<a href="[% HTML.escape(c.uri_for('/tag', tag)) %]">[% HTML.escape(tag) %]</a>,
+<a href="[% HTML.escape(c.uri_for('/tag', tag)) %]">[% HTML.escape(tag) %]</a>[% UNLESS loop.last %], [% END %]
[% END %]
</li>
</ul>
[% author = release.author %]
<p>By <a href="[% c.uri_for( '/author', author.cpanid ) %]">[% author.name %]</a>, released on [% release.release_date.ymd %]</p>
-<h3 id="packages">Packages</h3>
+[% IF graph %]
+<h3 id="graph">Graph</h3>
+<pre>
+[% graph %]
+</pre>
+
+[% END %]
+<h3 id="packages">Packages</h3>
<ul>
[% FOREACH pack = release.distribution.packages %]
<li>
<a href="[% c.uri_for( '/package', pack.name) %]">[% HTML.escape(pack.name) %]</a>
</li>
[% END %]
</ul>
+
+<h3 id="dependencies">Dependencies</h3>
+<ul>
+[% FOREACH dep = uses %]
+<li>
+<a href="[% c.uri_for( '/dist', dep) %]">[% HTML.escape(dep) %]</a>
+</li>
+[% END %]
+</ul>

0 comments on commit 3be39cb

Please sign in to comment.