Skip to content

Commit

Permalink
Improve in-dist links for non-indexed modules
Browse files Browse the repository at this point in the history
For unindexed files like scripts, or unauthorized modules, use better
link forms even when permalinks haven't been requested.
  • Loading branch information
haarg committed Sep 14, 2015
1 parent f652397 commit db3fa81
Showing 1 changed file with 57 additions and 46 deletions.
103 changes: 57 additions & 46 deletions lib/MetaCPAN/Server/Controller/Source.pm
Expand Up @@ -32,57 +32,68 @@ sub get : Chained('index') : PathPart('') : Args {
$c->res->body( $res->[2]->[0] );
}
else {
if ( $c->req->query_params->{permalinks} ) {
my $links = {};
my $modules = $c->model('CPAN::File')->raw->filter(
{
and => [
{ term => { release => $release } },
{ term => { author => $author } },
{
or => [
{
and => [
{
exists => {
field => 'file.module.name',
}
},
{
term => {
'file.module.indexed' => \1
}
},
]
},
{
and => [
{
exists => {
field => 'file.pod.analyzed',
}
},
{ term => { 'file.indexed' => \1 } },
]
},
]
},
],
}
)->fields( [qw( module path documentation )] )->size(5000)
->all->{hits}->{hits};
for my $file ( map { $_->{fields} } @$modules ) {
my $name = $file->{documentation} or next;
my ($module)
= grep { $_->{name} eq $name } @{ $file->{module} };
my $link
my $permalinks = $c->req->query_params->{permalinks};
my $links = {};
my $modules = $c->model('CPAN::File')->raw->filter(
{
and => [
{ term => { release => $release } },
{ term => { author => $author } },
{
or => [
{
and => [
{
exists => {
field => 'file.module.name',
}
},
{
term => {
'file.module.indexed' => \1
}
},
]
},
{
and => [
{
exists => {
field => 'file.pod.analyzed',
}
},
{ term => { 'file.indexed' => \1 } },
]
},
]
},
],
}
)->fields( [qw( module path documentation distribution )] )
->size(5000)->all->{hits}->{hits};
for my $file ( map { $_->{fields} } @$modules ) {
my $name = $file->{documentation} or next;
my ($module)
= grep { $_->{name} eq $name } @{ $file->{module} };

if ($permalinks) {
$links->{$name}
= 'release/'
. ( ( $module && $module->{associated_pod} )
|| "$author/$release/$file->{path}" );
$links->{$name} = $link;
}
$c->stash->{link_mappings} = $links;
elsif ( !$module ) {
$links->{$name}
= "distribution/$file->{distribution}/$file->{path}";
}
elsif ( !$module->{authorized} || !$module->{indexed} ) {
$links->{$name}
= 'release/'
. ( $module->{associated_pod}
|| "$author/$release/$file->{path}" );
}
}
$c->stash->{link_mappings} = $links;

$c->stash->{path} = $file;

Expand Down

0 comments on commit db3fa81

Please sign in to comment.