Skip to content

Commit

Permalink
Merge pull request #1685 from CPAN-API/topic/dispatch-cleanup
Browse files Browse the repository at this point in the history
clean up dispatch actions
  • Loading branch information
oalders committed May 4, 2016
2 parents fa4ca23 + 785af15 commit 4ad4eb9
Show file tree
Hide file tree
Showing 30 changed files with 69 additions and 106 deletions.
26 changes: 16 additions & 10 deletions lib/MetaCPAN/Web/Controller/About.pm
Expand Up @@ -15,47 +15,53 @@ sub auto : Private {

}

sub about : Local : Path('/about') {
sub about : Path : Args(0) {
my ( $self, $c ) = @_;
$c->stash( template => 'about.html' );
}

sub contributors : Local {
sub contributors : Local : Args(0) {
my ( $self, $c ) = @_;
$c->stash( template => 'about/contributors.html' );
}

sub resources : Local {
sub contact : Local : Args(0) {
my ( $self, $c ) = @_;
$c->stash( template => 'about/resources.html' );
$c->stash( template => 'about/contact.html' );
}

sub sponsors : Local {
sub resources : Local : Args(0) {
my ( $self, $c ) = @_;
$c->res->redirect( '/about/contact', 301 );
$c->detach;
}

sub sponsors : Local : Args(0) {
my ( $self, $c ) = @_;
$c->stash( template => 'about/sponsors.html' );
}

sub development : Local {
sub development : Local : Args(0) {
my ( $self, $c ) = @_;
$c->stash( template => 'about/development.html' );
}

sub missing_modules : Local {
sub missing_modules : Local : Args(0) {
my ( $self, $c ) = @_;
$c->stash( template => 'about/missing_modules.html' );
}

sub faq : Local {
sub faq : Local : Args(0) {
my ( $self, $c ) = @_;
$c->stash( template => 'about/faq.html' );
}

sub metadata : Local {
sub metadata : Local : Args(0) {
my ( $self, $c ) = @_;
$c->stash( template => 'about/metadata.html' );
}

sub stats : Local {
sub stats : Local : Args(0) {
my ( $self, $c ) = @_;

$c->add_surrogate_key('stats');
Expand Down
8 changes: 4 additions & 4 deletions lib/MetaCPAN/Web/Controller/Account.pm
Expand Up @@ -20,18 +20,18 @@ sub auto : Private {
return $c->user_exists;
}

sub logout : Local {
sub logout : Local : Args(0) {
my ( $self, $c ) = @_;
$c->detach('/forbidden') unless ( $c->req->method eq 'POST' );
$c->req->session->expire;
$c->res->redirect(q{/});
}

sub settings : Local {
sub settings : Local : Args(0) {
my ( $self, $c ) = @_;
}

sub identities : Local {
sub identities : Local : Args(0) {
my ( $self, $c ) = @_;
if ( $c->req->method eq 'POST'
&& ( my $delete = $c->req->params->{delete} ) )
Expand All @@ -41,7 +41,7 @@ sub identities : Local {
}
}

sub profile : Local {
sub profile : Local : Args(0) {
my ( $self, $c ) = @_;
my $author = $c->model('API::User')->get_profile( $c->token )->recv;
$c->stash(
Expand Down
6 changes: 3 additions & 3 deletions lib/MetaCPAN/Web/Controller/Account/Favorite.pm
Expand Up @@ -13,7 +13,7 @@ sub auto : Private {
return 1;
}

sub add : Local {
sub add : Local : Args(0) {
my ( $self, $c ) = @_;
$c->detach('/forbidden') unless ( $c->req->method eq 'POST' );
my $model = $c->model('API::User');
Expand Down Expand Up @@ -43,12 +43,12 @@ sub add : Local {
}
}

sub list : Local {
sub list : Local : Args(0) {
my ( $self, $c ) = @_;
$self->_add_fav_list_to_stash( $c, 1_000 );
}

sub list_as_json : Local {
sub list_as_json : Local : Args(0) {
my ( $self, $c ) = @_;

$self->_add_fav_list_to_stash( $c, 1_000 );
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Controller/Account/Turing.pm
Expand Up @@ -6,7 +6,7 @@ BEGIN { extends 'MetaCPAN::Web::Controller' }

has public_key => ( is => 'ro', required => 1 );

sub index : Path('') {
sub index : Path('') : Args(0) {
my ( $self, $c ) = @_;
if ( $c->req->method eq 'POST' ) {
my $params = $c->req->params;
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Controller/Activity.pm
Expand Up @@ -8,7 +8,7 @@ use DateTime;

my %res = ( week => '1w', month => 'month' );

sub index : Path {
sub index : Path : Args(0) {
my ( $self, $c ) = @_;
my $req = $c->req;
my $res = $res{ $req->parameters->{res} || 'week' } || '1w';
Expand Down
4 changes: 2 additions & 2 deletions lib/MetaCPAN/Web/Controller/Diff.pm
Expand Up @@ -8,14 +8,14 @@ BEGIN { extends 'MetaCPAN::Web::Controller' }
sub index : PathPart('diff') : Chained('/') : CaptureArgs(0) {
}

sub diff_releases : Chained('index') : PathPart('release') : Args(4) {
sub release : Local : Args(4) {
my ( $self, $c, @path ) = @_;
my $diff = $c->model('API::Diff')->releases(@path)->recv;
$c->stash(
{ diff => $diff, template => 'diff.html', type => 'release' } );
}

sub diff_files : Chained('index') : PathPart('file') : Args(0) {
sub file : Local : Args(0) {
my ( $self, $c ) = @_;
my $diff = $c->model('API::Diff')
->files( $c->req->params->{source}, $c->req->params->{target} )->recv;
Expand Down
4 changes: 2 additions & 2 deletions lib/MetaCPAN/Web/Controller/Favorite.pm
Expand Up @@ -2,7 +2,7 @@ package MetaCPAN::Web::Controller::Favorite;
use Moose;
BEGIN { extends 'MetaCPAN::Web::Controller' }

sub recent : Path('/favorite/recent') {
sub recent : Local : Args(0) {
my ( $self, $c ) = @_;

my $page_size = $c->req->get_page_size(100);
Expand Down Expand Up @@ -38,7 +38,7 @@ sub recent : Path('/favorite/recent') {
);
}

sub index : Path('/favorite/leaderboard') {
sub leaderboard : Local : Args(0) {
my ( $self, $c ) = @_;

my $data = $c->model('API::Favorite')->leaderboard( $c->req->page )->recv;
Expand Down
11 changes: 4 additions & 7 deletions lib/MetaCPAN/Web/Controller/Feed.pm
Expand Up @@ -10,10 +10,7 @@ use DateTime::Format::ISO8601;
use Path::Tiny qw/path/;
use Text::Markdown qw/markdown/;

sub index : PathPart('feed') : Chained('/') : CaptureArgs(0) {
}

sub recent : Chained('index') PathPart Args(0) {
sub recent : Local : Args(0) {
my ( $self, $c ) = @_;
$c->forward('/recent/index');
my $data = $c->stash;
Expand All @@ -23,7 +20,7 @@ sub recent : Chained('index') PathPart Args(0) {
);
}

sub news : Chained('index') PathPart Args(0) {
sub news : Local : Args(0) {
my ( $self, $c ) = @_;

my $file = $c->config->{home} . '/News.md';
Expand Down Expand Up @@ -61,7 +58,7 @@ sub news : Chained('index') PathPart Args(0) {
);
}

sub author : Chained('index') PathPart Args(1) {
sub author : Local : Args(1) {
my ( $self, $c, $author ) = @_;

# Redirect to this same action with uppercase author.
Expand Down Expand Up @@ -101,7 +98,7 @@ sub author : Chained('index') PathPart Args(1) {
);
}

sub distribution : Chained('index') PathPart Args(1) {
sub distribution : Local : Args(1) {
my ( $self, $c, $distribution ) = @_;
my $data = $c->model('API::Release')->versions($distribution)->recv;
$c->stash->{feed} = $self->build_feed(
Expand Down
9 changes: 3 additions & 6 deletions lib/MetaCPAN/Web/Controller/Lab.pm
Expand Up @@ -16,15 +16,12 @@ __PACKAGE__->config(
}
);

sub lab : Local : Path('/lab') {
sub lab : Path : Args(0) {
my ( $self, $c ) = @_;
$c->stash( template => 'lab.html' );
}

sub index : Chained('/') : PathPart('lab') : CaptureArgs(0) { }

#sub dependencies : Chained('index') : PathPart : Args(1) : Does('Sortable') {
sub dependencies : Chained('index') : PathPart : Does('Sortable') {
sub dependencies : Local : Args(0) : Does('Sortable') {
my ( $self, $c ) = @_;

my $module;
Expand All @@ -43,7 +40,7 @@ sub dependencies : Chained('index') : PathPart : Does('Sortable') {
);
}

sub dashboard : Chained('index') : PathPart {
sub dashboard : Local : Args(0) {
my ( $self, $c ) = @_;

my $user = $c->model('API::User')->get_profile( $c->token )->recv;
Expand Down
33 changes: 6 additions & 27 deletions lib/MetaCPAN/Web/Controller/Login.pm
Expand Up @@ -5,7 +5,7 @@ use namespace::autoclean;

BEGIN { extends 'MetaCPAN::Web::Controller' }

sub index : Path {
sub index : Path : Args(0) {
my ( $self, $c ) = @_;
if ( my $code = $c->req->parameters->{code} ) {
my $data
Expand All @@ -20,37 +20,16 @@ sub index : Path {
my $state = $c->req->params->{state} || q{};
$c->res->redirect( $c->uri_for("/$state") );
}
elsif ( $c->req->path eq 'login/openid' ) {
$c->stash( { template => 'account/openid-login.html' } );
}
else {
$c->stash( { template => 'account/login.html' } );
}
}

__PACKAGE__->meta->make_immutable;

use Plack::Middleware::Session::Cookie;

package Plack::Middleware::Session::Cookie;
use strict;
no warnings 'redefine';

# every response contains the Vary: Cookie header
# which will make sure that upstream caches
# and browsers cache the responses based on the
# value in the Cookie header.
# With stock Plack::Middleware::Session::Cookie,
# the cookie will change with every request
# because a random id is generated. This will break
# this very useful feature and the browser and
# upstream caches will revalidate each request.
# Overriding generate_id solves this nicely.
# Since the generated_id is never validated against
# anything, there seems to be no ramification.

sub generate_id {
'session';
sub openid : Local : Args(0) {
my ( $self, $c ) = @_;
$c->stash( { template => 'account/openid-login.html' } );
}

__PACKAGE__->meta->make_immutable;

1;
3 changes: 1 addition & 2 deletions lib/MetaCPAN/Web/Controller/Mirrors.pm
Expand Up @@ -5,7 +5,7 @@ use namespace::autoclean;

BEGIN { extends 'MetaCPAN::Web::Controller' }

sub index : Path {
sub index : Path : Args(0) {
my ( $self, $c ) = @_;

$c->add_surrogate_key('mirrors');
Expand All @@ -30,7 +30,6 @@ sub index : Path {
push( @or, { not => { filter => { missing => { field => $_ } } } } )
for (@protocols);

my $cv = AE::cv();
my $data = $c->model('API')->request(
'/mirror/_search',
{
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Controller/Module.pm
Expand Up @@ -8,7 +8,7 @@ BEGIN { extends 'MetaCPAN::Web::Controller' }
# NOTE: We may (be able to) put these redirects into nginx
# but it's nice to have them here (additionally) for development.

sub redirect_to_pod : PathPart('module') : Chained('/') : Args {
sub redirect_to_pod : Path : Args {
my ( $self, $c, @path ) = @_;

# Forward old '/module/' links to the new '/pod/' controller.
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Controller/News.pm
Expand Up @@ -6,7 +6,7 @@ BEGIN { extends 'MetaCPAN::Web::Controller' }

use Path::Tiny qw/path/;

sub news : Local : Path('/news') {
sub news : Path : Args(0) {
my ( $self, $c ) = @_;

my $file = $c->config->{home} . '/News.md';
Expand Down
9 changes: 3 additions & 6 deletions lib/MetaCPAN/Web/Controller/Pod.pm
Expand Up @@ -12,11 +12,8 @@ with qw(
MetaCPAN::Web::Role::ReleaseInfo
);

sub root : Chained('/') PathPart('pod') CaptureArgs(0) {
}

# /pod/$name
sub find : Chained('root') PathPart('') Args(1) {
sub find : Path : Args(1) {
my ( $self, $c, @path ) = @_;

# TODO: Pass size param so we can disambiguate?
Expand All @@ -28,7 +25,7 @@ sub find : Chained('root') PathPart('') Args(1) {
}

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

# force consistent casing in URLs
Expand All @@ -43,7 +40,7 @@ sub release : Chained('root') Local Args {
}

# /pod/distribution/$name/@path
sub distribution : Chained('root') Local Args {
sub distribution : Local : Args {
my ( $self, $c, $dist, @path ) = @_;

# TODO: Could we do this with one query?
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Controller/Raw.pm
Expand Up @@ -5,7 +5,7 @@ use namespace::autoclean;

BEGIN { extends 'MetaCPAN::Web::Controller' }

sub index : PathPart('raw') : Chained('/') : Args {
sub index : Path : Args {
my ( $self, $c, @module ) = @_;

my ( $source, $module ) = (
Expand Down
6 changes: 3 additions & 3 deletions lib/MetaCPAN/Web/Controller/Recent.pm
Expand Up @@ -2,7 +2,7 @@ package MetaCPAN::Web::Controller::Recent;
use Moose;
BEGIN { extends 'MetaCPAN::Web::Controller' }

sub index : Path {
sub index : Path : Args(0) {
my ( $self, $c ) = @_;
my $req = $c->req;

Expand All @@ -25,12 +25,12 @@ sub index : Path {
);
}

sub log : Local {
sub log : Local : Args(0) {
my ( $self, $c ) = @_;
$c->stash( { template => 'recent/log.html' } );
}

sub faves : Path('/recent/favorites') {
sub favorites : Local : Args(0) {
my ( $self, $c ) = @_;
$c->res->redirect( '/favorite/recent', 301 );
$c->detach;
Expand Down

0 comments on commit 4ad4eb9

Please sign in to comment.