diff --git a/.perlcriticrc b/.perlcriticrc index bfc20693..d2058e9c 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -1,4 +1,4 @@ theme = community # 5 is the least complainy, 1 is the most complainy -severity = 3 +severity = 2 diff --git a/flake.nix b/flake.nix index 5d76568a..43cce4bd 100644 --- a/flake.nix +++ b/flake.nix @@ -199,6 +199,21 @@ }; }; + ReadonlyX = final.perlPackages.buildPerlModule { + pname = "ReadonlyX"; + version = "1.04"; + src = final.fetchurl { + url = "mirror://cpan/authors/id/S/SA/SANKO/ReadonlyX-1.04.tar.gz"; + sha256 = "81bb97dba93ac6b5ccbce04a42c3590eb04557d75018773ee18d5a30fcf48188"; + }; + buildInputs = with final.perlPackages; [ ModuleBuildTiny TestFatal ]; + meta = { + homepage = "https://github.com/sanko/readonly"; + description = "Faster facility for creating read-only scalars, arrays, hashes"; + license = final.lib.licenses.artistic2; + }; + }; + TieHashMethod = final.buildPerlPackage { pname = "Tie-Hash-Method"; version = "0.02"; @@ -462,6 +477,7 @@ JSON JSONMaybeXS JSONXS + ListSomeUtils LWP LWPProtocolHttps ModulePluggable @@ -472,7 +488,7 @@ ParallelForkManager PerlCriticCommunity PrometheusTinyShared - Readonly + ReadonlyX SetScalar SQLSplitStatement Starman diff --git a/src/lib/Hydra/Base/Controller/NixChannel.pm b/src/lib/Hydra/Base/Controller/NixChannel.pm index a598144f..3f8e9609 100644 --- a/src/lib/Hydra/Base/Controller/NixChannel.pm +++ b/src/lib/Hydra/Base/Controller/NixChannel.pm @@ -3,7 +3,7 @@ package Hydra::Base::Controller::NixChannel; use strict; use warnings; use base 'Hydra::Base::Controller::REST'; -use List::MoreUtils qw(any); +use List::SomeUtils qw(any); use Nix::Store; use Hydra::Helper::Nix; use Hydra::Helper::CatalystUtils; diff --git a/src/lib/Hydra/Component/ToJSON.pm b/src/lib/Hydra/Component/ToJSON.pm index 727a5b1f..a94d235f 100644 --- a/src/lib/Hydra/Component/ToJSON.pm +++ b/src/lib/Hydra/Component/ToJSON.pm @@ -5,7 +5,7 @@ use strict; use warnings; use base 'DBIx::Class'; -use JSON; +use JSON::MaybeXS; sub TO_JSON { my $self = shift; @@ -27,7 +27,7 @@ sub TO_JSON { } 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}}) { diff --git a/src/lib/Hydra/Controller/API.pm b/src/lib/Hydra/Controller/API.pm index 474a0021..76c54bdf 100644 --- a/src/lib/Hydra/Controller/API.pm +++ b/src/lib/Hydra/Controller/API.pm @@ -7,7 +7,6 @@ use base 'Hydra::Base::Controller::REST'; use Hydra::Helper::Nix; use Hydra::Helper::CatalystUtils; use Hydra::Controller::Project; -use JSON; use JSON::MaybeXS; use DateTime; use Digest::SHA qw(sha256_hex); @@ -87,7 +86,7 @@ sub jobsetToHash { triggertime => $jobset->triggertime, fetcherrormsg => $jobset->fetcherrormsg, 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 }; } diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index 72883579..d05aef51 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -11,7 +11,7 @@ use File::stat; use Data::Dump qw(dump); use Nix::Store; use Nix::Config; -use List::MoreUtils qw(all); +use List::SomeUtils qw(all); use Encode; use MIME::Types; use JSON::PP; diff --git a/src/lib/Hydra/Controller/JobsetEval.pm b/src/lib/Hydra/Controller/JobsetEval.pm index 2635adee..6f6e7eab 100644 --- a/src/lib/Hydra/Controller/JobsetEval.pm +++ b/src/lib/Hydra/Controller/JobsetEval.pm @@ -6,7 +6,7 @@ use warnings; use base 'Hydra::Base::Controller::NixChannel'; use Hydra::Helper::Nix; use Hydra::Helper::CatalystUtils; -use List::MoreUtils qw(uniq); +use List::SomeUtils qw(uniq); sub evalChain : Chained('/') PathPart('eval') CaptureArgs(1) { diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 01bb7b44..764ccc33 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -11,9 +11,9 @@ use Nix::Store; use Nix::Config; use Encode; use File::Basename; -use JSON; +use JSON::MaybeXS; use List::Util qw[min max]; -use List::MoreUtils qw{any}; +use List::SomeUtils qw{any}; use Net::Prometheus; use Types::Standard qw/StrMatch/; diff --git a/src/lib/Hydra/Controller/User.pm b/src/lib/Hydra/Controller/User.pm index f22075b9..2aec69ee 100644 --- a/src/lib/Hydra/Controller/User.pm +++ b/src/lib/Hydra/Controller/User.pm @@ -11,7 +11,7 @@ use Hydra::Helper::Nix; use Hydra::Helper::CatalystUtils; use Hydra::Helper::Email; use LWP::UserAgent; -use JSON; +use JSON::MaybeXS; use HTML::Entities; use Encode qw(decode); diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index bf520321..1e6d8944 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -4,7 +4,7 @@ use strict; use warnings; use utf8; use Encode; -use JSON; +use JSON::MaybeXS; use Nix::Store; use Nix::Config; use Hydra::Model::DB; @@ -64,7 +64,8 @@ sub updateDeclarativeJobset { $db->txn_do(sub { my $jobset = $project->jobsets->update_or_create(\%update); $jobset->jobsetinputs->delete; - while ((my $name, my $data) = each %{$declSpec->{"inputs"}}) { + foreach my $name (keys %{$declSpec->{"inputs"}}) { + my $data = $declSpec->{"inputs"}->{$name}; my $row = { name => $name, type => $data->{type} @@ -84,7 +85,8 @@ sub handleDeclarativeJobsetJson { my @kept = keys %$declSpec; push @kept, ".jobsets"; $project->jobsets->search({ name => { "not in" => \@kept } })->update({ enabled => 0, hidden => 1 }); - while ((my $jobsetName, my $spec) = each %$declSpec) { + foreach my $jobsetName (keys %$declSpec) { + my $spec = $declSpec->{$jobsetName}; eval { updateDeclarativeJobset($db, $project, $jobsetName, $spec); 1; diff --git a/src/lib/Hydra/Helper/AttributeSet.pm b/src/lib/Hydra/Helper/AttributeSet.pm index b750d6e1..21966394 100644 --- a/src/lib/Hydra/Helper/AttributeSet.pm +++ b/src/lib/Hydra/Helper/AttributeSet.pm @@ -50,7 +50,7 @@ sub splitPath { sub enumerate { my ($self) = @_; my @paths = sort { length($a) <=> length($b) } @{$self->{"paths"}}; - return wantarray ? @paths : \@paths; + return @paths; } 1; diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm index 64e3c44f..925ed718 100644 --- a/src/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/lib/Hydra/Helper/CatalystUtils.pm @@ -4,7 +4,7 @@ use utf8; use strict; use warnings; use Exporter; -use Readonly; +use ReadonlyX; use Nix::Store; use Hydra::Helper::Nix; @@ -34,7 +34,7 @@ our @EXPORT = qw( # Columns from the Builds table needed to render build lists. -Readonly our @buildListColumns => ('id', 'finished', 'timestamp', 'stoptime', 'project', 'jobset', 'job', 'nixname', 'system', 'buildstatus', 'releasename'); +Readonly::Array our @buildListColumns => ('id', 'finished', 'timestamp', 'stoptime', 'project', 'jobset', 'job', 'nixname', 'system', 'buildstatus', 'releasename'); sub getBuild { @@ -317,16 +317,16 @@ sub paramToList { # Security checking of filenames. -Readonly our $pathCompRE => "(?:[A-Za-z0-9-\+\._\$][A-Za-z0-9-\+\._\$:]*)"; -Readonly our $relPathRE => "(?:$pathCompRE(?:/$pathCompRE)*)"; -Readonly our $relNameRE => "(?:[A-Za-z0-9-_][A-Za-z0-9-\._]*)"; -Readonly our $attrNameRE => "(?:[A-Za-z_][A-Za-z0-9-_]*)"; -Readonly our $projectNameRE => "(?:[A-Za-z_][A-Za-z0-9-_]*)"; -Readonly our $jobsetNameRE => "(?:[A-Za-z_][A-Za-z0-9-_\.]*)"; -Readonly our $jobNameRE => "(?:$attrNameRE(?:\\.$attrNameRE)*)"; -Readonly our $systemRE => "(?:[a-z0-9_]+-[a-z0-9_]+)"; -Readonly our $userNameRE => "(?:[a-z][a-z0-9_\.]*)"; -Readonly our $inputNameRE => "(?:[A-Za-z_][A-Za-z0-9-_]*)"; +Readonly::Scalar our $pathCompRE => "(?:[A-Za-z0-9-\+\._\$][A-Za-z0-9-\+\._\$:]*)"; +Readonly::Scalar our $relPathRE => "(?:$pathCompRE(?:/$pathCompRE)*)"; +Readonly::Scalar our $relNameRE => "(?:[A-Za-z0-9-_][A-Za-z0-9-\._]*)"; +Readonly::Scalar our $attrNameRE => "(?:[A-Za-z_][A-Za-z0-9-_]*)"; +Readonly::Scalar our $projectNameRE => "(?:[A-Za-z_][A-Za-z0-9-_]*)"; +Readonly::Scalar our $jobsetNameRE => "(?:[A-Za-z_][A-Za-z0-9-_\.]*)"; +Readonly::Scalar our $jobNameRE => "(?:$attrNameRE(?:\\.$attrNameRE)*)"; +Readonly::Scalar our $systemRE => "(?:[a-z0-9_]+-[a-z0-9_]+)"; +Readonly::Scalar our $userNameRE => "(?:[a-z][a-z0-9_\.]*)"; +Readonly::Scalar our $inputNameRE => "(?:[A-Za-z_][A-Za-z0-9-_]*)"; sub parseJobsetName { diff --git a/src/lib/Hydra/Plugin/BitBucketPulls.pm b/src/lib/Hydra/Plugin/BitBucketPulls.pm index 5371d5f0..3a082ac9 100644 --- a/src/lib/Hydra/Plugin/BitBucketPulls.pm +++ b/src/lib/Hydra/Plugin/BitBucketPulls.pm @@ -5,7 +5,7 @@ use warnings; use parent 'Hydra::Plugin'; use HTTP::Request; use LWP::UserAgent; -use JSON; +use JSON::MaybeXS; use Hydra::Helper::CatalystUtils; use File::Temp; use POSIX qw(strftime); diff --git a/src/lib/Hydra/Plugin/BitBucketStatus.pm b/src/lib/Hydra/Plugin/BitBucketStatus.pm index 33e3bc03..b01956ec 100644 --- a/src/lib/Hydra/Plugin/BitBucketStatus.pm +++ b/src/lib/Hydra/Plugin/BitBucketStatus.pm @@ -4,7 +4,7 @@ use strict; use warnings; use parent 'Hydra::Plugin'; use HTTP::Request; -use JSON; +use JSON::MaybeXS; use LWP::UserAgent; use Hydra::Helper::CatalystUtils; diff --git a/src/lib/Hydra/Plugin/CircleCINotification.pm b/src/lib/Hydra/Plugin/CircleCINotification.pm index a2eb26a4..8c45a073 100644 --- a/src/lib/Hydra/Plugin/CircleCINotification.pm +++ b/src/lib/Hydra/Plugin/CircleCINotification.pm @@ -6,7 +6,7 @@ use parent 'Hydra::Plugin'; use HTTP::Request; use LWP::UserAgent; use Hydra::Helper::CatalystUtils; -use JSON; +use JSON::MaybeXS; sub isEnabled { my ($self) = @_; diff --git a/src/lib/Hydra/Plugin/GitInput.pm b/src/lib/Hydra/Plugin/GitInput.pm index 39a5cf83..99d397a6 100644 --- a/src/lib/Hydra/Plugin/GitInput.pm +++ b/src/lib/Hydra/Plugin/GitInput.pm @@ -118,7 +118,8 @@ sub fetchInput { $jobset->get_column('name'), $name); # give preference to the options from the input value - while (my ($opt_name, $opt_value) = each %{$options}) { + foreach my $opt_name (keys %{$options}) { + my $opt_value = $options->{$opt_name}; if ($opt_value =~ /^[+-]?\d+\z/) { $opt_value = int($opt_value); } diff --git a/src/lib/Hydra/Plugin/GiteaStatus.pm b/src/lib/Hydra/Plugin/GiteaStatus.pm index 567dfd09..426c93f5 100644 --- a/src/lib/Hydra/Plugin/GiteaStatus.pm +++ b/src/lib/Hydra/Plugin/GiteaStatus.pm @@ -5,7 +5,7 @@ use warnings; use parent 'Hydra::Plugin'; use HTTP::Request; -use JSON; +use JSON::MaybeXS; use LWP::UserAgent; use Hydra::Helper::CatalystUtils; use List::Util qw(max); diff --git a/src/lib/Hydra/Plugin/GithubPulls.pm b/src/lib/Hydra/Plugin/GithubPulls.pm index 393c6b73..db0e8d25 100644 --- a/src/lib/Hydra/Plugin/GithubPulls.pm +++ b/src/lib/Hydra/Plugin/GithubPulls.pm @@ -5,7 +5,7 @@ use warnings; use parent 'Hydra::Plugin'; use HTTP::Request; use LWP::UserAgent; -use JSON; +use JSON::MaybeXS; use Hydra::Helper::CatalystUtils; use File::Temp; use POSIX qw(strftime); diff --git a/src/lib/Hydra/Plugin/GithubRefs.pm b/src/lib/Hydra/Plugin/GithubRefs.pm index 2038ea47..7d6e303f 100644 --- a/src/lib/Hydra/Plugin/GithubRefs.pm +++ b/src/lib/Hydra/Plugin/GithubRefs.pm @@ -5,7 +5,7 @@ use warnings; use parent 'Hydra::Plugin'; use HTTP::Request; use LWP::UserAgent; -use JSON; +use JSON::MaybeXS; use Hydra::Helper::CatalystUtils; use File::Temp; use POSIX qw(strftime); diff --git a/src/lib/Hydra/Plugin/GithubStatus.pm b/src/lib/Hydra/Plugin/GithubStatus.pm index cda7426a..05a35ca2 100644 --- a/src/lib/Hydra/Plugin/GithubStatus.pm +++ b/src/lib/Hydra/Plugin/GithubStatus.pm @@ -4,7 +4,7 @@ use strict; use warnings; use parent 'Hydra::Plugin'; use HTTP::Request; -use JSON; +use JSON::MaybeXS; use LWP::UserAgent; use Hydra::Helper::CatalystUtils; use List::Util qw(max); diff --git a/src/lib/Hydra/Plugin/GitlabPulls.pm b/src/lib/Hydra/Plugin/GitlabPulls.pm index 3249ecf8..13bf1c46 100644 --- a/src/lib/Hydra/Plugin/GitlabPulls.pm +++ b/src/lib/Hydra/Plugin/GitlabPulls.pm @@ -19,7 +19,7 @@ use warnings; use parent 'Hydra::Plugin'; use HTTP::Request; use LWP::UserAgent; -use JSON; +use JSON::MaybeXS; use Hydra::Helper::CatalystUtils; use File::Temp; use POSIX qw(strftime); diff --git a/src/lib/Hydra/Plugin/GitlabStatus.pm b/src/lib/Hydra/Plugin/GitlabStatus.pm index d19877ed..9d6718d2 100644 --- a/src/lib/Hydra/Plugin/GitlabStatus.pm +++ b/src/lib/Hydra/Plugin/GitlabStatus.pm @@ -4,7 +4,7 @@ use strict; use warnings; use parent 'Hydra::Plugin'; use HTTP::Request; -use JSON; +use JSON::MaybeXS; use LWP::UserAgent; use Hydra::Helper::CatalystUtils; use List::Util qw(max); diff --git a/src/lib/Hydra/Plugin/RunCommand.pm b/src/lib/Hydra/Plugin/RunCommand.pm index b4abc4dd..38547fa2 100644 --- a/src/lib/Hydra/Plugin/RunCommand.pm +++ b/src/lib/Hydra/Plugin/RunCommand.pm @@ -4,7 +4,7 @@ use strict; use warnings; use parent 'Hydra::Plugin'; use experimental 'smartmatch'; -use JSON; +use JSON::MaybeXS; sub isEnabled { my ($self) = @_; @@ -74,7 +74,7 @@ sub makeJsonPayload { my $json = { event => $event, 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'), project => $build->get_column('project'), jobset => $build->get_column('jobset'), diff --git a/src/lib/Hydra/Plugin/S3Backup.pm b/src/lib/Hydra/Plugin/S3Backup.pm index a67082ec..98e79747 100644 --- a/src/lib/Hydra/Plugin/S3Backup.pm +++ b/src/lib/Hydra/Plugin/S3Backup.pm @@ -98,7 +98,8 @@ sub buildFinished { foreach my $reference (@{$refs}) { push @needed_paths, $reference; } - while (my ($compression_type, $configs) = each %compression_types) { + foreach my $compression_type (keys %compression_types) { + my $configs = $compression_types{$compression_type}; my @incomplete_buckets = (); # Don't do any work if all the buckets have this path foreach my $bucket_config (@{$configs}) { @@ -144,7 +145,8 @@ sub buildFinished { } # Upload narinfos - while (my ($compression_type, $infos) = each %narinfos) { + foreach my $compression_type (keys %narinfos) { + my $infos = $narinfos{$compression_type}; foreach my $bucket_config (@{$compression_types{$compression_type}}) { foreach my $info (@{$infos}) { my $bucket = $client->bucket( name => $bucket_config->{name} ); diff --git a/src/lib/Hydra/Plugin/SlackNotification.pm b/src/lib/Hydra/Plugin/SlackNotification.pm index 5320dd7b..21e2777c 100644 --- a/src/lib/Hydra/Plugin/SlackNotification.pm +++ b/src/lib/Hydra/Plugin/SlackNotification.pm @@ -6,7 +6,7 @@ use parent 'Hydra::Plugin'; use HTTP::Request; use LWP::UserAgent; use Hydra::Helper::CatalystUtils; -use JSON; +use JSON::MaybeXS; =head1 NAME diff --git a/src/lib/Hydra/Schema/Result/JobsetInputs.pm b/src/lib/Hydra/Schema/Result/JobsetInputs.pm index e714de26..c8a1e969 100644 --- a/src/lib/Hydra/Schema/Result/JobsetInputs.pm +++ b/src/lib/Hydra/Schema/Result/JobsetInputs.pm @@ -134,7 +134,7 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-26 12:02:36 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CkU+hbVTmhfOzQhkHJHCsg -use JSON; +use JSON::MaybeXS; sub as_json { my $self = shift; @@ -148,7 +148,7 @@ sub as_json { "value" => $input->value // "", # boolean_columns - "emailresponsible" => $self->get_column("emailresponsible") ? JSON::true : JSON::false, + "emailresponsible" => $self->get_column("emailresponsible") ? JSON::MaybeXS::true : JSON::MaybeXS::false, ); return \%json; diff --git a/src/lib/Hydra/Schema/Result/Jobsets.pm b/src/lib/Hydra/Schema/Result/Jobsets.pm index 8e3c1509..27d8a388 100644 --- a/src/lib/Hydra/Schema/Result/Jobsets.pm +++ b/src/lib/Hydra/Schema/Result/Jobsets.pm @@ -375,7 +375,7 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-26 12:02:36 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:iI44C3BFTo6IsS1tBwWYsg -use JSON; +use JSON::MaybeXS; =head2 builds @@ -423,8 +423,8 @@ sub as_json { "flake" => $self->get_column("flake") // "", # boolean_columns - "enableemail" => $self->get_column("enableemail") ? JSON::true : JSON::false, - "visible" => $self->get_column("hidden") ? JSON::false : JSON::true, + "enableemail" => $self->get_column("enableemail") ? JSON::MaybeXS::true : JSON::MaybeXS::false, + "visible" => $self->get_column("hidden") ? JSON::MaybeXS::false : JSON::MaybeXS::true, "inputs" => { map { $_->name => $_ } $self->jobsetinputs } ); diff --git a/src/lib/Hydra/Schema/Result/Projects.pm b/src/lib/Hydra/Schema/Result/Projects.pm index 441c70a9..9513d883 100644 --- a/src/lib/Hydra/Schema/Result/Projects.pm +++ b/src/lib/Hydra/Schema/Result/Projects.pm @@ -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 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nKVZ8ZNCZQQ52zbpDAaoQQ -use JSON; +use JSON::MaybeXS; sub as_json { my $self = shift; @@ -260,8 +260,8 @@ sub as_json { "owner" => $self->get_column("owner") // "", # boolean_columns - "enabled" => $self->get_column("enabled") ? JSON::true : JSON::false, - "hidden" => $self->get_column("hidden") ? JSON::true : JSON::false, + "enabled" => $self->get_column("enabled") ? JSON::MaybeXS::true : JSON::MaybeXS::false, + "hidden" => $self->get_column("hidden") ? JSON::MaybeXS::true : JSON::MaybeXS::false, "jobsets" => [ map { $_->name } $self->jobsets ] ); diff --git a/src/script/hydra-eval-jobset b/src/script/hydra-eval-jobset index 0f946562..c61ce226 100755 --- a/src/script/hydra-eval-jobset +++ b/src/script/hydra-eval-jobset @@ -15,7 +15,7 @@ use Hydra::Helper::Nix; use Hydra::Model::DB; use Hydra::Plugin; use Hydra::Schema; -use JSON; +use JSON::MaybeXS; use Net::Statsd; use Nix::Store; use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC); @@ -753,7 +753,8 @@ sub checkJobsetWrapped { if ($jobsetChanged) { # Create JobsetEvalMembers mappings. - while (my ($id, $x) = each %buildMap) { + foreach my $id (keys %buildMap) { + my $x = $buildMap{$id}; $ev->jobsetevalmembers->create({ build => $id, isnew => $x->{new} }); } @@ -762,7 +763,8 @@ sub checkJobsetWrapped { # builds for the same derivation, pick the one with the # shortest name. my %drvPathToId; - while (my ($id, $x) = each %buildMap) { + foreach my $id (keys %buildMap) { + my $x = $buildMap{$id}; my $y = $drvPathToId{$x->{drvPath}}; if (defined $y) { next if length $x->{jobName} > length $y->{jobName}; @@ -806,7 +808,8 @@ sub checkJobsetWrapped { # Wake up hydra-queue-runner. my $lowestId; - while (my ($id, $x) = each %buildMap) { + foreach my $id (keys %buildMap) { + my $x = $buildMap{$id}; $lowestId = $id if $x->{new} && (!defined $lowestId || $id < $lowestId); } $notifyAdded->execute($lowestId) if defined $lowestId; diff --git a/src/script/hydra-send-stats b/src/script/hydra-send-stats index 85807631..596c622a 100755 --- a/src/script/hydra-send-stats +++ b/src/script/hydra-send-stats @@ -6,7 +6,7 @@ use utf8; use Hydra::Helper::Nix; use Net::Statsd; use File::Slurper qw(read_text); -use JSON; +use JSON::MaybeXS; use Getopt::Long qw(:config gnu_getopt); STDERR->autoflush(1); diff --git a/t/Controller/Admin/clear-queue-non-current.t b/t/Controller/Admin/clear-queue-non-current.t index 630abbdc..4669fb73 100644 --- a/t/Controller/Admin/clear-queue-non-current.t +++ b/t/Controller/Admin/clear-queue-non-current.t @@ -1,7 +1,7 @@ use strict; use warnings; use Setup; -use JSON qw(decode_json encode_json); +use JSON::MaybeXS qw(decode_json encode_json); use File::Copy; my %ctx = test_init( diff --git a/t/Controller/Build/cancel.t b/t/Controller/Build/cancel.t index 5dc5ba8a..b2afc074 100644 --- a/t/Controller/Build/cancel.t +++ b/t/Controller/Build/cancel.t @@ -2,7 +2,7 @@ use feature 'unicode_strings'; use strict; use warnings; use Setup; -use JSON qw(decode_json encode_json); +use JSON::MaybeXS qw(decode_json encode_json); my %ctx = test_init(); diff --git a/t/Controller/Build/constituents.t b/t/Controller/Build/constituents.t index ea1b419d..93b4a491 100644 --- a/t/Controller/Build/constituents.t +++ b/t/Controller/Build/constituents.t @@ -1,7 +1,7 @@ use strict; use warnings; use Setup; -use JSON qw(decode_json encode_json); +use JSON::MaybeXS qw(decode_json encode_json); use Data::Dumper; use URI; my %ctx = test_init(); diff --git a/t/Controller/Build/restart.t b/t/Controller/Build/restart.t index 75904ba4..9a993a11 100644 --- a/t/Controller/Build/restart.t +++ b/t/Controller/Build/restart.t @@ -2,7 +2,7 @@ use feature 'unicode_strings'; use strict; use warnings; use Setup; -use JSON qw(decode_json encode_json); +use JSON::MaybeXS qw(decode_json encode_json); my %ctx = test_init(); diff --git a/t/Controller/Jobset/channel.t b/t/Controller/Jobset/channel.t index 322abc92..7fa7498e 100644 --- a/t/Controller/Jobset/channel.t +++ b/t/Controller/Jobset/channel.t @@ -4,7 +4,7 @@ use warnings; use Setup; use IO::Uncompress::Bunzip2 qw(bunzip2); use Archive::Tar; -use JSON qw(decode_json); +use JSON::MaybeXS qw(decode_json); use Data::Dumper; my %ctx = test_init( use_external_destination_store => 0 diff --git a/t/Controller/Jobset/http.t b/t/Controller/Jobset/http.t index 6b5788c5..32b3a681 100644 --- a/t/Controller/Jobset/http.t +++ b/t/Controller/Jobset/http.t @@ -2,7 +2,7 @@ use feature 'unicode_strings'; use strict; use warnings; use Setup; -use JSON qw(decode_json encode_json); +use JSON::MaybeXS qw(decode_json encode_json); my %ctx = test_init(); @@ -47,7 +47,7 @@ subtest 'Create new jobset "job" as flake type' => sub { Cookie => $cookie, Content => encode_json({ enabled => 2, - visible => JSON::true, + visible => JSON::MaybeXS::true, name => "job", type => 1, description => "test jobset", @@ -72,12 +72,12 @@ subtest 'Read newly-created jobset "job"' => sub { description => "test jobset", emailoverride => "", enabled => 2, - enableemail => JSON::false, + enableemail => JSON::MaybeXS::false, errortime => undef, errormsg => "", fetcherrormsg => "", flake => "github:nixos/nix", - visible => JSON::true, + visible => JSON::MaybeXS::true, inputs => {}, keepnr => 3, lastcheckedtime => undef, @@ -100,7 +100,7 @@ subtest 'Update jobset "job" to legacy type' => sub { Cookie => $cookie, Content => encode_json({ enabled => 3, - visible => JSON::true, + visible => JSON::MaybeXS::true, name => "job", type => 0, nixexprinput => "ofborg", @@ -130,17 +130,17 @@ subtest 'Update jobset "job" to legacy type' => sub { description => "test jobset", emailoverride => "", enabled => 3, - enableemail => JSON::false, + enableemail => JSON::MaybeXS::false, errortime => undef, errormsg => "", fetcherrormsg => "", flake => "", - visible => JSON::true, + visible => JSON::MaybeXS::true, inputs => { ofborg => { name => "ofborg", type => "git", - emailresponsible => JSON::false, + emailresponsible => JSON::MaybeXS::false, 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, Content => encode_json({ enabled => 3, - visible => JSON::true, + visible => JSON::MaybeXS::true, name => "job", type => 0, nixexprinput => "ofborg", diff --git a/t/Controller/JobsetEval/cancel.t b/t/Controller/JobsetEval/cancel.t index 03f23e05..5b848117 100644 --- a/t/Controller/JobsetEval/cancel.t +++ b/t/Controller/JobsetEval/cancel.t @@ -2,7 +2,7 @@ use feature 'unicode_strings'; use strict; use warnings; use Setup; -use JSON qw(decode_json encode_json); +use JSON::MaybeXS qw(decode_json encode_json); my %ctx = test_init(); diff --git a/t/Controller/JobsetEval/restart.t b/t/Controller/JobsetEval/restart.t index c5957cf7..30581987 100644 --- a/t/Controller/JobsetEval/restart.t +++ b/t/Controller/JobsetEval/restart.t @@ -2,7 +2,7 @@ use feature 'unicode_strings'; use strict; use warnings; use Setup; -use JSON qw(decode_json encode_json); +use JSON::MaybeXS qw(decode_json encode_json); my %ctx = test_init(); diff --git a/t/Controller/Root/narinfo.t b/t/Controller/Root/narinfo.t index 297d336b..0a473a03 100644 --- a/t/Controller/Root/narinfo.t +++ b/t/Controller/Root/narinfo.t @@ -2,7 +2,7 @@ use strict; use warnings; use Setup; use Data::Dumper; -use JSON qw(decode_json); +use JSON::MaybeXS qw(decode_json); my %ctx = test_init( # Without this, the test will fail because a `file:` store is not treated as a # local store by `isLocalStore` in src/lib/Hydra/Helper/Nix.pm, and any diff --git a/t/Controller/metrics.t b/t/Controller/metrics.t index 325efad9..e851abdb 100644 --- a/t/Controller/metrics.t +++ b/t/Controller/metrics.t @@ -2,7 +2,7 @@ use feature 'unicode_strings'; use strict; use warnings; use Setup; -use JSON qw(decode_json encode_json); +use JSON::MaybeXS qw(decode_json encode_json); my %ctx = test_init(); diff --git a/t/Controller/projects.t b/t/Controller/projects.t index 068f566b..df1290aa 100644 --- a/t/Controller/projects.t +++ b/t/Controller/projects.t @@ -2,7 +2,7 @@ use feature 'unicode_strings'; use strict; use warnings; use Setup; -use JSON qw(decode_json encode_json); +use JSON::MaybeXS qw(decode_json encode_json); my %ctx = test_init(); @@ -45,8 +45,8 @@ subtest "Read project 'tests'" => sub { is(decode_json($projectinfo->content), { description => "", displayname => "Tests", - enabled => JSON::true, - hidden => JSON::false, + enabled => JSON::MaybeXS::true, + hidden => JSON::MaybeXS::false, homepage => "", jobsets => [], name => "tests", @@ -61,8 +61,8 @@ subtest "Transitioning from declarative project to normal" => sub { Content_Type => 'application/json', Cookie => $cookie, Content => encode_json({ - enabled => JSON::true, - visible => JSON::true, + enabled => JSON::MaybeXS::true, + visible => JSON::MaybeXS::true, name => "tests", displayname => "Tests", declarative => { @@ -84,8 +84,8 @@ subtest "Transitioning from declarative project to normal" => sub { is(decode_json($projectinfo->content), { description => "", displayname => "Tests", - enabled => JSON::true, - hidden => JSON::false, + enabled => JSON::MaybeXS::true, + hidden => JSON::MaybeXS::false, homepage => "", jobsets => [".jobsets"], name => "tests", @@ -104,8 +104,8 @@ subtest "Transitioning from declarative project to normal" => sub { Content_Type => 'application/json', Cookie => $cookie, Content => encode_json({ - enabled => JSON::true, - visible => JSON::true, + enabled => JSON::MaybeXS::true, + visible => JSON::MaybeXS::true, name => "tests", displayname => "Tests", declarative => { @@ -127,8 +127,8 @@ subtest "Transitioning from declarative project to normal" => sub { is(decode_json($projectinfo->content), { description => "", displayname => "Tests", - enabled => JSON::true, - hidden => JSON::false, + enabled => JSON::MaybeXS::true, + hidden => JSON::MaybeXS::false, homepage => "", jobsets => [], name => "tests", diff --git a/t/Helper/attributeset.t b/t/Helper/attributeset.t index 112cd9be..9c6c7b02 100644 --- a/t/Helper/attributeset.t +++ b/t/Helper/attributeset.t @@ -31,8 +31,9 @@ $attrs->registerValue("foo"); $attrs->registerValue("bar.baz.tux"); $attrs->registerValue("bar.baz.bux.foo.bar.baz"); +my @enumerated = $attrs->enumerate(); is( - $attrs->enumerate(), + \@enumerated, [ # "foo": skipped since we're registering values, and we # only want to track nested attribute sets. diff --git a/t/api-test.t b/t/api-test.t index 3fee0264..bd26d487 100644 --- a/t/api-test.t +++ b/t/api-test.t @@ -1,7 +1,7 @@ use strict; use warnings; use Setup; -use JSON; +use JSON::MaybeXS; use File::Copy; my %ctx = test_init( diff --git a/t/plugins/RunCommand/basic.t b/t/plugins/RunCommand/basic.t index 4771e6af..0dfcd79d 100644 --- a/t/plugins/RunCommand/basic.t +++ b/t/plugins/RunCommand/basic.t @@ -1,7 +1,7 @@ use feature 'unicode_strings'; use strict; use warnings; -use JSON; +use JSON::MaybeXS; use Setup; my %ctx = test_init( @@ -42,7 +42,7 @@ my $dat = do { open(my $json_fh, "<", $filename) or die("Can't open \"$filename\": $!\n"); local $/; - my $json = JSON->new; + my $json = JSON::MaybeXS->new; $json->decode(<$json_fh>) }; diff --git a/t/plugins/RunCommand/json.t b/t/plugins/RunCommand/json.t index f45ab7a8..e0221b24 100644 --- a/t/plugins/RunCommand/json.t +++ b/t/plugins/RunCommand/json.t @@ -1,5 +1,6 @@ use strict; use warnings; +use JSON::MaybeXS; use Setup; 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->{buildStatus}, 0, "The build status 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->{jobset}, "basic", "The jobset matches."); is($dat->{job}, "metrics", "The job matches."); diff --git a/t/plugins/gitea.t b/t/plugins/gitea.t index 56601b95..27fe1173 100644 --- a/t/plugins/gitea.t +++ b/t/plugins/gitea.t @@ -1,7 +1,7 @@ use feature 'unicode_strings'; use strict; use warnings; -use JSON; +use JSON::MaybeXS; use Setup; my %ctx = test_init( diff --git a/t/queue-runner/notifications.t b/t/queue-runner/notifications.t index f9d36361..83646460 100644 --- a/t/queue-runner/notifications.t +++ b/t/queue-runner/notifications.t @@ -1,7 +1,7 @@ use feature 'unicode_strings'; use strict; use warnings; -use JSON; +use JSON::MaybeXS; use Setup; my $binarycachedir = File::Temp->newdir(); diff --git a/t/setup-notifications-jobset.pl b/t/setup-notifications-jobset.pl index 70998845..7bdb6d1c 100644 --- a/t/setup-notifications-jobset.pl +++ b/t/setup-notifications-jobset.pl @@ -1,7 +1,7 @@ use strict; use warnings; use LWP::UserAgent; -use JSON; +use JSON::MaybeXS; my $ua = LWP::UserAgent->new; $ua->cookie_jar({});