use Bugzilla::FlagType;
use Bugzilla::Util qw(datetime_from email_filter);
-use JSON;
+use JSON::MaybeXS;
use MIME::Base64 qw(decode_base64 encode_base64);
use Storable qw(dclone);
use Test::Taint ();
# simple types
-sub as_boolean { $_[0] ? JSON::true : JSON::false }
+sub as_boolean { $_[0] ? JSON->true : JSON->false }
sub as_double { defined $_[0] ? $_[0] + 0.0 : JSON::null }
sub as_int { defined $_[0] ? int($_[0]) : JSON::null }
sub as_string { defined $_[0] ? $_[0] . '' : JSON::null }
use File::Spec qw(catfile);
use HTTP::Request;
use HTTP::Response;
-use JSON;
+use JSON::MaybeXS;
use Moo;
use Module::Runtime qw(require_module);
use Scalar::Util qw(blessed);
if ($status_code && $message) {
$self->{_return_error} = {
status_code => $status_code,
- error => JSON::true,
+ error => JSON->true,
message => $message
};
$self->{_return_error}->{code} = $error_code if $error_code;
use Bugzilla::Install::Util qw(i_am_persistent);
use Bugzilla::Util qw(trick_taint read_text write_text);
-use JSON::XS;
+use JSON::MaybeXS;
use File::Temp;
use File::Basename;
}
# This hook is also called in editparams.cgi. This call here is required
# to make SetParam work.
- Bugzilla::Hook::process('config_modify_panels',
+ Bugzilla::Hook::process('config_modify_panels',
{ panels => \%hook_panels });
foreach my $panel (keys %hook_panels) {
$param_panels->{$module} = "Bugzilla::Config::$module" unless $module eq 'Common';
}
# Now check for any hooked params
- Bugzilla::Hook::process('config_add_panels',
+ Bugzilla::Hook::process('config_add_panels',
{ panel_modules => $param_panels });
return $param_panels;
}
}
# set verify method to whatever loginmethod was
- if (exists $param->{'loginmethod'}
- && !exists $param->{'user_verify_class'})
+ if (exists $param->{'loginmethod'}
+ && !exists $param->{'user_verify_class'})
{
$new_params{'user_verify_class'} = $param->{'loginmethod'};
}
# Remove quip-display control from parameters
# and give it to users via User Settings (Bug 41972)
- if ( exists $param->{'enablequips'}
- && !exists $param->{'quip_list_entry_control'})
+ if ( exists $param->{'enablequips'}
+ && !exists $param->{'quip_list_entry_control'})
{
my $new_value;
($param->{'enablequips'} eq 'on') && do {$new_value = 'open';};
$param_data ||= Bugzilla->params;
my $param_file = bz_locations()->{'datadir'} . '/params.json';
- my $json_data = JSON::XS->new->canonical->pretty->encode($param_data);
+ my $json_data = JSON()->new->canonical->pretty->encode($param_data);
write_text($param_file, $json_data);
-
# It's not common to edit parameters and loading
# Bugzilla::Install::Filesystem is slow.
require Bugzilla::Install::Filesystem;
trick_taint($data);
# If params.json has been manually edited and e.g. some quotes are
- # missing, we don't want JSON::XS to leak the content of the file
+ # missing, we don't want JSON::MaybeXS to leak the content of the file
# to all users in its error message, so we have to eval'uate it.
- $params = eval { JSON::XS->new->decode($data) };
+ $params = eval { JSON()->new->decode($data) };
if ($@) {
my $error_msg = (basename($0) eq 'checksetup.pl') ?
$@ : 'run checksetup.pl to see the details.';
my $params;
if (defined $cgi->param('params')) {
local $@;
- $params = eval {
- $self->json->decode(scalar $cgi->param('params'))
+ $params = eval {
+ $self->json->decode(scalar $cgi->param('params'))
};
if ($@) {
ThrowUserError('json_rpc_invalid_params',
sub type {
my ($self, $type, $value) = @_;
-
+
# This is the only type that does something special with undef.
if ($type eq 'boolean') {
- return $value ? JSON::true : JSON::false;
+ return $value ? JSON->true : JSON->false;
}
-
+
return JSON::null if !defined $value;
my $retval = $value;
if (defined $params->{$field}) {
my $value = $params->{$field};
if (ref $value eq 'ARRAY') {
- $params->{$field} =
+ $params->{$field} =
[ map { $self->datetime_format_inbound($_) } @$value ];
}
else {
# methods that can change data. This protects us against cross-site
# request forgeries.
if (!grep($_ eq $method, $pkg->READ_ONLY)) {
- ThrowUserError('json_rpc_post_only',
+ ThrowUserError('json_rpc_post_only',
{ method => $self->_bz_method_name });
}
}
$self->handle_login();
# Bugzilla::WebService packages call internal methods like
- # $self->_some_private_method. So we have to inherit from
+ # $self->_some_private_method. So we have to inherit from
# that class as well as this Server class.
my $new_class = ref($self) . '::' . $pkg;
my $isa_string = 'our @ISA = qw(' . ref($self) . " $pkg)";
# _bz_method_name is stored by _find_procedure for later use.
sub _bz_method_name {
- return $_[0]->{_bz_method_name};
+ return $_[0]->{_bz_method_name};
}
sub _bz_callback {
To connect over GET, simply send the values that you'd normally send for
each JSON-RPC argument as URL parameters, with the C<params> item being
-a JSON string.
+a JSON string.
The simplest example is a call to C<Bugzilla.time>:
To use JSONP with Bugzilla's JSON-RPC WebService, simply specify a
C<callback> parameter to jsonrpc.cgi when using it via GET as described above.
-For example, here's some HTML you could use to get the data from
+For example, here's some HTML you could use to get the data from
C<Bugzilla.time> on a remote website, using JSONP:
- <script type="text/javascript"
+ <script type="text/javascript"
src="http://bugzilla.example.com/jsonrpc.cgi?method=Bugzilla.time&callback=foo">
That would call the C<Bugzilla.time> method and pass its value to a function
So, for example, in JSON-RPC 1.0, an error response would look like:
- {
- result: null,
- error: { message: 'Some message here', code: 123 },
+ {
+ result: null,
+ error: { message: 'Some message here', code: 123 },
id: 1
}
'Email::Sender' => '1.300011',
'HTTP::Request' => 0,
'HTTP::Response' => 0,
- 'JSON::XS' => '2.01',
+ 'JSON::MaybeXS' => '1.003008',
'List::MoreUtils' => '0.32',
'Math::Random::ISAAC' => '1.0.1',
'Moo' => 2,
use URI::QueryParam;
use Digest::SHA qw(sha256_hex);
use LWP::UserAgent ();
-use JSON qw(decode_json encode_json);
+use JSON::MaybeXS qw(decode_json encode_json);
Bugzilla->login(LOGIN_REQUIRED);
use autodie;
use LWP::UserAgent;
-use JSON;
+use JSON::MaybeXS;
use QA::Util;
use parent qw(LWP::UserAgent Exporter);