Skip to content

Commit

Permalink
Merge pull request #1731 from CPAN-API/mickey/merge_last_commits_from…
Browse files Browse the repository at this point in the history
…_mi_es2

merge last commits from mi/es2
  • Loading branch information
oalders committed Jun 14, 2016
2 parents 18e4b04 + 99e3a98 commit 07e4106
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 52 deletions.
2 changes: 1 addition & 1 deletion cpanfile
Expand Up @@ -19,6 +19,7 @@ requires 'Catalyst::View::TT::Alloy';
requires 'CatalystX::RoleApplicator';
requires 'Config::General';
requires 'Config::JFDI';
requires 'Cpanel::JSON::XS';
requires 'Data::Dumper';
requires 'Data::Pageset';
requires 'Data::Printer', '0.38';
Expand All @@ -45,7 +46,6 @@ requires 'Hash::AsObject';
requires 'Hash::Merge';
requires 'Importer';
requires 'JavaScript::Minifier::XS';
requires 'JSON::MaybeXS', '1.002000';
requires 'List::AllUtils';
requires 'List::MoreUtils';
requires 'List::Util';
Expand Down
7 changes: 3 additions & 4 deletions cpanfile.snapshot
Expand Up @@ -910,14 +910,13 @@ DISTRIBUTIONS
Module::Build 0.38
URI::Escape 0
perl 5.008001
Cpanel-JSON-XS-3.0213
pathname: R/RU/RURBAN/Cpanel-JSON-XS-3.0213.tar.gz
Cpanel-JSON-XS-3.0216
pathname: R/RU/RURBAN/Cpanel-JSON-XS-3.0216.tar.gz
provides:
Cpanel::JSON::XS 3.0213
Cpanel::JSON::XS 3.0216
requirements:
ExtUtils::MakeMaker 0
Pod::Text 2.08
Pod::Usage 1.33
Data-Dump-1.23
pathname: G/GA/GAAS/Data-Dump-1.23.tar.gz
provides:
Expand Down
3 changes: 1 addition & 2 deletions lib/MetaCPAN/Web/Controller/Account.pm
Expand Up @@ -2,8 +2,7 @@ package MetaCPAN::Web::Controller::Account;

use Moose;
use List::MoreUtils qw(pairwise);
use DateTime ();
use JSON::MaybeXS ();
use DateTime ();

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

