Skip to content

Commit

Permalink
clean up redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Aug 7, 2017
1 parent 4e85bf9 commit d5320ff
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
5 changes: 3 additions & 2 deletions lib/MetaCPAN/Web/Controller/Module.pm
Expand Up @@ -19,12 +19,13 @@ sub redirect_to_pod : Path : Args {

# Force the author arg to uppercase to avoid another redirect.
$c->res->redirect(
'/pod/release/' . join( q{/}, uc( shift @path ), @path ), 301 );
$c->uri_for( '/pod/release', uc( shift @path ), @path),
301, );
}

# /module/Foo::Bar
else {
$c->res->redirect( '/pod/' . join( q{/}, @path ), 301 );
$c->res->redirect( $c->uri_for( '/pod', @path ), 301, );
}

$c->detach();
Expand Down
20 changes: 12 additions & 8 deletions lib/MetaCPAN/Web/Controller/Pod.pm
Expand Up @@ -36,20 +36,24 @@ sub find : Path : Args(1) {

# /pod/release/$AUTHOR/$release/@path
sub release : Local : Args {
my ( $self, $c, @path ) = @_;
my ( $self, $c, $author, $release, @path ) = @_;

if (!@path) {
$c->detach('/not_found');
}
$c->browser_max_age('1d');

# force consistent casing in URLs
if ( @path > 2 && $path[0] ne uc( $path[0] ) ) {
if ( $author ne uc $author ) {
$c->res->redirect(
'/pod/release/' . join( q{/}, uc( shift @path ), @path ), 301 );
$c->uri_for( $c->action, uc $author, $release, @path ),
301 );
$c->detach();
}

my $release_data = $c->model('ReleaseInfo')->get( @path[ 0, 1 ] )
->else( sub { Future->done( {} ) } );
my $pod_file = $c->model('API::Module')->get(@path);
my $release_data = $c->model('ReleaseInfo')->get( $author, $release )
->else_done({});
my $pod_file = $c->model('API::Module')->get( $author, $release, @path );
$c->stash(
{
pod_file => $pod_file->get,
Expand All @@ -58,7 +62,7 @@ sub release : Local : Args {
}
);

$c->forward( 'view', [@path] );
$c->forward( 'view', [ $author, $release, @path ] );
}

# /pod/distribution/$name/@path
Expand Down Expand Up @@ -95,7 +99,7 @@ sub view : Private {
my $permalinks = $c->stash->{permalinks};

if ( $data->{directory} ) {
$c->res->redirect( '/source/' . join( q{/}, @path ), 301 );
$c->res->redirect( $c->uri_for( '/source', @path ), 301 );
$c->detach;
}

Expand Down
8 changes: 2 additions & 6 deletions lib/MetaCPAN/Web/Controller/Release.pm
Expand Up @@ -36,12 +36,8 @@ sub by_author_and_release : Chained('root') PathPart('') Args(2) {
# force consistent casing in URLs
if ( $author ne uc($author) ) {
$c->res->redirect(
$c->uri_for_action(
$c->controller->action_for('by_author_and_release'),
[ uc($author), $release ]
),
301
);
$c->uri_for_action( $c->action, uc($author), $release ),
301, );
$c->detach();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/MetaCPAN/Web/Controller/Search.pm
Expand Up @@ -47,19 +47,19 @@ sub index : Path : Args(0) {
my $module = $model->first($query)->get;
$module = $module->[0] if $module and is_arrayref($module);
if ( $module && $module eq $query ) {
$c->res->redirect( '/pod/' . $module );
$c->res->redirect( $c->uri_for('/pod', $module));
$c->detach;
}
else {
my $author = $c->model('API::Author')->search($query)->get;
if ( $author->{total} == 1
&& $query eq $author->{authors}->[0]->{pauseid} )
{
$c->res->redirect( '/author/' . uc($query) );
$c->res->redirect( $c->uri_for('/author', uc($query)) );
$c->detach;
}
elsif ($module) {
$c->res->redirect("/pod/$module");
$c->res->redirect( $c->uri_for('/pod', $module) );
$c->detach;
}
else {
Expand Down

0 comments on commit d5320ff

Please sign in to comment.