JSON -> JSON::MaybeXS

This commit is contained in:
Graham Christensen 2021-10-19 22:53:39 -04:00
parent d16c57e5f1
commit 7dcf6a01c6
31 changed files with 57 additions and 57 deletions

View file

@ -5,7 +5,7 @@ use strict;
use warnings; use warnings;
use base 'DBIx::Class'; use base 'DBIx::Class';
use JSON; use JSON::MaybeXS;
sub TO_JSON { sub TO_JSON {
my $self = shift; my $self = shift;
@ -27,7 +27,7 @@ sub TO_JSON {
} }
foreach my $column (@{$hint->{boolean_columns}}) { foreach my $column (@{$hint->{boolean_columns}}) {
$json{$column} = $self->get_column($column) ? JSON::true : JSON::false; $json{$column} = $self->get_column($column) ? JSON::MaybeXS::true : JSON::MaybeXS::false;
} }
foreach my $relname (keys %{$hint->{relations}}) { foreach my $relname (keys %{$hint->{relations}}) {

View file

@ -7,7 +7,6 @@ use base 'Hydra::Base::Controller::REST';
use Hydra::Helper::Nix; use Hydra::Helper::Nix;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use Hydra::Controller::Project; use Hydra::Controller::Project;
use JSON;
use JSON::MaybeXS; use JSON::MaybeXS;
use DateTime; use DateTime;
use Digest::SHA qw(sha256_hex); use Digest::SHA qw(sha256_hex);
@ -87,7 +86,7 @@ sub jobsetToHash {
triggertime => $jobset->triggertime, triggertime => $jobset->triggertime,
fetcherrormsg => $jobset->fetcherrormsg, fetcherrormsg => $jobset->fetcherrormsg,
errortime => $jobset->errortime, errortime => $jobset->errortime,
haserrormsg => defined($jobset->errormsg) && $jobset->errormsg ne "" ? JSON::true : JSON::false haserrormsg => defined($jobset->errormsg) && $jobset->errormsg ne "" ? JSON::MaybeXS::true : JSON::MaybeXS::false
}; };
} }

View file

@ -11,7 +11,7 @@ use Nix::Store;
use Nix::Config; use Nix::Config;
use Encode; use Encode;
use File::Basename; use File::Basename;
use JSON; use JSON::MaybeXS;
use List::Util qw[min max]; use List::Util qw[min max];
use List::MoreUtils qw{any}; use List::MoreUtils qw{any};
use Net::Prometheus; use Net::Prometheus;

View file

@ -11,7 +11,7 @@ use Hydra::Helper::Nix;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use Hydra::Helper::Email; use Hydra::Helper::Email;
use LWP::UserAgent; use LWP::UserAgent;
use JSON; use JSON::MaybeXS;
use HTML::Entities; use HTML::Entities;
use Encode qw(decode); use Encode qw(decode);

View file

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use utf8; use utf8;
use Encode; use Encode;
use JSON; use JSON::MaybeXS;
use Nix::Store; use Nix::Store;
use Nix::Config; use Nix::Config;
use Hydra::Model::DB; use Hydra::Model::DB;

View file

@ -5,7 +5,7 @@ use warnings;
use parent 'Hydra::Plugin'; use parent 'Hydra::Plugin';
use HTTP::Request; use HTTP::Request;
use LWP::UserAgent; use LWP::UserAgent;
use JSON; use JSON::MaybeXS;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use File::Temp; use File::Temp;
use POSIX qw(strftime); use POSIX qw(strftime);

View file

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use parent 'Hydra::Plugin'; use parent 'Hydra::Plugin';
use HTTP::Request; use HTTP::Request;
use JSON; use JSON::MaybeXS;
use LWP::UserAgent; use LWP::UserAgent;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;

View file

