Skip to content

Commit

Permalink
use same JSON module as API
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Jun 12, 2016
1 parent 2071c8d commit 5025497
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 22 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
8 changes: 8 additions & 0 deletions cpanfile.snapshot
Expand Up @@ -910,6 +910,13 @@ DISTRIBUTIONS
Module::Build 0.38
URI::Escape 0
perl 5.008001
Cpanel-JSON-XS-3.0216
pathname: R/RU/RURBAN/Cpanel-JSON-XS-3.0216.tar.gz
provides:
Cpanel::JSON::XS 3.0216
requirements:
ExtUtils::MakeMaker 0
Pod::Text 2.08
Data-Dump-1.23
pathname: G/GA/GAAS/Data-Dump-1.23.tar.gz
provides:
Expand Down Expand Up @@ -2288,6 +2295,7 @@ DISTRIBUTIONS
JSON::MaybeXS 1.003005
requirements:
Carp 0
Cpanel::JSON::XS 2.3310
ExtUtils::CBuilder 0.27
ExtUtils::MakeMaker 0
File::Spec 0
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
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
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
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 5025497

Please sign in to comment.