diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-12-10 21:24:57 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-01-22 16:58:04 +0000 |
commit | 1c40be1f4b5a00fd6da081225b04efad228f8025 (patch) | |
tree | ec6e320f4d44c1a06deddfbd43050e2e04a6499b /perllib/FixMyStreet | |
parent | 61573768a8bd0a9f6c3ec69d405f153121e07563 (diff) |
Switch to JSON::MaybeXS, remove JSON::XS.
Travis has Cpanel::JSON::XS preinstalled, which means that the build
would fail there, as JSON::MaybeXS would try and upgrade JSON::XS to
version 3 which the snapshot did not contain.
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Auth.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 3 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/FakeMapit.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/JSON.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Open311.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 24 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 3 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Status.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 2 |
13 files changed, 28 insertions, 34 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 4aa695ae5..5ccab4047 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -6,6 +6,7 @@ BEGIN { extends 'Catalyst::Controller'; } use FixMyStreet::Map; use Encode; +use JSON::MaybeXS; use Utils; =head1 NAME @@ -306,7 +307,7 @@ sub ajax : Path('/ajax') { # JSON encode the response my $json = { pins => $pins }; $json->{current} = $on_map_list_html if $on_map_list_html; - my $body = JSON->new->utf8(1)->encode($json); + my $body = encode_json($json); $c->res->body($body); } @@ -363,9 +364,7 @@ sub _geocode : Private { $response = \@addresses; } - my $body = JSON->new->utf8(1)->encode( - $response - ); + my $body = encode_json($response); $c->res->body($body); } diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm index 6de416c53..b6cd84cf0 100644 --- a/perllib/FixMyStreet/App/Controller/Auth.pm +++ b/perllib/FixMyStreet/App/Controller/Auth.pm @@ -7,7 +7,7 @@ BEGIN { extends 'Catalyst::Controller'; } use Email::Valid; use Net::Domain::TLD; use mySociety::AuthToken; -use JSON; +use JSON::MaybeXS; =head1 NAME @@ -275,7 +275,7 @@ sub ajax_sign_in : Path('ajax/sign_in') { $return->{error} = 1; } - my $body = JSON->new->utf8(1)->encode( $return ); + my $body = encode_json($return); $c->res->content_type('application/json; charset=utf-8'); $c->res->body($body); @@ -287,7 +287,7 @@ sub ajax_sign_out : Path('ajax/sign_out') { $c->logout(); - my $body = JSON->new->utf8(1)->encode( { signed_out => 1 } ); + my $body = encode_json( { signed_out => 1 } ); $c->res->content_type('application/json; charset=utf-8'); $c->res->body($body); @@ -305,7 +305,7 @@ sub ajax_check_auth : Path('ajax/check_auth') { $code = 200; } - my $body = JSON->new->utf8(1)->encode( $data ); + my $body = encode_json($data); $c->res->content_type('application/json; charset=utf-8'); $c->res->code($code); $c->res->body($body); diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index faddaa89e..9189b28e5 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -4,6 +4,7 @@ use namespace::autoclean; use DateTime; use File::Slurp; +use JSON::MaybeXS; BEGIN { extends 'Catalyst::Controller'; } @@ -40,7 +41,7 @@ sub example : Local : Args(0) { my $data = File::Slurp::read_file( FixMyStreet->path_to( 'data/dashboard.json' )->stringify ); - my $j = JSON->new->utf8->decode($data); + my $j = decode_json($data); if ( !$c->stash->{ward} && !$c->stash->{category} ) { $c->stash->{problems} = $j->{counts_all}; } else { diff --git a/perllib/FixMyStreet/App/Controller/FakeMapit.pm b/perllib/FixMyStreet/App/Controller/FakeMapit.pm index 253c75ba4..a4adadd09 100755 --- a/perllib/FixMyStreet/App/Controller/FakeMapit.pm +++ b/perllib/FixMyStreet/App/Controller/FakeMapit.pm @@ -1,6 +1,7 @@ package FixMyStreet::App::Controller::FakeMapit; use Moose; use namespace::autoclean; +use JSON::MaybeXS; BEGIN { extends 'Catalyst::Controller'; } @@ -22,7 +23,7 @@ my $area = { "name" => "Everywhere", "type" => "ZZZ", "id" => 161 }; sub output : Private { my ( $self, $c, $data ) = @_; - my $body = JSON->new->utf8(1)->encode( $data ); + my $body = encode_json($data); $c->res->content_type('application/json; charset=utf-8'); $c->res->body( $body ); } diff --git a/perllib/FixMyStreet/App/Controller/JSON.pm b/perllib/FixMyStreet/App/Controller/JSON.pm index be738bb8b..d3cd33546 100644 --- a/perllib/FixMyStreet/App/Controller/JSON.pm +++ b/perllib/FixMyStreet/App/Controller/JSON.pm @@ -4,7 +4,7 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } -use JSON; +use JSON::MaybeXS; use DateTime; use DateTime::Format::ISO8601; use List::MoreUtils 'uniq'; diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index 96066ca93..f35dc64a5 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -4,7 +4,7 @@ use utf8; use Moose; use namespace::autoclean; -use JSON; +use JSON::MaybeXS; use XML::Simple; use DateTime::Format::W3CDTF; diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index d7cae05d4..5cc44bb8f 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -2,6 +2,8 @@ package FixMyStreet::App::Controller::Report; use Moose; use namespace::autoclean; +use JSON::MaybeXS; + BEGIN { extends 'Catalyst::Controller'; } =head1 NAME @@ -184,7 +186,7 @@ sub format_problem_for_display : Private { if ( $c->stash->{ajax} ) { $c->res->content_type('application/json; charset=utf-8'); - my $content = JSON->new->utf8(1)->encode( + my $content = encode_json( { report => $c->cobrand->problem_as_hashref( $problem, $c ), updates => $c->cobrand->updates_as_hashref( $problem, $c ), diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index db524ada4..1b4c1b295 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -12,7 +12,7 @@ use mySociety::MaPit; use Path::Class; use Utils; use mySociety::EmailUtil; -use JSON; +use JSON::MaybeXS; =head1 NAME @@ -164,9 +164,7 @@ sub report_new_ajax : Path('mobile') : Args(0) { sub send_json_response : Private { my ( $self, $c ) = @_; - my $body = JSON->new->utf8(1)->encode( - $c->stash->{json_response}, - ); + my $body = encode_json($c->stash->{json_response}); $c->res->content_type('application/json; charset=utf-8'); $c->res->body($body); } @@ -178,9 +176,7 @@ sub report_form_ajax : Path('ajax') : Args(0) { # work out the location for this report and do some checks if ( ! $c->forward('determine_location') ) { - my $body = JSON->new->utf8(1)->encode( { - error => $c->stash->{location_error}, - } ); + my $body = encode_json({ error => $c->stash->{location_error} }); $c->res->content_type('application/json; charset=utf-8'); $c->res->body($body); return; @@ -197,7 +193,7 @@ sub report_form_ajax : Path('ajax') : Args(0) { my $extra_titles_list = $c->cobrand->title_list($c->stash->{all_areas}); - my $body = JSON->new->utf8(1)->encode( + my $body = encode_json( { councils_text => $councils_text, category => $category, @@ -216,11 +212,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) { $c->forward('initialize_report'); if ( ! $c->forward('determine_location') ) { - my $body = JSON->new->utf8(1)->encode( - { - error => _("Sorry, we could not find that location."), - } - ); + my $body = encode_json({ error => _("Sorry, we could not find that location.") }); $c->res->content_type('application/json; charset=utf-8'); $c->res->body($body); return 1; @@ -244,11 +236,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) { $category_extra = $c->render_fragment( 'report/new/category_extras.html'); } - my $body = JSON->new->utf8(1)->encode( - { - category_extra => $category_extra, - } - ); + my $body = encode_json({ category_extra => $category_extra }); $c->res->content_type('application/json; charset=utf-8'); $c->res->body($body); diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 407fc625e..027b0d5a4 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -3,6 +3,7 @@ use Moose; use namespace::autoclean; use File::Slurp; +use JSON::MaybeXS; use List::MoreUtils qw(any); use POSIX qw(strcoll); use RABX; @@ -68,7 +69,7 @@ sub index : Path : Args(0) { my $data = File::Slurp::read_file( FixMyStreet->path_to( '../data/all-reports.json' )->stringify ); - my $j = JSON->new->utf8->decode($data); + my $j = decode_json($data); $c->stash->{fixed} = $j->{fixed}; $c->stash->{open} = $j->{open}; }; diff --git a/perllib/FixMyStreet/App/Controller/Status.pm b/perllib/FixMyStreet/App/Controller/Status.pm index 8a84a1666..931c7bd47 100755 --- a/perllib/FixMyStreet/App/Controller/Status.pm +++ b/perllib/FixMyStreet/App/Controller/Status.pm @@ -3,7 +3,7 @@ use Moose; use namespace::autoclean; use HTTP::Negotiate; -use JSON; +use JSON::MaybeXS; BEGIN { extends 'Catalyst::Controller'; } diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index 2473f386f..824590d38 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -1,6 +1,7 @@ package FixMyStreet::Cobrand::UK; use base 'FixMyStreet::Cobrand::Default'; +use JSON::MaybeXS; use mySociety::MaPit; use mySociety::VotingArea; diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index aac52fbaa..4470ecbca 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -11,6 +11,7 @@ use Digest::MD5 qw(md5_hex); use Encode; use File::Slurp; use File::Path (); +use JSON::MaybeXS; use LWP::Simple qw($ua); use URI::Escape; use FixMyStreet::Geocode::Bing; diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index d3adce08b..9d836ca4d 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -14,7 +14,7 @@ use Test::More; use Web::Scraper; use Carp; use Email::Send::Test; -use JSON; +use JSON::MaybeXS; =head1 NAME |