Expand Down
21 changes: 8 additions & 13 deletions lib/MetaCPAN/Web/Controller/Feed.pm
Expand Up @@ -44,7 +44,7 @@ sub news : Local : Args(0) {
$str =~ s/\A\s*-+//g;
$e{date} = $str =~ s/^Date:\s*(.*)$//m ? $1 : '2014-01-01T00:00:00';
$e{link} = "https://metacpan.org/news#$a_name";
$e{link} = "/news#$a_name";
$e{author} = 'METACPAN';
$str =~ s/^\s*|\s*$//g;
Expand Down Expand Up @@ -123,11 +123,8 @@ sub build_entry {
single_valued_arrayref_to_scalar($entry);
my $e = XML::Feed::Entry->new('RSS');
$e->title( $entry->{name} );
$e->link(
$entry->{link} ||= join( q{/},
'https://metacpan.org', 'release',
$entry->{author}, $entry->{name} )
);
$e->link( $entry->{link}
||= join( q{/}, 'release', $entry->{author}, $entry->{name} ) );
$e->author( $entry->{author} );
$e->issued( DateTime::Format::ISO8601->parse_datetime( $entry->{date} ) );
$e->summary( escape_html( $entry->{abstract} ) );
Expand All @@ -138,7 +135,7 @@ sub build_feed {
my ( $self, %params ) = @_;
my $feed = XML::Feed->new( 'RSS', version => 2.0 );
$feed->title( $params{title} );
$feed->link('https://metacpan.org/');
$feed->link('/');
foreach my $entry ( @{ $params{entries} } ) {

$feed->add_entry( $self->build_entry($entry) );
Expand All @@ -150,9 +147,8 @@ sub _format_release_entries {
my ( $self, $releases ) = @_;
my @release_data;
foreach my $item ( @{$releases} ) {
$item->{link} = join( q{/},
'https://metacpan.org', 'release',
$item->{author}, $item->{name} );
$item->{link}
= join( q{/}, 'release', $item->{author}, $item->{name} );
$item->{name} = "$item->{author} has released $item->{name}";
push( @release_data, $item );
}
Expand All @@ -166,9 +162,8 @@ sub _format_favorite_entries {
$fav->{abstract}
= "$author ++ed $fav->{distribution} from $fav->{author}";
$fav->{author} = $author;
$fav->{link} = join( q{/},
'https://metacpan.org', 'release', $fav->{distribution} );
$fav->{name} = "$author ++ed $fav->{distribution}";
$fav->{link} = join( q{/}, 'release', $fav->{distribution} );
$fav->{name} = "$author ++ed $fav->{distribution}";
push( @fav_data, $fav );
}
return \@fav_data;
Expand Down
4 changes: 2 additions & 2 deletions lib/MetaCPAN/Web/Controller/Search/AutoComplete.pm
@@ -1,7 +1,7 @@
package MetaCPAN::Web::Controller::Search::AutoComplete;

use Moose;
use JSON::MaybeXS ();
use Cpanel::JSON::XS ();

use Importer 'MetaCPAN::Web::Elasticsearch::Adapter' =>
qw/ single_valued_arrayref_to_scalar /;
Expand All @@ -17,7 +17,7 @@ sub index : Path : Args(0) {
my $data = $model->autocomplete($query)->recv;
$c->res->content_type('application/json');
$c->res->body(
JSON::MaybeXS::encode_json(
Cpanel::JSON::XS::encode_json(
single_valued_arrayref_to_scalar( $data->{results} )
)
);
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Model/API.pm
Expand Up @@ -8,7 +8,7 @@ use namespace::autoclean;
use AnyEvent::Curl::Multi;
use Encode ();
use HTTP::Request ();
use JSON::MaybeXS;
use Cpanel::JSON::XS qw( decode_json encode_json );
use MetaCPAN::Web::Types qw( Uri );
use MooseX::ClassAttribute;
use Try::Tiny qw( catch try );
Expand Down
9 changes: 7 additions & 2 deletions lib/MetaCPAN/Web/Model/API/Release.pm
Expand Up @@ -153,8 +153,9 @@ sub modules {
query => { match_all => {} },
filter => {
and => [
{ term => { release => $release } },
{ term => { author => $author } },
{ term => { release => $release } },
{ term => { author => $author } },
{ term => { directory => 0 } },
{
or => [
{
Expand All @@ -173,6 +174,10 @@ sub modules {
},
{
and => [
{
range =>
{ slop => { gt => 0 } }
},
{
exists => {
field => 'pod.analyzed'
Expand Down
5 changes: 3 additions & 2 deletions lib/MetaCPAN/Web/Role/Request.pm
Expand Up @@ -3,7 +3,7 @@ package MetaCPAN::Web::Role::Request;
use utf8;
use Moose::Role;
use Plack::Session;
use JSON::MaybeXS ();
use Cpanel::JSON::XS ();
use MetaCPAN::Web::Types qw( PositiveInt );
use Try::Tiny;

Expand Down Expand Up @@ -33,7 +33,8 @@ sub get_page_size {
sub json_param {
my ( $self, $name ) = @_;
return try {
JSON::MaybeXS->new->relaxed->utf8( $self->params_are_decoded ? 0 : 1 )
Cpanel::JSON::XS->new->relaxed->utf8(
$self->params_are_decoded ? 0 : 1 )
->decode( $self->params->{$name} );
}
catch {
Expand Down
8 changes: 4 additions & 4 deletions lib/MetaCPAN/Web/View/HTML.pm
Expand Up @@ -5,8 +5,8 @@ extends 'Catalyst::View::TT::Alloy';

use Digest::MD5 qw(md5_hex);
use Digest::SHA1;
use List::Util ();
use JSON::MaybeXS;
use List::Util ();
use Cpanel::JSON::XS ();
use Gravatar::URL;
use Regexp::Common qw(time);
use Template::Plugin::DateTime;
Expand Down Expand Up @@ -91,7 +91,7 @@ Template::Alloy->define_vmethod(
pretty_json => sub {

# Use utf8(0) because Catatlyst expects our view to be a character string.
JSON::MaybeXS->new->utf8(0)->pretty->encode(shift);
Cpanel::JSON::XS->new->utf8(0)->pretty->encode(shift);
}
);

Expand Down Expand Up @@ -139,7 +139,7 @@ Template::Alloy->define_vmethod(
Template::Alloy->define_vmethod(
'array',
json => sub {
JSON::MaybeXS::encode_json(shift);
Cpanel::JSON::XS::encode_json(shift);
}
);

Expand Down
4 changes: 2 additions & 2 deletions lib/MetaCPAN/Web/View/JSON.pm
@@ -1,13 +1,13 @@
package MetaCPAN::Web::View::JSON;

use Moose;
use JSON::MaybeXS ();
use Cpanel::JSON::XS ();

extends 'Catalyst::View::JSON';

sub encode_json {
my ( $self, $c, $data ) = @_;
JSON::MaybeXS->new->utf8->encode($data);
Cpanel::JSON::XS->new->utf8->encode($data);
}

# Catalyst::View::JSON is not a Moose.
Expand Down
10 changes: 6 additions & 4 deletions lib/Plack/Middleware/Session/Cookie/MetaCPAN.pm
Expand Up @@ -4,10 +4,10 @@ use parent qw(Plack::Middleware::Session::Cookie);

use Plack::Util;
use MIME::Base64;
use JSON::MaybeXS;
use Cpanel::JSON::XS ();
use Try::Tiny;

my $json = JSON::MaybeXS->new( canonical => 1 );
my $json = Cpanel::JSON::XS->new->canonical(1);

sub prepare_app {
my $self = shift;
Expand All @@ -16,7 +16,8 @@ sub prepare_app {
sub {
# Pass $_[0] since the json subs may have a ($) protoype.
# Pass '' to base64 for a blank separator (instead of newlines).
MIME::Base64::encode( JSON::MaybeXS::encode_json( $_[0] ), q[] );
MIME::Base64::encode( Cpanel::JSON::XS::encode_json( $_[0] ),
q[] );
}
) unless $self->serializer;

Expand All @@ -27,7 +28,8 @@ sub prepare_app {

# Use try/catch so JSON doesn't barf if the cookie is bad.
try {
JSON::MaybeXS::decode_json( MIME::Base64::decode($cookie) );
Cpanel::JSON::XS::decode_json(
MIME::Base64::decode($cookie) );
}

# No session.
Expand Down
10 changes: 5 additions & 5 deletions root/browse.html
Expand Up @@ -15,8 +15,8 @@
<li><a data-keyboard-shortcut="g a" href="/author/<% author %>"><i class="fa fa-user fa-fw black"></i>Author</a></li>
<li><a href="<% api_external_secure %>/source/<% base %>"><i class="fa fa-file-text-o fa-fw black"></i>Raw browser</a></li>
<li class="nav-header">Info</li>
<li><% count = files.grep(->{this.directory == 'true'}).size; count %> folder<% count != 1 ? "s" : "" %></li>
<li><% count = files.grep(->{this.directory == 'false'}).size; count %> file<% count != 1 ? "s" : "" %></li>
<li><% count = files.grep(->{this.directory == 1 }).size; count %> folder<% count != 1 ? "s" : "" %></li>
<li><% count = files.grep(->{this.directory == 0 }).size; count %> file<% count != 1 ? "s" : "" %></li>
</ul>

<div class="content">
Expand All @@ -32,14 +32,14 @@
<tbody>
<% i = 0; FOREACH file IN files %>
<tr>
<td class="name" sort="<% file.directory == 'true' ? "!" _ file.name : file.name %>"><strong><a href="/source/<% [author, release, file.path].join("/") %>" class="<%
file.directory == 'true' ? 'silk-folder'
<td class="name" sort="<% file.directory == 1 ? "!" _ file.name : file.name %>"><strong><a href="/source/<% [author, release, file.path].join("/") %>" class="<%
file.directory == 1 ? 'silk-folder'
: file.mime.match("perl") ? 'silk-page-white-code'
: file.mime.match("x-c") ? 'silk-page-white-c'
: 'silk-page-white'
-%>" title="<% file.path %>"><% file.name %></a></strong></td>
<td class="documentation"><strong><a href="/pod/release/<% [author, release, file.path].join("/") %>" title="<% file.path %>" class="ellipsis"><% file.slop ? file.documentation ? file.documentation : file.name : "" %></a></strong></td>
<td class="size" sort="<% file.directory == "false" ? file.${"stat.size"} : 0 %>"><% file.directory == "false" ? file.${"stat.size"} | format_bytes : "" %></td>
<td class="size" sort="<% file.directory == 0 ? file.${"stat.size"} : 0 %>"><% file.directory == 0 ? file.${"stat.size"} | format_bytes : "" %></td>
<td class="mtime relatize" nowrap="nowrap" sort="<% date = file.${"stat.mtime"}.dt_http; date %>"><% date %></td>
</tr>
<% END %>
Expand Down
8 changes: 2 additions & 6 deletions t/controller/feed.t
Expand Up @@ -91,11 +91,7 @@ subtest 'get correct author favorite data format' => sub {
'PERLHACKER ++ed Git-Sub from DOLMEN',
'get correct release abstract'
);
is(
$entry->[0]->{link},
'https://metacpan.org/release/Git-Sub',
'get correct release link'
);
is( $entry->[0]->{link}, 'release/Git-Sub', 'get correct release link' );
is(
$entry->[0]->{name},
'PERLHACKER ++ed Git-Sub',
Expand Down Expand Up @@ -124,7 +120,7 @@ subtest 'get correct author release data format' => sub {
);
is(
$entry->[0]->{link},
'https://metacpan.org/release/OALDERS/Net-FreshBooks-API-0.24',
'release/OALDERS/Net-FreshBooks-API-0.24',
'get correct release link'
);
is(
Expand Down
2 changes: 1 addition & 1 deletion t/controller/search/autocomplete.t
Expand Up @@ -4,7 +4,7 @@ use utf8;
use Encode qw(encode is_utf8);
use Test::More;
use MetaCPAN::Web::Test;
use JSON::MaybeXS;
use Cpanel::JSON::XS qw( decode_json );

my @tests = (
[ moose => 'Moose' ],
Expand Down
4 changes: 3 additions & 1 deletion t/lib/MetaCPAN/Web/Controller/Test.pm
@@ -1,11 +1,13 @@
package MetaCPAN::Web::Controller::Test;

use Moose;
use Cpanel::JSON::XS;

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

sub _json_body {
my ( $self, $c ) = @_;
JSON::MaybeXS->new->utf8->decode(
Cpanel::JSON::XS->new->utf8->decode(
do { local $/; $c->req->body->getline }
);
}
Expand Down
2 changes: 1 addition & 1 deletion t/model/release.t
Expand Up @@ -2,7 +2,7 @@ use strict;
use warnings;

use Test::More;
use JSON::MaybeXS;
use Cpanel::JSON::XS qw( decode_json );
use MetaCPAN::Web;

use Importer 'MetaCPAN::Web::Elasticsearch::Adapter' =>
Expand Down
2 changes: 1 addition & 1 deletion t/view/json.t
Expand Up @@ -4,7 +4,7 @@ use lib 't/lib';
use Test::More;
use HTTP::Request::Common 'POST';
use MetaCPAN::Web::Test;
use JSON::MaybeXS;
use Cpanel::JSON::XS qw( decode_json );

sub post_json {
POST(
Expand Down

0 comments on commit 07e4106

Please sign in to comment.