Skip to content

Commit 7645f44

Browse files
committed
Feature request: What depends on this?, fixes metacpan#111
1 parent 47b6469 commit 7645f44

File tree

10 files changed

+95
-8
lines changed

10 files changed

+95
-8
lines changed

lib/MetaCPAN/Web/Controller/Activity.pm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ sub index : Path {
1818
if ( my $distribution = $req->parameters->{distribution} ) {
1919
push( @$q, { term => { distribution => $distribution } } );
2020
}
21+
if ( my $requires = $req->parameters->{requires} ) {
22+
push( @$q, { term => { "release.dependency.module" => $requires } } );
23+
}
2124

2225
my $cv = AE::cv;
2326
my $start
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package MetaCPAN::Web::Controller::Requires;
2+
3+
use Moose;
4+
use namespace::autoclean;
5+
6+
BEGIN { extends 'MetaCPAN::Web::Controller' }
7+
8+
sub index : Chained('/') : PathPart('requires') : CaptureArgs(0) {
9+
}
10+
11+
sub module : Chained('index') : PathPart : Args(1) {
12+
my ( $self, $c, $module ) = @_;
13+
my $cv = AE::cv;
14+
my $data = $c->model('API::Module')->requires($module, $c->req->page)->recv;
15+
$c->stash({%{$data}, module => $module, template => 'requires.html'});
16+
}
17+
18+
1;

lib/MetaCPAN/Web/Model/API/Module.pm

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ sub search_distribution {
135135
my @ids = map { $_->{fields}->{id} } @{ $data->{hits}->{hits} };
136136
my $descriptions = $self->search_descriptions(@ids);
137137
my $ratings = $self->model('Rating')->get(@distributions);
138-
my $favorites = $self->model('Favorite')->get($user, @distributions);
138+
my $favorites
139+
= $self->model('Favorite')->get( $user, @distributions );
139140
return $ratings & $favorites & $descriptions;
140141
}
141142
)->(
@@ -190,8 +191,9 @@ sub search_collapsed {
190191
}
191192

192193
@distributions = splice( @distributions, $from, 20 );
193-
my $ratings = $self->model('Rating')->get(@distributions);
194-
my $favorites = $self->model('Favorite')->get($user, @distributions);
194+
my $ratings = $self->model('Rating')->get(@distributions);
195+
my $favorites
196+
= $self->model('Favorite')->get( $user, @distributions );
195197
my $results
196198
= $self->model('Module')
197199
->search( $query,
@@ -461,6 +463,43 @@ sub _search_in_distributions {
461463
}
462464
} };
463465
}
464-
__PACKAGE__->meta->make_immutable;
465466

466-
1;
467+
sub requires {
468+
my ( $self, $module, $page ) = @_;
469+
my $cv = $self->cv;
470+
$self->request(
471+
'/release/_search',
472+
{ query => {
473+
filtered => {
474+
query => { "match_all" => {} },
475+
filter => {
476+
and => [
477+
{ term => { 'release.status' => 'latest' } },
478+
{ term => { 'release.authorized' => \1 } },
479+
{ term => {
480+
"release.dependency.module" => $module
481+
}
482+
}
483+
]
484+
}
485+
}
486+
},
487+
size => 50,
488+
from => $page * 50 - 50,
489+
sort => [{date => 'desc'}],
490+
}
491+
)->(
492+
sub {
493+
my $data = shift->recv;
494+
$cv->send(
495+
{ data => [map { $_->{_source} } @{$data->{hits}->{hits}}],
496+
total => $data->{hits}->{total},
497+
took => $data->{took}
498+
}
499+
);
500+
}
501+
);
502+
return $cv;
503+
}
504+
505+
__PACKAGE__->meta->make_immutable;

root/author.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@
7878
</div>
7979

8080
<div class="content">
81-
<% INCLUDE inc/release-table.html releases = aggregated, header = 1 %>
81+
<% INCLUDE inc/release-table.html releases = aggregated, header = 1, tablesorter = 1 %>
8282
</div>

root/inc/release-table.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<table class="release-table author-table tablesorter">
1+
<table class="release-table author-table<% IF tablesorter %> tablesorter<% END %>">
22
<%- IF header %>
33
<thead>
44
<tr>

root/module.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<input type="text" name="q">
3939
<input type="submit" style="display: none"></form></li>
4040
<li><a href="#" onclick="return toggleTOC()">Toggle Table of Contents</a></li>
41+
<li><a href="/requires/module/<% module.distribution.replace('-', '::') %>">Dependants</a></li>
4142
<li><a href="http://explorer.metacpan.org/?url=/module/<% module.author %>/<% module.release %>/<% module.path %>">MetaCPAN Explorer</a></li>
4243
</ul>
4344
<hr>

root/release.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<input type="hidden" name="q" value="distribution:<% release.distribution %>">
2929
<input type="text" name="q">
3030
<input type="submit" style="display: none"></form></li>
31+
<li><a href="/requires/module/<% release.distribution.replace('-', '::') %>">Dependants</a></li>
3132
<li><a href="http://explorer.metacpan.org/?url=/release/<% release.author %>/<% release.name %>">MetaCPAN Explorer</a></li>
3233
</ul>
3334
<hr>

root/requires.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<%- title = "Distributions depending on " _ module %>
2+
<div class="search-bar">
3+
<% INCLUDE inc/activity.html query = "requires=" _ module %>
4+
<hr>
5+
<strong>Index</strong>
6+
<ul>
7+
<a href=""><li>Latest</li></a>
8+
<a href=""><li>CPAN</li></a>
9+
<a href=""><li>BackPAN</li></a>
10+
</ul>
11+
</div>
12+
13+
<div class="content">
14+
<% IF data.size > 0 %>
15+
<% INCLUDE inc/release-table.html releases = data, header = 1 %>
16+
<% INCLUDE inc/pager.html size = 50 %>
17+
<% ELSE %>
18+
<big><strong>No depedants for <% module %> could be found</strong></big>
19+
<% END %>
20+
</div>

root/static/css/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,11 @@ div.qtip-github table th {
643643
padding: 2px;
644644
}
645645

646+
.release-table th {
647+
text-align: left;
648+
font-weight: bold;
649+
}
650+
646651
.release-table .name {
647652
width: 266px;
648653
}

root/static/js/cpan.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ $(document).ready(function() {
7474
$('#signin-button').mouseenter(function(){$('#signin').show()});
7575
$('#signin').mouseleave(function(){$('#signin').hide()});
7676

77-
$('.author-table').tablesorter({widgets: ['zebra'],textExtraction: function(node){
77+
$('.tablesorter').tablesorter({widgets: ['zebra'],textExtraction: function(node){
7878
if(node.getAttribute('class') == 'date') {
7979
var date = new Date(node.firstChild.getAttribute('sort'));
8080
return date.getTime();

0 commit comments

Comments
 (0)