Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Tidy everything.
  • Loading branch information
oalders committed Feb 21, 2014
1 parent fc78e0c commit 30c9370
Show file tree
Hide file tree
Showing 60 changed files with 1,208 additions and 926 deletions.
18 changes: 7 additions & 11 deletions .gitignore
Expand Up @@ -3,19 +3,15 @@
.carton
.includepath
.project
.tidyall.d/
/MYMETA.*
/Makefile
/Makefile.old
/blib
/pm_to_blib
/var/tmp
carton.lock
cover_db/
local
metacpan_web_local.conf

# generated by Makefile.PL (for instance when doing `cpanm --installdeps .`)
/Makefile
/Makefile.old
/MYMETA.*
/pm_to_blib
/blib

.tidyall.d/
perltidy.LOG

cover_db/
26 changes: 15 additions & 11 deletions app.psgi
Expand Up @@ -27,9 +27,11 @@ use Plack::Middleware::ServerStatus::Lite;

# explicitly call ->to_app on every Plack::App::* for performance
my $app = Plack::App::URLMap->new;
$app->map( '/static/' => Plack::App::File->new( root => 'root/static' )->to_app );
$app->map(
'/static/' => Plack::App::File->new( root => 'root/static' )->to_app );
$app->map( '/favicon.ico' =>
Plack::App::File->new( file => 'root/static/icons/favicon.ico' )->to_app );
Plack::App::File->new( file => 'root/static/icons/favicon.ico' )
->to_app );
$app->map( '/' => MetaCPAN::Web->psgi_app );
$app = $app->to_app;