@ -6,7 +6,7 @@ use parent 'Hydra::Plugin';
use HTTP::Request; use HTTP::Request;
use LWP::UserAgent; use LWP::UserAgent;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use JSON; use JSON::MaybeXS;
sub isEnabled { sub isEnabled {
my ($self) = @_; my ($self) = @_;

View file

@ -5,7 +5,7 @@ use warnings;
use parent 'Hydra::Plugin'; use parent 'Hydra::Plugin';
use HTTP::Request; use HTTP::Request;
use JSON; use JSON::MaybeXS;
use LWP::UserAgent; use LWP::UserAgent;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use List::Util qw(max); use List::Util qw(max);

View file

@ -5,7 +5,7 @@ use warnings;
use parent 'Hydra::Plugin'; use parent 'Hydra::Plugin';
use HTTP::Request; use HTTP::Request;
use LWP::UserAgent; use LWP::UserAgent;
use JSON; use JSON::MaybeXS;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use File::Temp; use File::Temp;
use POSIX qw(strftime); use POSIX qw(strftime);

View file

@ -5,7 +5,7 @@ use warnings;
use parent 'Hydra::Plugin'; use parent 'Hydra::Plugin';
use HTTP::Request; use HTTP::Request;
use LWP::UserAgent; use LWP::UserAgent;
use JSON; use JSON::MaybeXS;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use File::Temp; use File::Temp;
use POSIX qw(strftime); use POSIX qw(strftime);

View file

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use parent 'Hydra::Plugin'; use parent 'Hydra::Plugin';
use HTTP::Request; use HTTP::Request;
use JSON; use JSON::MaybeXS;
use LWP::UserAgent; use LWP::UserAgent;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use List::Util qw(max); use List::Util qw(max);

View file

@ -19,7 +19,7 @@ use warnings;
use parent 'Hydra::Plugin'; use parent 'Hydra::Plugin';
use HTTP::Request; use HTTP::Request;
use LWP::UserAgent; use LWP::UserAgent;
use JSON; use JSON::MaybeXS;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use File::Temp; use File::Temp;
use POSIX qw(strftime); use POSIX qw(strftime);

View file

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use parent 'Hydra::Plugin'; use parent 'Hydra::Plugin';
use HTTP::Request; use HTTP::Request;
use JSON; use JSON::MaybeXS;
use LWP::UserAgent; use LWP::UserAgent;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use List::Util qw(max); use List::Util qw(max);

View file

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use parent 'Hydra::Plugin'; use parent 'Hydra::Plugin';
use experimental 'smartmatch'; use experimental 'smartmatch';
use JSON; use JSON::MaybeXS;
sub isEnabled { sub isEnabled {
my ($self) = @_; my ($self) = @_;
@ -74,7 +74,7 @@ sub makeJsonPayload {
my $json = { my $json = {
event => $event, event => $event,
build => $build->id, build => $build->id,
finished => $build->get_column('finished') ? JSON::true : JSON::false, finished => $build->get_column('finished') ? JSON::MaybeXS::true : JSON::MaybeXS::false,
timestamp => $build->get_column('timestamp'), timestamp => $build->get_column('timestamp'),
project => $build->get_column('project'), project => $build->get_column('project'),
jobset => $build->get_column('jobset'), jobset => $build->get_column('jobset'),

View file

@ -6,7 +6,7 @@ use parent 'Hydra::Plugin';
use HTTP::Request; use HTTP::Request;
use LWP::UserAgent; use LWP::UserAgent;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use JSON; use JSON::MaybeXS;
=head1 NAME =head1 NAME

View file

@ -134,7 +134,7 @@ __PACKAGE__->has_many(
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-26 12:02:36 # Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-26 12:02:36
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CkU+hbVTmhfOzQhkHJHCsg # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CkU+hbVTmhfOzQhkHJHCsg
use JSON; use JSON::MaybeXS;
sub as_json { sub as_json {
my $self = shift; my $self = shift;
@ -148,7 +148,7 @@ sub as_json {
"value" => $input->value // "", "value" => $input->value // "",
# boolean_columns # boolean_columns
"emailresponsible" => $self->get_column("emailresponsible") ? JSON::true : JSON::false, "emailresponsible" => $self->get_column("emailresponsible") ? JSON::MaybeXS::true : JSON::MaybeXS::false,
); );
return \%json; return \%json;

View file

@ -375,7 +375,7 @@ __PACKAGE__->has_many(
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-26 12:02:36 # Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-26 12:02:36
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:iI44C3BFTo6IsS1tBwWYsg # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:iI44C3BFTo6IsS1tBwWYsg
use JSON; use JSON::MaybeXS;
=head2 builds =head2 builds
@ -423,8 +423,8 @@ sub as_json {
"flake" => $self->get_column("flake") // "", "flake" => $self->get_column("flake") // "",
# boolean_columns # boolean_columns
"enableemail" => $self->get_column("enableemail") ? JSON::true : JSON::false, "enableemail" => $self->get_column("enableemail") ? JSON::MaybeXS::true : JSON::MaybeXS::false,
"visible" => $self->get_column("hidden") ? JSON::false : JSON::true, "visible" => $self->get_column("hidden") ? JSON::MaybeXS::false : JSON::MaybeXS::true,
"inputs" => { map { $_->name => $_ } $self->jobsetinputs } "inputs" => { map { $_->name => $_ } $self->jobsetinputs }
); );

View file

@ -246,7 +246,7 @@ __PACKAGE__->many_to_many("usernames", "projectmembers", "username");
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-26 12:02:36 # Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-26 12:02:36
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nKVZ8ZNCZQQ52zbpDAaoQQ # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nKVZ8ZNCZQQ52zbpDAaoQQ
use JSON; use JSON::MaybeXS;
sub as_json { sub as_json {
my $self = shift; my $self = shift;
@ -260,8 +260,8 @@ sub as_json {
"owner" => $self->get_column("owner") // "", "owner" => $self->get_column("owner") // "",
# boolean_columns # boolean_columns
"enabled" => $self->get_column("enabled") ? JSON::true : JSON::false, "enabled" => $self->get_column("enabled") ? JSON::MaybeXS::true : JSON::MaybeXS::false,
"hidden" => $self->get_column("hidden") ? JSON::true : JSON::false, "hidden" => $self->get_column("hidden") ? JSON::MaybeXS::true : JSON::MaybeXS::false,
"jobsets" => [ map { $_->name } $self->jobsets ] "jobsets" => [ map { $_->name } $self->jobsets ]
); );

View file

@ -15,7 +15,7 @@ use Hydra::Helper::Nix;
use Hydra::Model::DB; use Hydra::Model::DB;
use Hydra::Plugin; use Hydra::Plugin;
use Hydra::Schema; use Hydra::Schema;
use JSON; use JSON::MaybeXS;
use Net::Statsd; use Net::Statsd;
use Nix::Store; use Nix::Store;
use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC); use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);

View file

@ -6,7 +6,7 @@ use utf8;
use Hydra::Helper::Nix; use Hydra::Helper::Nix;
use Net::Statsd; use Net::Statsd;
use File::Slurper qw(read_text); use File::Slurper qw(read_text);
use JSON; use JSON::MaybeXS;
use Getopt::Long qw(:config gnu_getopt); use Getopt::Long qw(:config gnu_getopt);
STDERR->autoflush(1); STDERR->autoflush(1);

View file

@ -1,7 +1,7 @@
use strict; use strict;
use warnings; use warnings;
use Setup; use Setup;
use JSON qw(decode_json encode_json); use JSON::MaybeXS qw(decode_json encode_json);
use Data::Dumper; use Data::Dumper;
use URI; use URI;
my %ctx = test_init(); my %ctx = test_init();

View file

@ -4,7 +4,7 @@ use warnings;
use Setup; use Setup;
use IO::Uncompress::Bunzip2 qw(bunzip2); use IO::Uncompress::Bunzip2 qw(bunzip2);
use Archive::Tar; use Archive::Tar;
use JSON qw(decode_json); use JSON::MaybeXS qw(decode_json);
use Data::Dumper; use Data::Dumper;
my %ctx = test_init( my %ctx = test_init(
use_external_destination_store => 0 use_external_destination_store => 0

View file

@ -2,7 +2,7 @@ use feature 'unicode_strings';
use strict; use strict;
use warnings; use warnings;
use Setup; use Setup;
use JSON qw(decode_json encode_json); use JSON::MaybeXS qw(decode_json encode_json);
my %ctx = test_init(); my %ctx = test_init();
@ -47,7 +47,7 @@ subtest 'Create new jobset "job" as flake type' => sub {
Cookie => $cookie, Cookie => $cookie,
Content => encode_json({ Content => encode_json({
enabled => 2, enabled => 2,
visible => JSON::true, visible => JSON::MaybeXS::true,
name => "job", name => "job",
type => 1, type => 1,
description => "test jobset", description => "test jobset",
@ -72,12 +72,12 @@ subtest 'Read newly-created jobset "job"' => sub {
description => "test jobset", description => "test jobset",
emailoverride => "", emailoverride => "",
enabled => 2, enabled => 2,
enableemail => JSON::false, enableemail => JSON::MaybeXS::false,
errortime => undef, errortime => undef,
errormsg => "", errormsg => "",
fetcherrormsg => "", fetcherrormsg => "",
flake => "github:nixos/nix", flake => "github:nixos/nix",
visible => JSON::true, visible => JSON::MaybeXS::true,
inputs => {}, inputs => {},
keepnr => 3, keepnr => 3,
lastcheckedtime => undef, lastcheckedtime => undef,
@ -100,7 +100,7 @@ subtest 'Update jobset "job" to legacy type' => sub {
Cookie => $cookie, Cookie => $cookie,
Content => encode_json({ Content => encode_json({
enabled => 3, enabled => 3,
visible => JSON::true, visible => JSON::MaybeXS::true,
name => "job", name => "job",
type => 0, type => 0,
nixexprinput => "ofborg", nixexprinput => "ofborg",
@ -130,17 +130,17 @@ subtest 'Update jobset "job" to legacy type' => sub {
description => "test jobset", description => "test jobset",
emailoverride => "", emailoverride => "",
enabled => 3, enabled => 3,
enableemail => JSON::false, enableemail => JSON::MaybeXS::false,
errortime => undef, errortime => undef,
errormsg => "", errormsg => "",
fetcherrormsg => "", fetcherrormsg => "",
flake => "", flake => "",
visible => JSON::true, visible => JSON::MaybeXS::true,
inputs => { inputs => {
ofborg => { ofborg => {
name => "ofborg", name => "ofborg",
type => "git", type => "git",
emailresponsible => JSON::false, emailresponsible => JSON::MaybeXS::false,
value => "https://github.com/NixOS/ofborg.git released" value => "https://github.com/NixOS/ofborg.git released"
} }
}, },
@ -165,7 +165,7 @@ subtest 'Update jobset "job" to have an invalid input type' => sub {
Cookie => $cookie, Cookie => $cookie,
Content => encode_json({ Content => encode_json({
enabled => 3, enabled => 3,
visible => JSON::true, visible => JSON::MaybeXS::true,
name => "job", name => "job",
type => 0, type => 0,
nixexprinput => "ofborg", nixexprinput => "ofborg",

View file

@ -2,7 +2,7 @@ use feature 'unicode_strings';
use strict; use strict;
use warnings; use warnings;
use Setup; use Setup;
use JSON qw(decode_json encode_json); use JSON::MaybeXS qw(decode_json encode_json);
my %ctx = test_init(); my %ctx = test_init();

View file

@ -2,7 +2,7 @@ use feature 'unicode_strings';
use strict; use strict;
use warnings; use warnings;
use Setup; use Setup;
use JSON qw(decode_json encode_json); use JSON::MaybeXS qw(decode_json encode_json);
my %ctx = test_init(); my %ctx = test_init();
@ -45,8 +45,8 @@ subtest "Read project 'tests'" => sub {
is(decode_json($projectinfo->content), { is(decode_json($projectinfo->content), {
description => "", description => "",
displayname => "Tests", displayname => "Tests",
enabled => JSON::true, enabled => JSON::MaybeXS::true,
hidden => JSON::false, hidden => JSON::MaybeXS::false,
homepage => "", homepage => "",
jobsets => [], jobsets => [],
name => "tests", name => "tests",
@ -61,8 +61,8 @@ subtest "Transitioning from declarative project to normal" => sub {
Content_Type => 'application/json', Content_Type => 'application/json',
Cookie => $cookie, Cookie => $cookie,
Content => encode_json({ Content => encode_json({
enabled => JSON::true, enabled => JSON::MaybeXS::true,
visible => JSON::true, visible => JSON::MaybeXS::true,
name => "tests", name => "tests",
displayname => "Tests", displayname => "Tests",
declarative => { declarative => {
@ -84,8 +84,8 @@ subtest "Transitioning from declarative project to normal" => sub {
is(decode_json($projectinfo->content), { is(decode_json($projectinfo->content), {
description => "", description => "",
displayname => "Tests", displayname => "Tests",
enabled => JSON::true, enabled => JSON::MaybeXS::true,
hidden => JSON::false, hidden => JSON::MaybeXS::false,
homepage => "", homepage => "",
jobsets => [".jobsets"], jobsets => [".jobsets"],
name => "tests", name => "tests",
@ -104,8 +104,8 @@ subtest "Transitioning from declarative project to normal" => sub {
Content_Type => 'application/json', Content_Type => 'application/json',
Cookie => $cookie, Cookie => $cookie,
Content => encode_json({ Content => encode_json({
enabled => JSON::true, enabled => JSON::MaybeXS::true,
visible => JSON::true, visible => JSON::MaybeXS::true,
name => "tests", name => "tests",
displayname => "Tests", displayname => "Tests",
declarative => { declarative => {
@ -127,8 +127,8 @@ subtest "Transitioning from declarative project to normal" => sub {
is(decode_json($projectinfo->content), { is(decode_json($projectinfo->content), {
description => "", description => "",
displayname => "Tests", displayname => "Tests",
enabled => JSON::true, enabled => JSON::MaybeXS::true,
hidden => JSON::false, hidden => JSON::MaybeXS::false,
homepage => "", homepage => "",
jobsets => [], jobsets => [],
name => "tests", name => "tests",

View file

@ -1,7 +1,7 @@
use strict; use strict;
use warnings; use warnings;
use Setup; use Setup;
use JSON; use JSON::MaybeXS;
use File::Copy; use File::Copy;
my %ctx = test_init( my %ctx = test_init(

View file

@ -1,5 +1,6 @@
use strict; use strict;
use warnings; use warnings;
use JSON::MaybeXS;
use Setup; use Setup;
my %ctx = test_init( my %ctx = test_init(
@ -44,7 +45,7 @@ subtest "Validate the top level fields match" => sub {
is($dat->{build}, $build->id, "The build event matches our expected ID."); is($dat->{build}, $build->id, "The build event matches our expected ID.");
is($dat->{buildStatus}, 0, "The build status matches."); is($dat->{buildStatus}, 0, "The build status matches.");
is($dat->{event}, "buildFinished", "The build event matches."); is($dat->{event}, "buildFinished", "The build event matches.");
is($dat->{finished}, JSON::true, "The build finished."); is($dat->{finished}, JSON::MaybeXS::true, "The build finished.");
is($dat->{project}, "tests", "The project matches."); is($dat->{project}, "tests", "The project matches.");
is($dat->{jobset}, "basic", "The jobset matches."); is($dat->{jobset}, "basic", "The jobset matches.");
is($dat->{job}, "metrics", "The job matches."); is($dat->{job}, "metrics", "The job matches.");

View file

@ -1,7 +1,7 @@
use feature 'unicode_strings'; use feature 'unicode_strings';
use strict; use strict;
use warnings; use warnings;
use JSON; use JSON::MaybeXS;
use Setup; use Setup;
my %ctx = test_init( my %ctx = test_init(

View file

@ -1,7 +1,7 @@
use feature 'unicode_strings'; use feature 'unicode_strings';
use strict; use strict;
use warnings; use warnings;
use JSON; use JSON::MaybeXS;
use Setup; use Setup;
my $binarycachedir = File::Temp->newdir(); my $binarycachedir = File::Temp->newdir();

View file

@ -1,7 +1,7 @@
use strict; use strict;
use warnings; use warnings;
use LWP::UserAgent; use LWP::UserAgent;
use JSON; use JSON::MaybeXS;
my $ua = LWP::UserAgent->new; my $ua = LWP::UserAgent->new;
$ua->cookie_jar({}); $ua->cookie_jar({});