From b78b7ebfdb1d2d819cb68476ce1f895bcb8a8083 Mon Sep 17 00:00:00 2001 From: Natalie Rose Date: Sat, 29 Aug 2026 16:32:26 +1000 Subject: [PATCH] Smartmatch cleanup --- bin/check_for_total_victory.pl | 5 +- bin/clean_up_battle_log.pl | 1 - bin/clean_up_empires.pl | 1 - bin/clean_up_game_over.pl | 1 - bin/clean_up_mail.pl | 1 - bin/clean_up_market.pl | 1 - bin/convert_ships_to_fleets.pl | 1 - bin/delete_all_trades.pl | 1 - bin/deploy.pl | 16 +-- bin/lce_starterpacks.pl | 1 - bin/record_rpc.pl | 1 - bin/saben/orig_send_attack.pl | 1 - bin/schedule_building.pl | 1 - bin/schedule_ship_arrival.pl | 1 - bin/summarize_economy.pl | 2 +- bin/util/check_spy_count.pl | 1 - bin/util/diffdb.pl | 4 +- bin/util/move_to_center.pl | 4 +- bin/util/new_starters.pl | 4 +- bin/util/normalize_spies.pl | 3 +- cpanfile | 9 +- cpanfile.snapshot | 123 ++++++++++++++++-- lib/Lacuna/DB/Result/Alliance.pm | 4 +- lib/Lacuna/DB/Result/Building.pm | 4 +- lib/Lacuna/DB/Result/Building/Archaeology.pm | 5 +- .../DB/Result/Building/DistributionCenter.pm | 4 +- lib/Lacuna/DB/Result/Building/GeneticsLab.pm | 4 +- lib/Lacuna/DB/Result/Building/LCOTa.pm | 4 +- .../DB/Result/Building/MercenariesGuild.pm | 4 +- lib/Lacuna/DB/Result/Building/SSLa.pm | 4 +- lib/Lacuna/DB/Result/Building/Stockpile.pm | 10 +- lib/Lacuna/DB/Result/Building/Transporter.pm | 6 +- lib/Lacuna/DB/Result/Empire.pm | 1 - lib/Lacuna/DB/Result/Fleet.pm | 9 +- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 10 +- lib/Lacuna/DB/Result/Map/Star.pm | 6 +- lib/Lacuna/DB/Result/Mission.pm | 3 +- lib/Lacuna/DB/Result/Plan.pm | 10 +- lib/Lacuna/DB/Result/Propositions/FireBfg.pm | 4 +- lib/Lacuna/DB/Result/Ships.pm | 9 +- lib/Lacuna/DB/Result/Spies.pm | 20 ++- lib/Lacuna/RPC/Body.pm | 17 ++- lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 4 +- lib/Lacuna/RPC/Building/PoliceStation.pm | 10 +- lib/Lacuna/RPC/Building/Shipyard.pm | 6 +- lib/Lacuna/RPC/Building/SpacePort.pm | 23 ++-- lib/Lacuna/RPC/Building/Trade.pm | 5 +- lib/Lacuna/RPC/Empire.pm | 4 +- lib/Lacuna/RPC/EssentiaCode.pm | 4 +- lib/Lacuna/RPC/Inbox.pm | 6 +- lib/Lacuna/RPC/Stats.pm | 14 +- lib/Lacuna/Role/Ship/Trade.pm | 1 - lib/Lacuna/Role/Trader.pm | 18 ++- lib/Lacuna/Role/TraderRpc.pm | 5 +- lib/Lacuna/Web/Admin.pm | 11 +- lib/Lacuna/Web/MissionCurator.pm | 1 - t/030_Body.t | 13 +- t/370_Medals.t | 3 +- 58 files changed, 268 insertions(+), 181 deletions(-) diff --git a/bin/check_for_total_victory.pl b/bin/check_for_total_victory.pl index 00bafd96..d6d49493 100644 --- a/bin/check_for_total_victory.pl +++ b/bin/check_for_total_victory.pl @@ -7,7 +7,7 @@ use Lacuna::Util qw(format_date); use Getopt::Long; use List::Util qw(max shuffle); use UUID::Tiny ':std'; -use experimental 'smartmatch'; +use Switch::Right; $|=1; our $quiet; GetOptions( @@ -95,7 +95,8 @@ sub start_new_twenty_stars { for my $x ( $x[0] .. $x[1] ) { for my $y ( $y[0] .. $y[1] ) { my $zone = join '|', $x, $y; - if ( $zone ~~ $old_zones || $zone ~~ $skip_zones ) { + if ( (ref $old_zones && smartmatch($zone, any => $old_zones)) + || (ref $skip_zones && smartmatch($zone, any => $skip_zones)) ) { out("Skipping $zone"); next; } diff --git a/bin/clean_up_battle_log.pl b/bin/clean_up_battle_log.pl index 70a5d581..e60990a5 100644 --- a/bin/clean_up_battle_log.pl +++ b/bin/clean_up_battle_log.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/clean_up_empires.pl b/bin/clean_up_empires.pl index 6c9d8b50..85c1af86 100644 --- a/bin/clean_up_empires.pl +++ b/bin/clean_up_empires.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/clean_up_game_over.pl b/bin/clean_up_game_over.pl index cd877d3d..c7b961ba 100644 --- a/bin/clean_up_game_over.pl +++ b/bin/clean_up_game_over.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/clean_up_mail.pl b/bin/clean_up_mail.pl index abdfbf53..533dab2a 100644 --- a/bin/clean_up_mail.pl +++ b/bin/clean_up_mail.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/clean_up_market.pl b/bin/clean_up_market.pl index e3427302..607a7cba 100644 --- a/bin/clean_up_market.pl +++ b/bin/clean_up_market.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/convert_ships_to_fleets.pl b/bin/convert_ships_to_fleets.pl index 26ec66e9..0606cd0d 100644 --- a/bin/convert_ships_to_fleets.pl +++ b/bin/convert_ships_to_fleets.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/delete_all_trades.pl b/bin/delete_all_trades.pl index 24224cbb..4d7c109d 100644 --- a/bin/delete_all_trades.pl +++ b/bin/delete_all_trades.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/deploy.pl b/bin/deploy.pl index a94dd213..d5e70cea 100755 --- a/bin/deploy.pl +++ b/bin/deploy.pl @@ -82,8 +82,7 @@ sub run { $git->pull; my @updated_files = $git->diff({name_only => 1}, $old_rev, 'HEAD'); - given ($repo) { - when ('Lacuna-Web-Client') { + if ($repo eq 'Lacuna-Web-Client') { my $bucket = $branch_config->{bucket}; my $s3bucket = $s3->bucket($bucket) or die $s3->err . ": " . $s3->errstr; my ($new_rev) = $git->rev_parse({short => 1}, 'HEAD'); @@ -151,11 +150,11 @@ END_TEXT } $s3bucket->delete_key($file); } - } - when ('Lacuna-Server') { + } + elsif ($repo eq 'Lacuna-Server') { # pull already done locally - } - when ('Lacuna-Server-Open') { + } + elsif ($repo eq 'Lacuna-Server-Open') { my $restart_server = 0; # Reboot code if ($branch eq "pt-reboot") { @@ -175,8 +174,8 @@ END_TEXT chdir('/data/Lacuna-Server-Private/bin'); system("./startqa.sh"); } - } - when ('Lacuna-Assets') { + } + elsif ($repo eq 'Lacuna-Assets') { my $bucket = $branch_config->{bucket}; my $s3bucket = $s3->bucket($bucket); for my $file (@updated_files) { @@ -201,7 +200,6 @@ END_TEXT }, ) or die $s3->err . ": " . $s3->errstr; } - } } } diff --git a/bin/lce_starterpacks.pl b/bin/lce_starterpacks.pl index bdf96a89..3d627a17 100644 --- a/bin/lce_starterpacks.pl +++ b/bin/lce_starterpacks.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/record_rpc.pl b/bin/record_rpc.pl index 465af64c..8c93bff0 100644 --- a/bin/record_rpc.pl +++ b/bin/record_rpc.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/saben/orig_send_attack.pl b/bin/saben/orig_send_attack.pl index dcad20e0..6ec56b9a 100644 --- a/bin/saben/orig_send_attack.pl +++ b/bin/saben/orig_send_attack.pl @@ -6,7 +6,6 @@ use Lacuna; use Lacuna::Util qw(randint format_date); use Getopt::Long; use AnyEvent; -use experimental 'smartmatch'; $|=1; our $quiet; our $randomize; diff --git a/bin/schedule_building.pl b/bin/schedule_building.pl index 0bd1d6a3..7254413b 100644 --- a/bin/schedule_building.pl +++ b/bin/schedule_building.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/schedule_ship_arrival.pl b/bin/schedule_ship_arrival.pl index 6c457426..576d976c 100644 --- a/bin/schedule_ship_arrival.pl +++ b/bin/schedule_ship_arrival.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/summarize_economy.pl b/bin/summarize_economy.pl index 19acc7a4..9b92a629 100644 --- a/bin/summarize_economy.pl +++ b/bin/summarize_economy.pl @@ -7,7 +7,7 @@ use Lacuna::Util qw(randint format_date); use Getopt::Long; use DateTime; use DateTime::Format::Strptime; -use feature "switch"; +use Switch::Right; $|=1; diff --git a/bin/util/check_spy_count.pl b/bin/util/check_spy_count.pl index a517633b..4d6201a8 100644 --- a/bin/util/check_spy_count.pl +++ b/bin/util/check_spy_count.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; diff --git a/bin/util/diffdb.pl b/bin/util/diffdb.pl index 153a6cf8..0fcf846c 100644 --- a/bin/util/diffdb.pl +++ b/bin/util/diffdb.pl @@ -4,7 +4,7 @@ use 5.010; use DBI; use Config::JSON; use Text::Diff; -use experimental 'smartmatch'; +use Switch::Right; my $config = Config::JSON->new('/home/lacuna/server/etc/lacuna.conf'); my $dev = DBI->connect($config->get('db/dsn'), $config->get('db/username'), $config->get('db/password')); my $prod = DBI->connect('DBI:mysql:prod', $config->get('db/username'), $config->get('db/password')); @@ -15,7 +15,7 @@ foreach my $table_name (@dev_tables) { say "TABLE: ".$table_name; my $dev_table = get_table_definition($dev, $table_name); my $prod_table = ''; - if ($table_name ~~ \@prod_tables) { + if (smartmatch($table_name, any => \@prod_tables)) { $prod_table = get_table_definition($prod, $table_name); } say diff \$prod_table, \$dev_table; diff --git a/bin/util/move_to_center.pl b/bin/util/move_to_center.pl index 0a576ea2..e1654b10 100644 --- a/bin/util/move_to_center.pl +++ b/bin/util/move_to_center.pl @@ -6,7 +6,7 @@ use Lacuna; use Lacuna::Util qw(randint format_date); use Getopt::Long; use List::MoreUtils qw(uniq); -use experimental 'smartmatch'; +use Switch::Right; $|=1; our $quiet; GetOptions( @@ -55,7 +55,7 @@ my @stars_to_NOT_displace = $bodies->search({ my @stars_in_zone = $stars->search({zone => '0|0'})->get_column('id')->all; my @stars_to_displace; foreach my $star (@stars_in_zone) { - next if $star ~~ \@stars_to_NOT_displace; + next if smartmatch($star, any => \@stars_to_NOT_displace); push @stars_to_displace, $star; } diff --git a/bin/util/new_starters.pl b/bin/util/new_starters.pl index 7f69228e..3c18e35b 100644 --- a/bin/util/new_starters.pl +++ b/bin/util/new_starters.pl @@ -6,7 +6,7 @@ use Lacuna::DB; use Lacuna; use Lacuna::Util qw(randint format_date); use Getopt::Long; -use experimental 'smartmatch'; +use Switch::Right; $|=1; our $quiet; GetOptions( @@ -34,7 +34,7 @@ my $old_s = 0; my $new_s = 0; my $unch = 0; foreach my $id (@planets) { my $planet = $planets_rs->find($id); next unless ($planet->get_type eq 'habitable planet'); - next unless ($planet->zone ~~ ['1|1','1|-1','-1|1','-1|-1','0|0','0|1','1|0','-1|0','0|-1']); + next unless (smartmatch($planet->zone, any => ['1|1','1|-1','-1|1','-1|-1','0|0','0|1','1|0','-1|0','0|-1'])); my $orbit = $planet->orbit; my $start_val = 80 - sqrt($planet->y**2 + $planet->x**2)/10; diff --git a/bin/util/normalize_spies.pl b/bin/util/normalize_spies.pl index 60b1facc..0296dc64 100644 --- a/bin/util/normalize_spies.pl +++ b/bin/util/normalize_spies.pl @@ -1,6 +1,5 @@ use 5.010; use strict; -use feature "switch"; use lib '/home/lacuna/server/lib'; use Lacuna::DB; use Lacuna; @@ -13,7 +12,7 @@ GetOptions( 'quiet' => \$quiet, ); -die "Not a good idea to run now." +die "Not a good idea to run now."; # Worked well, except it didn't do anything with spy shuttles that were in orbit. out('Started'); diff --git a/cpanfile b/cpanfile index f86092c0..5ad80770 100644 --- a/cpanfile +++ b/cpanfile @@ -8,8 +8,10 @@ # and commit both cpanfile and cpanfile.snapshot together. The Docker build # installs strictly from the snapshot (`carton install --deployment`). # -# Perl 5.40. `given`/`when`/`~~` smartmatch is retained (deprecated, still works) -# — do not move past 5.40 without removing it first (see the upgrade plan). +# Perl 5.40. Core `given`/`when`/`default` and the `~~` smartmatch operator have +# been removed from this codebase (un-silenceable deprecation warnings on 5.40; +# gone entirely in 5.42). `given`/`when`/`default` and an explicit `smartmatch()` +# now come from Switch::Right (see `requires 'Switch::Right'` below). # --- Version pins (deliberate — keep the comment explaining why) ------------ @@ -138,6 +140,9 @@ requires 'Text::WagnerFischer'; requires 'Text::Xslate'; requires 'Regexp::Common'; requires 'URI::Encode'; +# Modern replacement for core given/when/default + the ~~ smartmatch operator +# (both removed from this codebase — see the header comment). Needs Perl v5.36+. +requires 'Switch::Right'; requires 'List::Util'; requires 'List::MoreUtils'; requires 'List::Util::WeightedChoice'; diff --git a/cpanfile.snapshot b/cpanfile.snapshot index a4a27177..3ced9061 100644 --- a/cpanfile.snapshot +++ b/cpanfile.snapshot @@ -15,6 +15,12 @@ DISTRIBUTIONS Algorithm::Diff::_impl 1.201 requirements: ExtUtils::MakeMaker 0 + Algorithm-FastPermute-0.999 + pathname: R/RO/ROBIN/Algorithm-FastPermute-0.999.tar.gz + provides: + Algorithm::FastPermute 0.999 + requirements: + ExtUtils::MakeMaker 0 Alien-Build-2.84 pathname: P/PL/PLICEASE/Alien-Build-2.84.tar.gz provides: @@ -3045,6 +3051,14 @@ DISTRIBUTIONS requirements: ExtUtils::MakeMaker 6.17 perl 5.006001 + ExtUtils-CChecker-0.12 + pathname: P/PE/PEVANS/ExtUtils-CChecker-0.12.tar.gz + provides: + ExtUtils::CChecker 0.12 + requirements: + ExtUtils::CBuilder 0 + Module::Build 0.4004 + perl 5.014 ExtUtils-Config-0.010 pathname: L/LE/LEONT/ExtUtils-Config-0.010.tar.gz provides: @@ -3427,17 +3441,6 @@ DISTRIBUTIONS HTTP::Date 0 Module::Build::Tiny 0.035 perl 5.008001 - HTTP-Lite-2.44 - pathname: N/NE/NEILB/HTTP-Lite-2.44.tar.gz - provides: - HTTP::Lite 2.44 - requirements: - ExtUtils::MakeMaker 0 - Fcntl 0 - Socket 1.3 - perl 5.005 - strict 0 - warnings 0 HTTP-Message-7.04 pathname: O/OA/OALDERS/HTTP-Message-7.04.tar.gz provides: @@ -3693,6 +3696,19 @@ DISTRIBUTIONS ExtUtils::MakeMaker 6.52 Types::Serialiser 0 common::sense 0 + Keyword-Simple-0.04 + pathname: M/MA/MAUKE/Keyword-Simple-0.04.tar.gz + provides: + Keyword::Simple 0.04 + requirements: + Carp 0 + ExtUtils::MakeMaker 0 + File::Find 0 + File::Spec 0 + XSLoader 0 + perl 5.012000 + strict 0 + warnings 0 LWP-MediaTypes-6.04 pathname: O/OA/OALDERS/LWP-MediaTypes-6.04.tar.gz provides: @@ -4986,6 +5002,20 @@ DISTRIBUTIONS Scalar::Util 1.14 XSLoader 0.02 perl 5.010001 + Multi-Dispatch-0.000006 + pathname: D/DC/DCONWAY/Multi-Dispatch-0.000006.tar.gz + provides: + Multi::Dispatch 0.000006 + Multi::Dispatch::Warning 0.000006 + requirements: + Algorithm::FastPermute 0 + Data::Dump 0 + ExtUtils::MakeMaker 0 + Keyword::Simple 0.04 + PPR 0.001004 + Test::More 0 + Type::Tiny 0 + perl 5.022 Net-Amazon-S3-0.992 pathname: B/BA/BARNEY/Net-Amazon-S3-0.992.tar.gz provides: @@ -5422,6 +5452,25 @@ DISTRIBUTIONS requirements: ExtUtils::MakeMaker 0 Test::More 0 + Object-Pad-0.825 + pathname: P/PE/PEVANS/Object-Pad-0.825.tar.gz + provides: + Object::Pad 0.825 + Object::Pad::ExtensionBuilder 0.825 + Object::Pad::MOP::Class 0.825 + Object::Pad::MOP::Field 0.825 + Object::Pad::MOP::FieldAttr 0.825 + Object::Pad::MOP::Method 0.825 + Object::Pad::MetaFunctions 0.825 + requirements: + ExtUtils::CBuilder 0 + File::ShareDir 1.00 + Module::Build 0.4004 + XS::Parse::Keyword 0.47 + XS::Parse::Keyword::Builder 0.48 + XS::Parse::Sublike 0.35 + XS::Parse::Sublike::Builder 0.35 + perl 5.022 Ouch-0.0501 pathname: R/RI/RIZEN/Ouch-0.0501.tar.gz provides: @@ -5444,6 +5493,17 @@ DISTRIBUTIONS POSIX 0 Time::Local 0 perl 5.008001 + PPR-0.001010 + pathname: D/DC/DCONWAY/PPR-0.001010.tar.gz + provides: + PPR 0.001010 + PPR::ERROR 0.001010 + PPR::X 0.001009 + PPR::X::ERROR 0.001009 + requirements: + ExtUtils::MakeMaker 0 + Test::More 0 + perl 5.010 Package-DeprecationManager-0.18 pathname: D/DR/DROLSKY/Package-DeprecationManager-0.18.tar.gz provides: @@ -6558,6 +6618,20 @@ DISTRIBUTIONS perl 5.006 strict 0 warnings 0 + Switch-Right-0.000006 + pathname: D/DC/DCONWAY/Switch-Right-0.000006.tar.gz + provides: + Switch::Right 0.000006 + requirements: + B::Deparse 0 + ExtUtils::MakeMaker 0 + Keyword::Simple 0 + Multi::Dispatch 0 + Object::Pad 0 + PPR 0.001009 + Test2::V0 0 + Type::Tiny 0 + perl 5.036 Symbol-Util-0.0203 pathname: D/DE/DEXTER/Symbol-Util-0.0203.tar.gz provides: @@ -7847,7 +7921,7 @@ DISTRIBUTIONS XML::TreePP 0.43 requirements: ExtUtils::MakeMaker 0 - HTTP::Lite 0 + LWP 5.811 Test::More 0 XS-Install-1.5.2 pathname: S/SY/SYBER/XS-Install-1.5.2.tar.gz @@ -7861,6 +7935,31 @@ DISTRIBUTIONS ExtUtils::ParseXS 3.24 PkgConfig 0.24 perl 5.010000 + XS-Parse-Keyword-0.49 + pathname: P/PE/PEVANS/XS-Parse-Keyword-0.49.tar.gz + provides: + XS::Parse::Infix 0.49 + XS::Parse::Infix::Builder 0.49 + XS::Parse::Keyword 0.49 + XS::Parse::Keyword::Builder 0.49 + requirements: + ExtUtils::CBuilder 0 + ExtUtils::CChecker 0.11 + ExtUtils::ParseXS 3.16 + File::ShareDir 1.00 + Module::Build 0.4004 + perl 5.014 + XS-Parse-Sublike-0.41 + pathname: P/PE/PEVANS/XS-Parse-Sublike-0.41.tar.gz + provides: + Sublike::Extended 0.41 + XS::Parse::Sublike 0.41 + XS::Parse::Sublike::Builder 0.41 + requirements: + ExtUtils::CBuilder 0 + File::ShareDir 1.00 + Module::Build 0.4004 + perl 5.016 XString-0.005 pathname: A/AT/ATOOMIC/XString-0.005.tar.gz provides: diff --git a/lib/Lacuna/DB/Result/Alliance.pm b/lib/Lacuna/DB/Result/Alliance.pm index b43a9d8b..afe2a1e0 100644 --- a/lib/Lacuna/DB/Result/Alliance.pm +++ b/lib/Lacuna/DB/Result/Alliance.pm @@ -7,7 +7,7 @@ extends 'Lacuna::DB::Result'; use Lacuna::Util qw(format_date); use Lacuna::Constants qw(FOOD_TYPES ORE_TYPES); use DateTime; -use experimental 'smartmatch'; +use Switch::Right; __PACKAGE__->table('alliance'); __PACKAGE__->add_columns( @@ -53,7 +53,7 @@ sub check_donation { my ($self, $body, $donation) = @_; my @valid = ('water','energy',FOOD_TYPES,ORE_TYPES); foreach my $resource (keys %{$donation}) { - unless ($resource ~~ \@valid) { + unless (smartmatch($resource, any => \@valid)) { confess [1010, 'The stash cannot hold '.$resource.'.']; } if ($donation->{$resource} < 0) { diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index 2fffa229..19b77f18 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -10,7 +10,7 @@ use List::MoreUtils qw(first_index); use Lacuna::Util qw(format_date); -use experimental 'smartmatch'; +use Switch::Right; __PACKAGE__->load_components('DynamicSubclass'); __PACKAGE__->table('building'); @@ -769,7 +769,7 @@ sub is_not_max_level { $max_level += ($self->body->empire->university_level - 25); } if ($self->level >= $max_level && - 'Resources' ~~ [ $self->build_tags] && (!('Storage' ~~ [$self->build_tags]) + smartmatch('Resources', any => [ $self->build_tags]) && (!(smartmatch('Storage', any => [$self->build_tags])) || $self->isa('Lacuna::DB::Result::Building::Waste::Exchanger'))) { # resource buildings except storage buildings (treat a Waste Exchanger as if it were not a storage building) my $stockpile = $self->body->get_building_of_class('Lacuna::DB::Result::Building::Stockpile'); diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 207c6545..8d8fc23f 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -7,8 +7,7 @@ extends 'Lacuna::DB::Result::Building'; use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES); use Lacuna::Util qw(randint random_element); use Clone qw(clone); -use feature 'switch'; -use experimental 'smartmatch'; +use Switch::Right; around 'build_tags' => sub { my ($orig, $class) = @_; @@ -617,7 +616,7 @@ sub can_search_for_glyph { unless ($self->effective_level > 0) { confess [1010, 'The Archaeology Ministry is not finished building yet.']; } - unless ($ore ~~ [ ORE_TYPES ]) { + unless (smartmatch($ore, any => [ ORE_TYPES ])) { confess [1005, $ore.' is not a valid type of ore.']; } if ($self->is_working) { diff --git a/lib/Lacuna/DB/Result/Building/DistributionCenter.pm b/lib/Lacuna/DB/Result/Building/DistributionCenter.pm index 9bbc3dfd..617faa98 100755 --- a/lib/Lacuna/DB/Result/Building/DistributionCenter.pm +++ b/lib/Lacuna/DB/Result/Building/DistributionCenter.pm @@ -5,7 +5,7 @@ use utf8; no warnings qw(uninitialized); use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES); extends 'Lacuna::DB::Result::Building'; -use experimental 'smartmatch'; +use Switch::Right; around 'build_tags' => sub { my ($orig, $class) = @_; @@ -78,7 +78,7 @@ sub reserve { my $body = $self->body; my $total = 0; for my $resource ( @$resources ) { - if ($resource->{type} ~~ [ORE_TYPES, FOOD_TYPES, 'water', 'energy']) { + if (smartmatch($resource->{type}, any => [ORE_TYPES, FOOD_TYPES, 'water', 'energy'])) { my $amount = $resource->{quantity}; $total += $amount; confess [1011, "You cannot reserve negative resources."] diff --git a/lib/Lacuna/DB/Result/Building/GeneticsLab.pm b/lib/Lacuna/DB/Result/Building/GeneticsLab.pm index e17bf73d..d300ec33 100644 --- a/lib/Lacuna/DB/Result/Building/GeneticsLab.pm +++ b/lib/Lacuna/DB/Result/Building/GeneticsLab.pm @@ -5,7 +5,7 @@ use utf8; no warnings qw(uninitialized); use Lacuna::Util qw(randint); extends 'Lacuna::DB::Result::Building'; -use experimental 'smartmatch'; +use Switch::Right; around 'build_tags' => sub { my ($orig, $class) = @_; @@ -132,7 +132,7 @@ sub experiment { unless ($spy->on_body_id == $self->body_id && $spy->task eq 'Captured') { confess [1010, 'This spy is not a prisoner on your planet.']; } - unless ($affinity ~~ $self->find_graftable($spy)) { + unless (smartmatch($affinity, any => $self->find_graftable($spy))) { confess [1013, 'This spy cannot help you with that type of graft.']; } my $empire = $self->body->empire; diff --git a/lib/Lacuna/DB/Result/Building/LCOTa.pm b/lib/Lacuna/DB/Result/Building/LCOTa.pm index 9203ef46..98312d4b 100644 --- a/lib/Lacuna/DB/Result/Building/LCOTa.pm +++ b/lib/Lacuna/DB/Result/Building/LCOTa.pm @@ -6,7 +6,7 @@ no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Building'; use Lacuna::Constants qw(GROWTH); with 'Lacuna::Role::LCOT'; -use experimental 'smartmatch'; +use Switch::Right; use constant controller_class => 'Lacuna::RPC::Building::LCOTa'; use constant image => 'lcota'; @@ -82,7 +82,7 @@ before 'can_demolish' => sub { before can_build => sub { my $self = shift; - if ($self->x ~~ [-5,5] || $self->y ~~ [-5,5] || ($self->x ~~ [-1,0,1] && $self->y ~~ [-1,0,1] )) { + if (smartmatch($self->x, any => [-5,5]) || smartmatch($self->y, any => [-5,5]) || (smartmatch($self->x, any => [-1,0,1]) && smartmatch($self->y, any => [-1,0,1]) )) { confess [1009, 'Lost City of Tyleon cannot be placed in that location.']; } }; diff --git a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm index 9c1e60ce..3b3a29ad 100644 --- a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm +++ b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm @@ -4,7 +4,7 @@ use Moose; use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Building'; -use experimental 'smartmatch'; +use Switch::Right; around 'build_tags' => sub { my ($orig, $class) = @_; @@ -79,7 +79,7 @@ sub add_to_market { confess [1009, "This Mercenaries Guild can only support ".$self->effective_level." spies at one time."]; } my $spy = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->find($spy_id); - confess $have_exception unless (defined $spy && $self->body_id eq $spy->on_body_id && $spy->task ~~ ['Counter Espionage','Idle']); + confess $have_exception unless (defined $spy && $self->body_id eq $spy->on_body_id && smartmatch($spy->task, any => ['Counter Espionage','Idle'])); $spy->task('Mercenary Transport'); $spy->update; $ship->task('Waiting On Trade'); diff --git a/lib/Lacuna/DB/Result/Building/SSLa.pm b/lib/Lacuna/DB/Result/Building/SSLa.pm index d4bea225..f953f808 100644 --- a/lib/Lacuna/DB/Result/Building/SSLa.pm +++ b/lib/Lacuna/DB/Result/Building/SSLa.pm @@ -5,7 +5,7 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Building'; use Lacuna::Constants qw(ORE_TYPES INFLATION); -use experimental 'smartmatch'; +use Switch::Right; around 'build_tags' => sub { my ($orig, $class) = @_; @@ -175,7 +175,7 @@ sub can_make_plan { confess [1013, 'This Space Station Lab is not a high enough level to make that plan.']; } my $makeable = $self->makeable_plans; - unless ($type ~~ [keys %{$makeable}]) { + unless (smartmatch($type, any => [keys %{$makeable}])) { confess [1009, 'Cannot make that type of plan.']; } my $resource_cost = $self->plan_cost_at_level($level, $self->plan_resource_cost); diff --git a/lib/Lacuna/DB/Result/Building/Stockpile.pm b/lib/Lacuna/DB/Result/Building/Stockpile.pm index 9306c574..dbde61c6 100644 --- a/lib/Lacuna/DB/Result/Building/Stockpile.pm +++ b/lib/Lacuna/DB/Result/Building/Stockpile.pm @@ -4,7 +4,7 @@ use Moose; use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Building'; -use experimental 'smartmatch'; +use Switch::Right; around 'build_tags' => sub { my ($orig, $class) = @_; @@ -59,8 +59,8 @@ before 'can_downgrade' => sub { } foreach my $building (@{$self->body->building_cache}) { if ($building->level > $max_level && - 'Resources' ~~ [$building->build_tags] && - ( !('Storage' ~~ [$building->build_tags]) || + smartmatch('Resources', any => [$building->build_tags]) && + ( !(smartmatch('Storage', any => [$building->build_tags])) || $building->isa('Lacuna::DB::Result::Building::Waste::Exchanger'))) { confess [1013, 'You have to downgrade your level '. $building->level.' '.$building->name.' to level '. @@ -77,8 +77,8 @@ before 'can_demolish' => sub { } foreach my $building (@{$self->body->building_cache}) { if ($building->level > $max_level && - 'Resources' ~~ [$building->build_tags] && - ( !('Storage' ~~ [$building->build_tags]) || + smartmatch('Resources', any => [$building->build_tags]) && + ( !(smartmatch('Storage', any => [$building->build_tags])) || $building->isa('Lacuna::DB::Result::Building::Waste::Exchanger'))) { confess [1013, 'You have to downgrade your level '. $building->level.' '.$building->name. diff --git a/lib/Lacuna/DB/Result/Building/Transporter.pm b/lib/Lacuna/DB/Result/Building/Transporter.pm index 23d7d84d..fe963e6b 100644 --- a/lib/Lacuna/DB/Result/Building/Transporter.pm +++ b/lib/Lacuna/DB/Result/Building/Transporter.pm @@ -5,7 +5,7 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Building'; use Lacuna::Constants qw(FOOD_TYPES ORE_TYPES); -use experimental 'smartmatch'; +use Switch::Right; with 'Lacuna::Role::Trader','Lacuna::Role::Ship::Trade'; @@ -101,10 +101,10 @@ sub trade_one_for_one { confess [1011, 'This transporter has a maximum load size of '.$self->determine_available_cargo_space.'.']; } my @types = (FOOD_TYPES, ORE_TYPES, qw(water waste energy)); - unless ($have ~~ \@types) { + unless (smartmatch($have, any => \@types)) { confess [1009, 'There is no resource called '.$have.'.']; } - unless ($want ~~ \@types) { + unless (smartmatch($want, any => \@types)) { confess [1009, 'There is no resource called '.$want.'.']; } my $body = $self->body; diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 9c80a60a..d0c4e1ea 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -15,7 +15,6 @@ use Email::Valid; use UUID::Tiny ':std'; use Lacuna::Constants qw(INFLATION); use PerlX::Maybe qw(provided maybe); -use experimental 'smartmatch'; __PACKAGE__->table('empire'); __PACKAGE__->add_columns( diff --git a/lib/Lacuna/DB/Result/Fleet.pm b/lib/Lacuna/DB/Result/Fleet.pm index 9dacc876..64853448 100644 --- a/lib/Lacuna/DB/Result/Fleet.pm +++ b/lib/Lacuna/DB/Result/Fleet.pm @@ -6,8 +6,7 @@ no warnings qw(uninitialized); extends 'Lacuna::DB::Result'; use Lacuna::Util qw(format_date randint); use DateTime; -use feature "switch"; -use experimental 'smartmatch'; +use Switch::Right; has 'hostile_action' => ( is => 'rw', @@ -168,7 +167,7 @@ sub can_send_to_target { sub can_recall { my $self = shift; - unless ($self->task ~~ [qw(Defend Orbiting)]) { + unless (smartmatch($self->task, any => [qw(Defend Orbiting)])) { confess [1010, 'That ship is busy.']; } return 1; @@ -217,7 +216,7 @@ sub get_status { max_occupants => $self->max_occupants, payload => $self->format_description_of_payload, can_scuttle => ($self->task eq 'Docked') ? 1 : 0, - can_recall => ($self->task ~~ [qw(Defend Orbiting)]) ? 1 : 0, + can_recall => (smartmatch($self->task, any => [qw(Defend Orbiting)])) ? 1 : 0, ); if ($target) { $status{estimated_travel_time} = $self->calculate_travel_time($target); @@ -244,7 +243,7 @@ sub get_status { $status{from} = $from; $status{date_arrives} = $status{date_available}; } - elsif ($self->task ~~ [qw(Defend Orbiting)]) { + elsif (smartmatch($self->task, any => [qw(Defend Orbiting)])) { my $body = $self->body; my $from = { id => $body->id, diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index c88ceea3..2a0e35ac 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -11,7 +11,7 @@ use Lacuna::Util qw(randint format_date random_element); use DateTime; use Data::Dumper; use Scalar::Util qw(weaken); -use experimental 'smartmatch'; +use Switch::Right; no warnings 'uninitialized'; @@ -297,7 +297,7 @@ sub sanitize { if ($self->get_type eq 'habitable planet' && $self->size >= 40 && $self->size <= 50 && $self->orbit != 8 && - $self->zone ~~ ['1|1','1|-1','-1|1','-1|-1','0|0','0|1','1|0','-1|0','0|-1']) { + smartmatch($self->zone, any => ['1|1','1|-1','-1|1','-1|-1','0|0','0|1','1|0','-1|0','0|-1'])) { $self->usable_as_starter_enabled(1); } my @attributes = qw( happiness_hour happiness waste_hour waste_stored waste_capacity @@ -1963,10 +1963,10 @@ sub spend_type { sub can_add_type { my ($self, $type, $value) = @_; - if ($type ~~ [ORE_TYPES]) { + if (smartmatch($type, any => [ORE_TYPES])) { $type = 'ore'; } - if ($type ~~ [FOOD_TYPES]) { + if (smartmatch($type, any => [FOOD_TYPES])) { $type = 'food'; } my $capacity = $type.'_capacity'; @@ -2812,7 +2812,7 @@ sub complain_about_lack_of_resources { my $class; foreach my $rpcclass (shuffle (BUILDABLE_CLASSES)) { $class = $rpcclass->model_class; - next unless ('Infrastructure' ~~ [$class->build_tags]); + next unless (smartmatch('Infrastructure', any => [$class->build_tags])); } my ($building) = grep {$_->efficiency > 0} $self->get_buildings_of_class($class); if (defined $building) { diff --git a/lib/Lacuna/DB/Result/Map/Star.pm b/lib/Lacuna/DB/Result/Map/Star.pm index c0bff2f7..8d806b75 100644 --- a/lib/Lacuna/DB/Result/Map/Star.pm +++ b/lib/Lacuna/DB/Result/Map/Star.pm @@ -5,7 +5,7 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Map'; use Lacuna::Util; -use experimental 'smartmatch'; +use Switch::Right; __PACKAGE__->table('star'); __PACKAGE__->add_columns( @@ -75,7 +75,7 @@ sub get_status_lite { }; } if (defined $empire) { - if ($override_probe or $self->id ~~ $empire->probed_stars) { + if ($override_probe or smartmatch($self->id, any => $empire->probed_stars)) { my @orbits; my $bodies = $self->bodies; while (my $body = $bodies->next) { @@ -99,7 +99,7 @@ sub get_status { influence => $self->influence, }; if (defined $empire) { - if ($override_probe || $self->id ~~ $empire->probed_stars) { + if ($override_probe || smartmatch($self->id, any => $empire->probed_stars)) { my @orbits; my $bodies = $self->bodies; while (my $body = $bodies->next) { diff --git a/lib/Lacuna/DB/Result/Mission.pm b/lib/Lacuna/DB/Result/Mission.pm index 0e26aa4e..f24d9a65 100644 --- a/lib/Lacuna/DB/Result/Mission.pm +++ b/lib/Lacuna/DB/Result/Mission.pm @@ -7,8 +7,7 @@ use Lacuna::Util qw(format_date commify randint consolidate_items); use UUID::Tiny ':std'; use Config::JSON; use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES); -use feature 'switch'; -use experimental 'switch'; +use Switch::Right; use List::Util qw(sum first); __PACKAGE__->table('mission'); diff --git a/lib/Lacuna/DB/Result/Plan.pm b/lib/Lacuna/DB/Result/Plan.pm index 48305d9d..0173b76f 100644 --- a/lib/Lacuna/DB/Result/Plan.pm +++ b/lib/Lacuna/DB/Result/Plan.pm @@ -8,8 +8,6 @@ extends 'Lacuna::DB::Result'; use Lacuna::Util qw(format_date); use DateTime; -use experimental 'smartmatch'; - __PACKAGE__->table('plan'); __PACKAGE__->add_columns( body_id => { data_type => 'int', size => 11, is_nullable => 0 }, @@ -93,7 +91,13 @@ sub get_glyph_recipe { sub check_glyph_recipe { my ($class, $glyphs) = @_; - my ($plan_class) = grep {@{$recipes->{$_}} ~~ @$glyphs} keys %$recipes; + # Order-sensitive element-wise match: the glyphs must be supplied in the + # exact order the recipe lists them (this is part of the assembly mechanic). + my ($plan_class) = grep { + my $recipe = $recipes->{$_}; + @$recipe == @$glyphs + && !grep { $recipe->[$_] ne $glyphs->[$_] } 0 .. $#$recipe + } keys %$recipes; if (defined $plan_class) { # Sort out different Halls recipes $plan_class =~ s/HallsOfVrbansk.*$/HallsOfVrbansk/; diff --git a/lib/Lacuna/DB/Result/Propositions/FireBfg.pm b/lib/Lacuna/DB/Result/Propositions/FireBfg.pm index 936db066..fef7f4ef 100644 --- a/lib/Lacuna/DB/Result/Propositions/FireBfg.pm +++ b/lib/Lacuna/DB/Result/Propositions/FireBfg.pm @@ -4,7 +4,7 @@ use Moose; use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Propositions'; -use experimental 'smartmatch'; +use Switch::Right; before pass => sub { my ($self) = @_; @@ -31,7 +31,7 @@ before pass => sub { if (defined $body->empire_id && $body->empire_id) { foreach my $building (@{$body->building_cache}) { - next unless ('Infrastructure' ~~ [$building->build_tags]); + next unless (smartmatch('Infrastructure', any => [$building->build_tags])); next if ( $building->class eq 'Lacuna::DB::Result::Building::PlanetaryCommand' ); $building->efficiency(0); $building->update; diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index c34729c1..0f208458 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -8,8 +8,7 @@ use Lacuna::Util qw(format_date randint); use Lacuna::Constants qw(HIGH_SPEED_TEST_TRAVEL_DIVISOR HIGH_SPEED_TEST_TRAVEL_MIN_SECONDS); use DateTime; use Scalar::Util qw(weaken); -use feature "switch"; -use experimental 'smartmatch'; +use Switch::Right; has 'hostile_action' => ( is => 'rw', @@ -266,7 +265,7 @@ sub can_send_to_target { sub can_recall { my $self = shift; - unless ($self->task ~~ [qw(Defend Orbiting)]) { + unless (smartmatch($self->task, any => [qw(Defend Orbiting)])) { confess [1010, 'That ship is busy.']; } return 1; @@ -324,7 +323,7 @@ sub get_status { max_occupants => $self->max_occupants, payload => $self->format_description_of_payload, can_scuttle => ($self->task eq 'Docked') ? 1 : 0, - can_recall => ($self->task ~~ [qw(Defend Orbiting)]) ? 1 : 0, + can_recall => (smartmatch($self->task, any => [qw(Defend Orbiting)])) ? 1 : 0, number_of_docks => $self->number_of_docks, ); if ($target) { @@ -352,7 +351,7 @@ sub get_status { $status{from} = $from; $status{date_arrives} = $status{date_available}; } - elsif ($self->task ~~ [qw(Defend Orbiting)]) { + elsif (smartmatch($self->task, any => [qw(Defend Orbiting)])) { my $body = $self->body; my $from = { id => $body->id, diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 940ca938..ddf4bae5 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -10,11 +10,9 @@ use Lacuna::Util qw(format_date randint random_element commify); use DateTime; use Scalar::Util qw(weaken); -use feature "switch"; +use Switch::Right; use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES SHIP_TYPES); -use experimental 'switch'; - __PACKAGE__->table('spies'); __PACKAGE__->add_columns( @@ -336,14 +334,14 @@ sub get_possible_assignments { my $self = shift; # can't be assigned anything right now - unless ($self->task ~~ ['Counter Espionage', + unless (smartmatch($self->task, any => ['Counter Espionage', 'Idle', 'Sabotage BHG', 'Intel Training', 'Mayhem Training', 'Politics Training', 'Theft Training', - 'Political Propaganda']) { + 'Political Propaganda'])) { return [{ task => $self->task, recovery => $self->seconds_remaining_on_assignment }]; } @@ -456,15 +454,15 @@ sub tick_all_spies { sub is_available { my ($self) = @_; my $task = $self->task; - if ($task ~~ ['Idle', + if (smartmatch($task, any => ['Idle', 'Counter Espionage', - 'Sabotage BHG']) { + 'Sabotage BHG'])) { return 1; } - elsif ($task ~~ ['Intel Training', + elsif (smartmatch($task, any => ['Intel Training', 'Mayhem Training', 'Politics Training', - 'Theft Training']) { + 'Theft Training'])) { my $train_bld; my $tr_skill; if ($task eq 'Intel Training') { @@ -687,10 +685,10 @@ sub assign { $self->available_on(DateTime->now->add(seconds => $mission->{recovery})); # run mission - if ($assignment ~~ ['Idle', + if (smartmatch($assignment, any => ['Idle', 'Counter Espionage', 'Political Propaganda', - 'Sabotage BHG']) { + 'Sabotage BHG'])) { $self->update; $self->on_body->needs_recalc(1); $self->on_body->update; diff --git a/lib/Lacuna/RPC/Body.pm b/lib/Lacuna/RPC/Body.pm index 3d0b28dd..94423e02 100644 --- a/lib/Lacuna/RPC/Body.pm +++ b/lib/Lacuna/RPC/Body.pm @@ -11,8 +11,7 @@ use Lacuna::Util qw(randint); use List::Util qw(all); use List::MoreUtils qw(uniq); use Carp; -use feature 'switch'; -use experimental 'smartmatch'; +use Switch::Right; with "Lacuna::RPC::Role::Building"; @@ -359,10 +358,10 @@ sub check_positions { } } when("Lacuna::DB::Result::Building::LCOTa") { - if ($new_ids->{$id}->{x} ~~ [ -5, 5 ] || - $new_ids->{$id}->{y} ~~ [ -5, 5 ] || - ($new_ids->{$id}->{x} ~~ [ -1, 0, 1 ] && - $new_ids->{$id}->{y} ~~ [ -1, 0, 1 ])) { + if (smartmatch($new_ids->{$id}->{x}, any => [ -5, 5 ]) || + smartmatch($new_ids->{$id}->{y}, any => [ -5, 5 ]) || + (smartmatch($new_ids->{$id}->{x}, any => [ -1, 0, 1 ]) && + smartmatch($new_ids->{$id}->{y}, any => [ -1, 0, 1 ]))) { push @position_err, sprintf("%s can not be placed in that position", $new_ids->{$id}->{name}); } @@ -484,11 +483,11 @@ sub get_buildable { $properties{class} = $class->model_class; my $building = $building_rs->new(\%properties); my @tags = $building->build_tags; - if ($properties{class} ~~ [keys %plans]) { + if (smartmatch($properties{class}, any => [keys %plans])) { push @tags, 'Plan'; } if ($tag) { - next unless ($tag ~~ \@tags); + next unless (smartmatch($tag, any => \@tags)); } my $cost = $building->cost_to_upgrade; my $can_build = eval{$body->has_met_building_prereqs($building, $cost)}; @@ -536,7 +535,7 @@ sub get_buildable_locations { my $body = $session->current_body; my %args; - $args{size} = $opts->{size} if $opts->{size} and $opts->{size} ~~ [1,4,9]; + $args{size} = $opts->{size} if $opts->{size} and smartmatch($opts->{size}, any => [1,4,9]); return { status => $self->format_status($session, $body), diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index f5be27e0..135eecf8 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -6,7 +6,7 @@ extends 'Lacuna::RPC::Building'; use List::Util qw(shuffle); use Lacuna::Util qw(randint random_element commify); use Lacuna::Constants qw(FOOD_TYPES ORE_TYPES); -use experimental 'smartmatch'; +use Switch::Right; sub app_url { return '/blackholegenerator'; @@ -166,7 +166,7 @@ sub find_target { undef, { distinct => 1 } )->get_column('zone')->all; - unless ($target_params->{zone} ~~ @zones) { + unless (smartmatch($target_params->{zone}, any => \@zones)) { confess [ 1002, 'Could not find '.$target_word.' zone.']; } #New Method diff --git a/lib/Lacuna/RPC/Building/PoliceStation.pm b/lib/Lacuna/RPC/Building/PoliceStation.pm index af98c44d..aacf73b5 100644 --- a/lib/Lacuna/RPC/Building/PoliceStation.pm +++ b/lib/Lacuna/RPC/Building/PoliceStation.pm @@ -4,7 +4,7 @@ use Moose; use utf8; no warnings qw(uninitialized); extends 'Lacuna::RPC::Building'; -use experimental 'smartmatch'; +use Switch::Right; sub app_url { return '/policestation'; @@ -173,7 +173,7 @@ sub view_foreign_ships { from => {}, image => 'unknown', ); - if ($ship->body_id ~~ \@my_planets || $see_ship_path >= $ship->stealth) { + if (smartmatch($ship->body_id, any => \@my_planets) || $see_ship_path >= $ship->stealth) { $ship_info{from} = { id => $ship->body->id, name => $ship->body->name, @@ -182,7 +182,7 @@ sub view_foreign_ships { name => $ship->body->empire->name, }, }; - if ($ship->body_id ~~ \@my_planets || $see_ship_type >= $ship->stealth) { + if (smartmatch($ship->body_id, any => \@my_planets) || $see_ship_type >= $ship->stealth) { $ship_info{name} = $ship->name; $ship_info{type} = $ship->type; $ship_info{type_human} = $ship->type_formatted; @@ -223,7 +223,7 @@ sub view_ships_orbiting { date_arrived => $ship->date_available_formatted, from => {}, ); - if ($ship->body_id ~~ \@my_planets || $see_ship_path >= $ship->stealth) { + if (smartmatch($ship->body_id, any => \@my_planets) || $see_ship_path >= $ship->stealth) { $ship_info{from} = { id => $ship->body->id, name => $ship->body->name, @@ -232,7 +232,7 @@ sub view_ships_orbiting { name => $ship->body->empire->name, }, }; - if ($ship->body_id ~~ \@my_planets || $see_ship_type >= $ship->stealth) { + if (smartmatch($ship->body_id, any => \@my_planets) || $see_ship_type >= $ship->stealth) { $ship_info{name} = $ship->name; $ship_info{type} = $ship->type; $ship_info{type_human} = $ship->type_formatted; diff --git a/lib/Lacuna/RPC/Building/Shipyard.pm b/lib/Lacuna/RPC/Building/Shipyard.pm index b8264a74..f5face3b 100644 --- a/lib/Lacuna/RPC/Building/Shipyard.pm +++ b/lib/Lacuna/RPC/Building/Shipyard.pm @@ -7,7 +7,7 @@ no warnings qw(uninitialized); extends 'Lacuna::RPC::Building'; use Lacuna::Constants qw(SHIP_TYPES); use List::Util qw(none max min any sum reduce); -use experimental 'smartmatch'; +use Switch::Right; sub app_url { return '/shipyard'; @@ -250,7 +250,7 @@ sub build_ships { } given(lc $opts->{autoselect}) { - when([undef,'']) { + when(any => [undef,'']) { confess [1011, 'No repaired building_id specified'] if @buildings < 1; } when('all') { @@ -346,7 +346,7 @@ sub get_buildable { my $ship = Lacuna->db->resultset('Ships')->new({type=>$type}); my @tags = @{$ship->build_tags}; if ($tag) { - next unless ($tag ~~ \@tags); + next unless (smartmatch($tag, any => \@tags)); } my $can = eval{$building->can_build_ship($ship)}; my $reason = $@; diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 39ecd221..9c8af981 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -8,8 +8,7 @@ use Lacuna::Constants qw(SHIP_TYPES); use Lacuna::Util qw(format_date); use Data::Dumper; -use feature "switch"; -use experimental 'smartmatch'; +use Switch::Right; sub app_url { return '/spaceport'; @@ -976,7 +975,7 @@ sub _ship_filter_options { for my $key ( keys %{ $filter } ) { # Throw away bad keys - unless ( $key ~~ [keys %$options] ) { + unless ( smartmatch($key, any => [keys %$options]) ) { delete $filter->{$key}; next; } @@ -984,10 +983,10 @@ sub _ship_filter_options { # Throw away bad values my $value = $filter->{$key}; if ( ref($value) eq 'ARRAY' ) { - @$value = grep { $_ ~~ $options->{$key} } @$value; + @$value = grep { smartmatch($_, any => $options->{$key}) } @$value; } elsif ( ! ref($value) ) { - delete $filter->{$key} unless ( $value ~~ $options->{$key} ); + delete $filter->{$key} unless ( smartmatch($value, any => $options->{$key}) ); } else { delete $filter->{$key}; @@ -1017,7 +1016,7 @@ sub _ship_sort_options { my ($self, $sort) = @_; # return the default if it's not one of the following or is 'name' - if ( ! $sort || $sort eq 'name' || ! $sort ~~ [qw(combat speed stealth task type)] ) { + if ( ! $sort || $sort eq 'name' || !smartmatch($sort, any => [qw(combat speed stealth task type)]) ) { return [ 'name' ]; } @@ -1084,7 +1083,7 @@ sub view_foreign_ships { from => {}, image => 'unknown', ); - if ($ship->body_id ~~ \@my_planets || $see_ship_path >= $ship->stealth) { + if (smartmatch($ship->body_id, any => \@my_planets) || $see_ship_path >= $ship->stealth) { $ship_info{from} = { id => $ship->body->id, name => $ship->body->name, @@ -1093,7 +1092,7 @@ sub view_foreign_ships { name => $ship->body->empire->name, }, }; - if ($ship->body_id ~~ \@my_planets || $see_ship_type >= $ship->stealth) { + if (smartmatch($ship->body_id, any => \@my_planets) || $see_ship_type >= $ship->stealth) { $ship_info{name} = $ship->name; $ship_info{type} = $ship->type; $ship_info{type_human} = $ship->type_formatted; @@ -1135,7 +1134,7 @@ sub view_ships_orbiting { from => {}, image => 'unknown', ); - if ($ship->body_id ~~ \@my_planets || $see_ship_path >= $ship->stealth) { + if (smartmatch($ship->body_id, any => \@my_planets) || $see_ship_path >= $ship->stealth) { $ship_info{from} = { id => $ship->body->id, name => $ship->body->name, @@ -1144,7 +1143,7 @@ sub view_ships_orbiting { name => $ship->body->empire->name, }, }; - if ($ship->body_id ~~ \@my_planets || $see_ship_type >= $ship->stealth) { + if (smartmatch($ship->body_id, any => \@my_planets) || $see_ship_type >= $ship->stealth) { $ship_info{name} = $ship->name; $ship_info{type} = $ship->type; $ship_info{type_human} = $ship->type_formatted; @@ -1185,7 +1184,7 @@ sub _view_ships { from => {}, image => 'unknown', ); - if ($ship->body_id ~~ \@my_planets || $see_ship_path >= $ship->stealth) { + if (smartmatch($ship->body_id, any => \@my_planets) || $see_ship_path >= $ship->stealth) { $ship_info{from} = { id => $ship->body->id, name => $ship->body->name, @@ -1194,7 +1193,7 @@ sub _view_ships { name => $ship->body->empire->name, }, }; - if ($ship->body_id ~~ \@my_planets || $see_ship_type >= $ship->stealth) { + if (smartmatch($ship->body_id, any => \@my_planets) || $see_ship_type >= $ship->stealth) { $ship_info{name} = $ship->name; $ship_info{type} = $ship->type; $ship_info{type_human} = $ship->type_formatted; diff --git a/lib/Lacuna/RPC/Building/Trade.pm b/lib/Lacuna/RPC/Building/Trade.pm index 8d8bb72d..f97cf85b 100644 --- a/lib/Lacuna/RPC/Building/Trade.pm +++ b/lib/Lacuna/RPC/Building/Trade.pm @@ -1,14 +1,13 @@ package Lacuna::RPC::Building::Trade; use Moose; -use feature "switch"; +use Switch::Right; use utf8; no warnings qw(uninitialized); extends 'Lacuna::RPC::Building'; use Guard; use List::Util qw(first); use Lacuna::Constants qw(FOOD_TYPES ORE_TYPES SHIP_WASTE_TYPES SHIP_TRADE_TYPES); -use experimental 'switch'; with 'Lacuna::Role::TraderRpc','Lacuna::Role::Ship::Trade'; @@ -453,7 +452,7 @@ sub push_items { # Allowed to push food, ore, water and energy only to SS that control your star foreach my $item (@{$items}) { given($item->{type}) { - when([qw(waste glyph plan prisoner ship)]) { + when(any => [qw(waste glyph plan prisoner ship)]) { confess [1010, "You cannot push $item->{type} to that space station."]; } } diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index add7f460..e1b52f35 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -16,7 +16,7 @@ use List::Util qw(none); use PerlX::Maybe qw(provided); use Log::Any qw($log); use Data::Dumper; -use experimental 'smartmatch'; +use Switch::Right; # logging features are new in this level. use JSON::RPC::Dispatcher 0.0508; @@ -687,7 +687,7 @@ sub edit_profile { } my $medals = $empire->medals; while (my $medal = $medals->next) { - if ($medal->id ~~ $profile->{public_medals}) { + if (smartmatch($medal->id, any => $profile->{public_medals})) { $medal->public(1); $medal->update; } diff --git a/lib/Lacuna/RPC/EssentiaCode.pm b/lib/Lacuna/RPC/EssentiaCode.pm index 1cc7a2a6..156a7e67 100644 --- a/lib/Lacuna/RPC/EssentiaCode.pm +++ b/lib/Lacuna/RPC/EssentiaCode.pm @@ -6,11 +6,11 @@ no warnings qw(uninitialized); extends 'Lacuna::RPC'; use DateTime; use UUID::Tiny ':std'; -use experimental 'smartmatch'; +use Switch::Right; sub verify_key { my ($self, $key) = @_; - return $key ~~ Lacuna->config->get('server_keys') ? 1 : 0; + return smartmatch($key, any => Lacuna->config->get('server_keys')) ? 1 : 0; } sub spend { diff --git a/lib/Lacuna/RPC/Inbox.pm b/lib/Lacuna/RPC/Inbox.pm index 1cca1874..07d38fe6 100644 --- a/lib/Lacuna/RPC/Inbox.pm +++ b/lib/Lacuna/RPC/Inbox.pm @@ -10,7 +10,7 @@ use Lacuna::Util qw(format_date); use List::Util qw(none); use PerlX::Maybe qw(provided); use Time::HiRes qw(usleep); -use experimental 'smartmatch'; +use Switch::Right; # This function basically handles all the "or baby" logic for # messages. Can be further refined by the caller with extra ->search @@ -265,14 +265,14 @@ sub send_message { my $empire = $session->current_empire; if ($options->{in_reply_to}) { my $reply_to = Lacuna->db->resultset('Lacuna::DB::Result::Message')->find($options->{in_reply_to}); - unless ($empire->id ~~ [$reply_to->to_id, $reply_to->from_id]) { + unless (smartmatch($empire->id, any => [$reply_to->to_id, $reply_to->from_id])) { confess [1010, 'You cannot reply to a message id that you cannot read.']; } } my $attachments = {}; if ($options->{forward}) { my $forward = Lacuna->db->resultset('Lacuna::DB::Result::Message')->find($options->{forward}); - unless ($empire->id ~~ [$forward->to_id, $forward->from_id]) { + unless (smartmatch($empire->id, any => [$forward->to_id, $forward->from_id])) { confess [1010, 'You cannot forward a message id that you cannot read.']; } $attachments = $forward->attachments; diff --git a/lib/Lacuna/RPC/Stats.pm b/lib/Lacuna/RPC/Stats.pm index 7a2b9c18..38e84f8e 100644 --- a/lib/Lacuna/RPC/Stats.pm +++ b/lib/Lacuna/RPC/Stats.pm @@ -5,7 +5,7 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::RPC'; use Lacuna::Constants qw(SHIP_TYPES); -use experimental 'smartmatch'; +use Switch::Right; sub credits { return [ @@ -26,7 +26,7 @@ sub alliance_rank { my ($self, $session_id, $by, $page_number) = @_; my $session = $self->get_session({session_id => $session_id }); my $empire = $session->current_empire; - unless ($by ~~ [qw(influence population average_empire_size_rank offense_success_rate_rank defense_success_rate_rank dirtiest_rank)]) { + unless (smartmatch($by, any => [qw(influence population average_empire_size_rank offense_success_rate_rank defense_success_rate_rank dirtiest_rank)])) { $by = 'influence desc,population desc'; } my $ranks = Lacuna->db->resultset('Lacuna::DB::Result::Log::Alliance'); @@ -79,7 +79,7 @@ sub find_alliance_rank { unless (length($alliance_name) >= 3) { confess [1009, 'Alliance name too short. Your search must be at least 3 characters.']; } - unless ($by ~~ [qw(average_empire_size_rank offense_success_rate_rank defense_success_rate_rank dirtiest_rank)]) { + unless (smartmatch($by, any => [qw(average_empire_size_rank offense_success_rate_rank defense_success_rate_rank dirtiest_rank)])) { $by = 'average_empire_size_rank'; } my $session = $self->get_session({session_id => $session_id }); @@ -108,7 +108,7 @@ sub empire_rank { my ($self, $session_id, $by, $page_number) = @_; my $session = $self->get_session({session_id => $session_id }); my $empire = $session->current_empire; - unless ($by ~~ [qw(empire_size_rank offense_success_rate_rank defense_success_rate_rank dirtiest_rank)]) { + unless (smartmatch($by, any => [qw(empire_size_rank offense_success_rate_rank defense_success_rate_rank dirtiest_rank)])) { $by = 'empire_size_rank'; } my $ranks = Lacuna->db->resultset('Lacuna::DB::Result::Log::Empire'); @@ -155,7 +155,7 @@ sub find_empire_rank { unless (length($empire_name) >= 3) { confess [1009, 'Empire name too short. Your search must be at least 3 characters.']; } - unless ($by ~~ [qw(empire_size_rank offense_success_rate_rank defense_success_rate_rank dirtiest_rank)]) { + unless (smartmatch($by, any => [qw(empire_size_rank offense_success_rate_rank defense_success_rate_rank dirtiest_rank)])) { $by = 'empire_size_rank'; } my $session = $self->get_session({session_id => $session_id }); @@ -184,7 +184,7 @@ sub colony_rank { my ($self, $session_id, $by) = @_; my $session = $self->get_session({session_id => $session_id }); my $empire = $session->current_empire; - unless ($by ~~ [qw(population_rank)]) { + unless (smartmatch($by, any => [qw(population_rank)])) { $by = 'population_rank'; } my $ranks = Lacuna->db->resultset('Lacuna::DB::Result::Log::Colony')->search(undef,{order_by =>$by, rows=>25}); @@ -211,7 +211,7 @@ sub spy_rank { my ($self, $session_id, $by) = @_; my $session = $self->get_session({session_id => $session_id }); my $empire = $session->current_empire; - unless ($by ~~ [qw(level_rank success_rate_rank dirtiest_rank)]) { + unless (smartmatch($by, any => [qw(level_rank success_rate_rank dirtiest_rank)])) { $by = 'level_rank'; } my $ranks = Lacuna->db->resultset('Lacuna::DB::Result::Log::Spies')->search(undef,{order_by => $by, rows=>25}); diff --git a/lib/Lacuna/Role/Ship/Trade.pm b/lib/Lacuna/Role/Ship/Trade.pm index 8f204bc5..36c7e777 100644 --- a/lib/Lacuna/Role/Ship/Trade.pm +++ b/lib/Lacuna/Role/Ship/Trade.pm @@ -1,7 +1,6 @@ package Lacuna::Role::Ship::Trade; use Moose::Role; -use feature "switch"; my $no_docks_exception = [1011, 'There are not enough docks available to receive the ships.']; my $no_spaceport_exception = [1011, 'There is no space port available to receive the ships.']; diff --git a/lib/Lacuna/Role/Trader.pm b/lib/Lacuna/Role/Trader.pm index ca528f43..38c0d9b8 100644 --- a/lib/Lacuna/Role/Trader.pm +++ b/lib/Lacuna/Role/Trader.pm @@ -1,11 +1,10 @@ package Lacuna::Role::Trader; use Moose::Role; -use feature "switch"; +use Switch::Right; use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES); use Lacuna::Util qw(randint); use Data::Dumper; -use experimental 'switch'; # hopefully this constant allows the comparison later to be # compiled out based on how we're called. @@ -18,6 +17,13 @@ use constant OVERLOAD_ALLOWED => $overload_allowed; my $ask_nothing_exception = [1013, 'It appears that you have asked for nothing.']; my $fractional_offer_exception = [1013, 'You cannot offer a fraction of something.']; +# Switch::Right's when(any => [...]) does not expand a bareword list-constant +# (ORE_TYPES/FOOD_TYPES) placed directly inside the arrayref literal, so +# pre-expand them into real arrays and match against a reference instead. +my @trade_resource_types = (qw(water energy waste), ORE_TYPES, FOOD_TYPES); +my @ore_type_list = (ORE_TYPES); +my @food_type_list = (FOOD_TYPES); + sub _market { my $self = shift; return Lacuna->db->resultset('Lacuna::DB::Result::Market'); @@ -48,7 +54,7 @@ sub check_payload { foreach my $item (@{$items}) { given($item->{type}) { - when ([qw(water energy waste), ORE_TYPES, FOOD_TYPES]) { + when (any => \@trade_resource_types) { confess $offer_nothing_exception unless ($item->{quantity} > 0); confess $fractional_offer_exception if ($item->{quantity} != int($item->{quantity})); confess $have_exception unless ($body->type_stored($item->{type}) >= $item->{quantity}); @@ -159,19 +165,19 @@ sub structure_payload { my %meta = ( offer_cargo_space_needed => $space_used ); foreach my $item (@{$items}) { given($item->{type}) { - when ([qw(water energy waste)]) { + when (any => [qw(water energy waste)]) { $body->spend_type($item->{type}, $item->{quantity}); $body->update; $payload->{resources}{$item->{type}} += $item->{quantity}; $meta{'has_'.$item->{type}} = 1; } - when ([ORE_TYPES]) { + when (any => \@ore_type_list) { $body->spend_type($item->{type}, $item->{quantity}); $body->update; $payload->{resources}{$item->{type}} += $item->{quantity}; $meta{has_ore} = 1; } - when ([FOOD_TYPES]) { + when (any => \@food_type_list) { $body->spend_type($item->{type}, $item->{quantity}); $body->update; $payload->{resources}{$item->{type}} += $item->{quantity}; diff --git a/lib/Lacuna/Role/TraderRpc.pm b/lib/Lacuna/Role/TraderRpc.pm index a6130da0..5de19eab 100644 --- a/lib/Lacuna/Role/TraderRpc.pm +++ b/lib/Lacuna/Role/TraderRpc.pm @@ -1,10 +1,9 @@ package Lacuna::Role::TraderRpc; use Moose::Role; -use feature "switch"; +use Switch::Right; use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES); use Lacuna::Util qw(randint); -use experimental 'smartmatch'; sub view_my_market { my ($self, $session_id, $building_id, $page_number) = @_; @@ -46,7 +45,7 @@ sub view_market { order_by => 'ask', } ); - if ($filter && $filter ~~ [qw(food ore water waste energy glyph prisoner ship plan)]) { + if ($filter && smartmatch($filter, any => [qw(food ore water waste energy glyph prisoner ship plan)])) { $all_trades = $all_trades->search({ 'has_'.$filter => 1 }); } my @trades; diff --git a/lib/Lacuna/Web/Admin.pm b/lib/Lacuna/Web/Admin.pm index c77be9c4..087633d2 100644 --- a/lib/Lacuna/Web/Admin.pm +++ b/lib/Lacuna/Web/Admin.pm @@ -5,14 +5,13 @@ use utf8; no warnings qw(uninitialized); extends qw(Lacuna::Web); use Lacuna::Constants qw(FOOD_TYPES ORE_TYPES); -use feature "switch"; +use Switch::Right; use Module::Find; use UUID::Tiny ':std'; use Lacuna::Util qw(format_date commify kmbtq); use List::Util qw(sum); use Data::Dumper; use LWP::UserAgent; -use experimental 'smartmatch'; sub www_send_test_message { my ($self, $request, $id) = @_; @@ -278,7 +277,7 @@ sub www_search_empires { } my $order = $request->param('order') || 'name'; my $desc = $request->param('desc') || 0; - if ( $order ~~ [qw( id name last_login )] ) { + if ( smartmatch($order, any => [qw( id name last_login )]) ) { my $sort = $desc ? "-desc" : "-asc"; $empires = $empires->search(undef, { order_by => {$sort => $order} }); } @@ -377,7 +376,7 @@ sub www_complete_builds { next unless ( $building->is_upgrading ); $building->finish_upgrade; } - return $self->wrap(sprintf('All building constuction completed! Back To Body', $request->param('body_id'))); + return $self->wrap(sprintf('All building construction completed! Back To Body', $request->param('body_id'))); } sub www_send_stellar_flare { @@ -407,7 +406,7 @@ sub www_send_meteor_shower { $body_id ||= $request->param('body_id'); my $body = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($body_id); foreach my $building (@{$body->building_cache}) { - next unless ('Infrastructure' ~~ [$building->build_tags]); + next unless (smartmatch('Infrastructure', any => [$building->build_tags])); # next if ( $building->class eq 'Lacuna::DB::Result::Building::PlanetaryCommand' ); $building->class('Lacuna::DB::Result::Building::Permanent::Crater'); $building->level(1); @@ -584,7 +583,7 @@ sub www_view_ships { if ($ship->task eq 'Travelling') { $out .= sprintf('%s
', $ship->task, $ship->id, $body_id); } - elsif ($ship->task ~~ [qw(Defend Orbiting)]) { + elsif (smartmatch($ship->task, any => [qw(Defend Orbiting)])) { my $target = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($ship->foreign_body_id); $out .= sprintf('%s
%s (%d, %d)
', $ship->task, $target->name, $target->x, $target->y, $ship->id, $body_id); } diff --git a/lib/Lacuna/Web/MissionCurator.pm b/lib/Lacuna/Web/MissionCurator.pm index de32b0d3..4f505805 100644 --- a/lib/Lacuna/Web/MissionCurator.pm +++ b/lib/Lacuna/Web/MissionCurator.pm @@ -5,7 +5,6 @@ use utf8; no warnings qw(uninitialized); extends qw(Lacuna::Web); use Lacuna::Constants qw(FOOD_TYPES ORE_TYPES); -use feature "switch"; use Module::Find; use UUID::Tiny ':std'; use Lacuna::Util qw(format_date); diff --git a/t/030_Body.t b/t/030_Body.t index 94183220..568932b7 100644 --- a/t/030_Body.t +++ b/t/030_Body.t @@ -2,6 +2,7 @@ use Test::More tests => 15; use Test::Deep; use Data::Dumper; use 5.010; +use Switch::Right; use TestClient; TestClient->clear_all_test_empires; @@ -45,13 +46,13 @@ ok($result->{result}{building}{energy_hour} > 0, 'command center is functional') $result = $tester->post('body', 'get_buildable', [$session_id, $home_planet, 3, 3, 'Food']); is($result->{result}{buildable}{'Algae Cropper'}{url}, '/algae', 'Can build buildings'); -ok('Food' ~~ $result->{result}{buildable}{'Algae Cropper'}{build}{tags}, 'Food'); -ok('Resources' ~~ $result->{result}{buildable}{'Algae Cropper'}{build}{tags}, 'Resources'); -ok('Now' ~~ $result->{result}{buildable}{'Malcud Fungus Farm'}{build}{tags}, 'Now'); +ok(smartmatch('Food', any => $result->{result}{buildable}{'Algae Cropper'}{build}{tags}), 'Food'); +ok(smartmatch('Resources', any => $result->{result}{buildable}{'Algae Cropper'}{build}{tags}), 'Resources'); +ok(smartmatch('Now', any => $result->{result}{buildable}{'Malcud Fungus Farm'}{build}{tags}), 'Now'); $result = $tester->post('body', 'get_buildable', [$session_id, $home_planet, 3, 3, 'Infrastructure']); -ok('Happiness' ~~ $result->{result}{buildable}{'University'}{build}{tags}, 'Happiness'); -ok('Infrastructure' ~~ $result->{result}{buildable}{'University'}{build}{tags}, 'Infrastructure'); -ok('Later' ~~ $result->{result}{buildable}{'Subspace Transporter'}{build}{tags}, 'Later'); +ok(smartmatch('Happiness', any => $result->{result}{buildable}{'University'}{build}{tags}), 'Happiness'); +ok(smartmatch('Infrastructure', any => $result->{result}{buildable}{'University'}{build}{tags}), 'Infrastructure'); +ok(smartmatch('Later', any => $result->{result}{buildable}{'Subspace Transporter'}{build}{tags}), 'Later'); $result = $tester->post('body', 'get_buildable', [$session_id, $home_planet, 3, 3, 'Waste']); cmp_ok($result->{result}{buildable}{'Waste Energy Plant'}{production}{happiness_hour}, '>=', 0, 'no negative happiness from waste buildings'); diff --git a/t/370_Medals.t b/t/370_Medals.t index 9955d41b..9e845fed 100644 --- a/t/370_Medals.t +++ b/t/370_Medals.t @@ -3,6 +3,7 @@ use Test::More; use Test::Deep; use Data::Dumper; use 5.010; +use Switch::Right; $|=1; @@ -19,7 +20,7 @@ closedir $dir; foreach my $key (@medals) { my $file = $key.'.png'; - ok($file ~~ @images, $key); + ok(smartmatch($file, any => \@images), $key); } -- 2.51.2