Expand Down Expand Up @@ -87,23 +89,25 @@ $app = Plack::Middleware::Assets->wrap(

use CHI;

if( !$ENV{PLACK_ENV} || $ENV{PLACK_ENV} ne 'development' ) {
if ( !$ENV{PLACK_ENV} || $ENV{PLACK_ENV} ne 'development' ) {

# Only need for live
my $cache = CHI->new( driver => 'File',
my $cache = CHI->new(
driver => 'File',
root_dir => '/tmp/less.cache'
);

# Wrap up to serve lessc parsed files
$app = Plack::Middleware::MCLess->wrap($app,
cache => $cache,
cache_ttl => "60 minutes",
root => "root/static",
files => [
$app = Plack::Middleware::MCLess->wrap(
$app,
cache => $cache,
cache_ttl => "60 minutes",
root => "root/static",
files => [
map {"root/static/less/$_.less"}
qw(
qw(
style
)
)
],
);
}
Expand Down
20 changes: 12 additions & 8 deletions lib/MetaCPAN/Web.pm
Expand Up @@ -13,20 +13,24 @@ use Catalyst qw/

extends 'Catalyst';

__PACKAGE__->apply_request_class_roles(qw(
MetaCPAN::Web::Role::Request
Catalyst::TraitFor::Request::REST::ForBrowsers
));
__PACKAGE__->apply_request_class_roles(
qw(
MetaCPAN::Web::Role::Request
Catalyst::TraitFor::Request::REST::ForBrowsers
)
);

__PACKAGE__->apply_response_class_roles(qw(
MetaCPAN::Web::Role::Response
));
__PACKAGE__->apply_response_class_roles(
qw(
MetaCPAN::Web::Role::Response
)
);

__PACKAGE__->config(
name => 'MetaCPAN::Web',
disable_component_resolution_regex_fallback => 1,
encoding => 'UTF-8',
'Plugin::Authentication' => {
'Plugin::Authentication' => {
default => {
credential => {
class => 'Password',
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Controller.pm
Expand Up @@ -2,6 +2,6 @@ package MetaCPAN::Web::Controller;
use Moose;
use namespace::autoclean;

BEGIN {extends 'Catalyst::Controller'; }
BEGIN { extends 'Catalyst::Controller'; }

__PACKAGE__->meta->make_immutable;
2 changes: 0 additions & 2 deletions lib/MetaCPAN/Web/Controller/About.pm
Expand Up @@ -39,6 +39,4 @@ sub faq : Local {
$c->stash( template => 'about/faq.html' );
}



1;
10 changes: 6 additions & 4 deletions lib/MetaCPAN/Web/Controller/Account/Favorite.pm
Expand Up @@ -16,13 +16,15 @@ sub add : Local {
$res = $model->add_favorite( $data, $c->token )->recv;
}
if ( $c->req->looks_like_browser ) {
$c->res->redirect( $res->{error}
$c->res->redirect(
$res->{error}
? $c->req->referer
: $c->uri_for('/account/turing/index') );
: $c->uri_for('/account/turing/index')
);
}
else {
$c->stash( { success => $res->{error} ? \0 : \1 } );
$c->res->code(400) if($res->{error});
$c->res->code(400) if ( $res->{error} );
$c->detach( $c->view('JSON') );
}
}
Expand All @@ -32,7 +34,7 @@ sub list : Local {

my $user = $c->model('API::User')->get_profile( $c->token )->recv;

my $faves_cv = $c->model('API::Favorite')->by_user( $user->{user} );
my $faves_cv = $c->model('API::Favorite')->by_user( $user->{user} );
my $faves_data = $faves_cv->recv;
my $faves = [
sort { $b->{date} cmp $a->{date} }
Expand Down
10 changes: 7 additions & 3 deletions lib/MetaCPAN/Web/Controller/Account/Turing.pm
Expand Up @@ -15,16 +15,20 @@ sub index : Path('') {
$c->token
)->recv;
$c->stash(
{ success => $res->{looks_human},
{
success => $res->{looks_human},
error => $res->{error},
res => $res,
referer => $params->{r},
}
);
}
$c->stash(
{ template => 'account/turing.html',
captcha => Captcha::reCAPTCHA->new->get_html( $self->public_key, undef, 1 ),
{
template => 'account/turing.html',
captcha => Captcha::reCAPTCHA->new->get_html(
$self->public_key, undef, 1
),
}
);

Expand Down
13 changes: 8 additions & 5 deletions lib/MetaCPAN/Web/Controller/Activity.pm
Expand Up @@ -24,24 +24,27 @@ sub index : Path {
if ( $req->parameters->{f} && $req->parameters->{f} eq 'n' ) {
push(
@$q,
@{ $c->model('API::Release')
@{
$c->model('API::Release')
->_new_distributions_query->{constant_score}->{filter}
->{and}
}
}
);
}

my $start
= DateTime->now->truncate( to => 'month' )->subtract( months => 23 );
my $data = $c->model('API')->request(
'/release/_search',
{ query => { match_all => {} },
{
query => { match_all => {} },
facets => {
histo => {
date_histogram => { field => 'date', interval => $res },
facet_filter => {
and => [
{ range => {
{
range => {
date => { from => $start->epoch . '000' }
}
},
Expand All @@ -59,7 +62,7 @@ sub index : Path {
map {
$data->{ $start->clone->add( months => $_ )->epoch . '000' }
|| 0
} ( 0 .. 23 )
} ( 0 .. 23 )
];
$c->res->content_type('image/svg+xml');
$c->res->headers->expires( time + 86400 );
Expand Down
5 changes: 3 additions & 2 deletions lib/MetaCPAN/Web/Controller/Author.pm
Expand Up @@ -39,7 +39,8 @@ sub index : Path : Args(1) {
$c->res->last_modified($date);

$c->stash(
{ author => $author,
{
author => $author,
releases => $releases,
faves => $faves,
show_author => 1,
Expand All @@ -50,7 +51,7 @@ sub index : Path : Args(1) {
);

$c->stash( author_country_name =>
Locale::Country::code2country( $author->{country} ) )
Locale::Country::code2country( $author->{country} ) )
if $author->{country};
}

Expand Down
37 changes: 20 additions & 17 deletions lib/MetaCPAN/Web/Controller/Changes.pm
Expand Up @@ -8,7 +8,7 @@ BEGIN { extends 'MetaCPAN::Web::Controller' }
sub distribution : Local Args(1) {
my ( $self, $c, $distribution ) = @_;

$c->forward('get', [$distribution]);
$c->forward( 'get', [$distribution] );
}

sub release : Local Args(2) {
Expand All @@ -17,46 +17,49 @@ sub release : Local Args(2) {
# force consistent casing in URLs
if ( $author ne uc($author) ) {
$c->res->redirect(
$c->uri_for($c->action, [ uc($author), $release ]),
301
);
$c->uri_for( $c->action, [ uc($author), $release ] ), 301 );
$c->detach();
}

$c->forward('get', [$author, $release]);
$c->forward( 'get', [ $author, $release ] );
}

sub get : Private {
my ($self, $c, @args) = @_;
my ( $self, $c, @args ) = @_;

my $file = $c->model('API::Changes')->get(@args)->recv;

# NOTE: There is currently no differentiation (from the API)
# of whether the release doesn't exist or we couldn't find a change log.
# We don't care about the difference here either.
if( !exists $file->{content} ){
if ( !exists $file->{content} ) {

my $release = join('/', @args);
my $release = join( '/', @args );
my $suggest = {
description => 'Try the release info page',

# Is there a more Catalyst way to do this?
url => $c->uri_for('/release/' . $release),
link_text => $release,
url => $c->uri_for( '/release/' . $release ),
link_text => $release,
};

$c->stash({
message => 'Change log not found for release.',
suggest => $suggest,
});
$c->stash(
{
message => 'Change log not found for release.',
suggest => $suggest,
}
);
$c->detach('/not_found');
}

# display as pod if it is a pod file (perldelta.pod and some other dists)
elsif( $file->{documentation} ){
elsif ( $file->{documentation} ) {

# Is there a better way to reuse the pod view?
$c->forward('/pod/release', [@$file{qw( author release path )}]);
$c->forward( '/pod/release', [ @$file{qw( author release path )} ] );
}
else {
$c->stash({ file => $file });
$c->stash( { file => $file } );
$c->forward('/source/content');
}
}
Expand Down
27 changes: 15 additions & 12 deletions lib/MetaCPAN/Web/Controller/Favorite.pm
Expand Up @@ -6,25 +6,26 @@ use base 'MetaCPAN::Web::Controller';
sub recent : Path('/favorite/recent') {
my ( $self, $c ) = @_;

my $data = $c->model( 'API::Favorite' )->recent( $c->req->page )->recv;
my @faves = map { $_->{_source} } @{ $data->{hits}->{hits} };
my $data = $c->model('API::Favorite')->recent( $c->req->page )->recv;
my @faves = map { $_->{_source} } @{ $data->{hits}->{hits} };
my @user_ids = map { $_->{user} } @faves;

my $authors
= $c->model( 'API::Author' )->by_user( \@user_ids )->recv->{hits}
= $c->model('API::Author')->by_user( \@user_ids )->recv->{hits}
->{hits};

my %author_for_user_id
= map { $_->{fields}->{user} => $_->{fields}->{pauseid} } @{$authors};

foreach my $fave ( @faves ) {
foreach my $fave (@faves) {
if ( exists $author_for_user_id{ $fave->{user} } ) {
$fave->{clicked_by_author} = $author_for_user_id{ $fave->{user} };
}
}

$c->stash(
{ header => 1,
{
header => 1,
recent => \@faves,
show_clicked_by => 1,
took => $data->{took},
Expand All @@ -37,15 +38,17 @@ sub recent : Path('/favorite/recent') {
sub index : Path('/favorite/leaderboard') {
my ( $self, $c ) = @_;

my $data = $c->model( 'API::Favorite' )->leaderboard( $c->req->page )->recv;
my $data = $c->model('API::Favorite')->leaderboard( $c->req->page )->recv;
my @leaders = @{ $data->{facets}->{leaderboard}->{terms} }[ 0 .. 99 ];

$c->stash({
leaders => \@leaders,
took => $data->{took},
total => $data->{hits}->{total},
template => 'favorite/leaderboard.html',
});
$c->stash(
{
leaders => \@leaders,
took => $data->{took},
total => $data->{hits}->{total},
template => 'favorite/leaderboard.html',
}
);
}

1;
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Controller/Feed.pm
Expand Up @@ -51,7 +51,7 @@ sub build_entry {
);
$e->author( $entry->{author} );
$e->issued( DateTime::Format::ISO8601->parse_datetime( $entry->{date} ) );
$e->summary( escape_html($entry->{abstract}) );
$e->summary( escape_html( $entry->{abstract} ) );
return $e;
}

Expand Down

0 comments on commit 30c9370

Please sign in to comment.