From c2eeeae7f81993db5e285a0ba9d72c8ba4a532be Mon Sep 17 00:00:00 2001 From: Erik Huelsmann Date: Sat, 4 Jan 2025 01:11:57 +0100 Subject: [PATCH] Eliminate dependency on IO::Scalar; we have open() --- Changelog | 2 ++ cpanfile | 1 - lib/LedgerSMB/Template/Plugin/XLSX.pm | 14 +++++++++----- t/16-schema-upgrade-html.t | 16 ++++++++++------ t/16-schema-upgrade-json.t | 13 ++++++++----- t/16-schema-upgrade-precheck.t | 25 ++++++++++++++++--------- xt/43-schema-upgrades.t | 18 +++++++++++++----- xt/perlcriticrc | 1 + 8 files changed, 59 insertions(+), 31 deletions(-) diff --git a/Changelog b/Changelog index 454a314be9..434646a102 100644 --- a/Changelog +++ b/Changelog @@ -19,6 +19,8 @@ Cleanup & architecture improvements * Loading of main section more predictable through state machine use (#8530) Updated dependencies +* Feature::Compat::Try (removed) +* IO::Scalar (removed) Changelog for 1.12 Series diff --git a/cpanfile b/cpanfile index 93caf4e80f..ee73d0f8ba 100644 --- a/cpanfile +++ b/cpanfile @@ -29,7 +29,6 @@ requires 'HTTP::AcceptLanguage'; requires 'HTTP::Headers::Fast', '0.21'; # for content_is_text() method requires 'HTTP::Negotiate', '6.01'; requires 'HTTP::Status'; -requires 'IO::Scalar'; requires 'JSON::MaybeXS'; requires 'JSONSchema::Validator', '0.010'; recommends 'Cpanel::JSON::XS', '3.0206'; # 3.0206 adds 'allow_bignum' option diff --git a/lib/LedgerSMB/Template/Plugin/XLSX.pm b/lib/LedgerSMB/Template/Plugin/XLSX.pm index 59bc8e533a..c61b688318 100644 --- a/lib/LedgerSMB/Template/Plugin/XLSX.pm +++ b/lib/LedgerSMB/Template/Plugin/XLSX.pm @@ -1,4 +1,7 @@ +use v5.36; +use warnings; + package LedgerSMB::Template::Plugin::XLSX; =head1 NAME @@ -11,10 +14,6 @@ Implements C's FORMATTER protocol for XLSX output. =cut -use strict; -use warnings; - -use IO::Scalar; use Excel::Writer::XLSX; use Spreadsheet::WriteExcel; use XML::Twig; @@ -202,7 +201,12 @@ sub postprocess { # Excel::Writer::XLSX wants a filehandle or filename, so # convert the variable reference into a filehandle my $output = $config->{_output}; - $output = IO::Scalar->new($output) if ref $output; + + if (ref $output) { + open(my $fh, '>', $output) + or die "Unable to create a filehandle to \$output: $!"; + $output = $fh; + } if (lc $self->format eq 'xlsx') { $workbook = Excel::Writer::XLSX->new($output); diff --git a/t/16-schema-upgrade-html.t b/t/16-schema-upgrade-html.t index 4f21e7cce1..6eea0fdff6 100644 --- a/t/16-schema-upgrade-html.t +++ b/t/16-schema-upgrade-html.t @@ -9,7 +9,6 @@ use Data::Dumper; use DBI; use Digest::MD5 qw( md5_hex ); use File::Temp qw( :seekable ); -use IO::Scalar; use MIME::Base64; use Plack::Request; @@ -175,7 +174,8 @@ check 'title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die "$!"; ok( lives { @checks = load_checks($fh); is scalar @checks, 1 }, 'Loading a single check from file-handle'); @@ -231,7 +231,8 @@ check 'title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; ok( lives { @checks = load_checks($fh); is scalar @checks, 1 }, 'Loading a single check from file-handle'); @@ -285,7 +286,8 @@ check 'title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; ok( lives { @checks = load_checks($fh); is scalar @checks, 1 }, 'Loading a single check from file-handle'); @@ -339,7 +341,8 @@ check 'title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; ok( lives { @checks = load_checks($fh); is scalar @checks, 1 }, 'Loading a single check from file-handle'); @@ -411,7 +414,8 @@ check 'title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; ok(lives { @checks = load_checks($fh); is scalar @checks, 1 }, 'Loading a single check from file-handle'); diff --git a/t/16-schema-upgrade-json.t b/t/16-schema-upgrade-json.t index 4cacaea24a..b39c160e4c 100644 --- a/t/16-schema-upgrade-json.t +++ b/t/16-schema-upgrade-json.t @@ -8,7 +8,6 @@ use Data::Dumper; use DBI; use Digest::MD5 qw( md5_hex ); use File::Temp qw( :seekable ); -use IO::Scalar; use MIME::Base64; use Plack::Request; @@ -90,7 +89,8 @@ check 'first title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; ok(lives { @checks = load_checks($fh); is scalar @checks, 1 }, 'Loading a single check from file-handle'); @@ -143,7 +143,8 @@ check 'second title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; ok( lives { @checks = load_checks($fh); is scalar @checks, 1 }, 'Loading a single check from file-handle'); @@ -198,7 +199,8 @@ check 'third title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; ok( lives { @checks = load_checks($fh); is scalar @checks, 1 }, 'Loading a single check from file-handle'); @@ -310,7 +312,8 @@ check 'fifth title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; ok( lives { @checks = load_checks($fh); is scalar @checks, 1 }, 'Loading a single check from file-handle'); diff --git a/t/16-schema-upgrade-precheck.t b/t/16-schema-upgrade-precheck.t index 6f28ba9bc7..4bfce464f6 100755 --- a/t/16-schema-upgrade-precheck.t +++ b/t/16-schema-upgrade-precheck.t @@ -11,7 +11,6 @@ use LedgerSMB::Database::ChangeChecks qw( :DEFAULT run_with_formatters use Data::Dumper; use DBI; use File::Temp qw( :seekable ); -use IO::Scalar; use MIME::Base64; @@ -53,7 +52,8 @@ package PreCheckTests; HEREDOC -my $fh = IO::Scalar->new(\$tests); +open my $fh, '<', \$tests + or die $!; ok( lives { is scalar &load_checks($fh), 0; } , 'Loading empty checks from file-handle'); @@ -86,7 +86,8 @@ check 'title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; ok( lives { is scalar &load_checks($fh), 1; }, 'Loading a single check from file-handle'); @@ -114,7 +115,8 @@ check 'title2', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; ok( lives { is scalar &load_checks($fh), 2; }, 'Loading two checks from file-handle'); @@ -142,7 +144,8 @@ check 'title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; like( dies { &load_checks($fh); }, qr/^Multiple checks with the same name not supported/, 'Loading two equally named checks from file-handle'); @@ -170,7 +173,8 @@ check 'title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; like( dies { &load_checks($fh); }, qr/doesn't define a description/, '"check" keyword bails without a description'); @@ -188,7 +192,8 @@ check 'title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; like( dies { &load_checks($fh); }, qr/doesn't define a query/, '"check" keyword bails without a query'); @@ -207,7 +212,8 @@ check 'title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; like( dies { &load_checks($fh); }, qr/doesn't define 'on_submit'/, '"check" keyword bails without an "on_submit"'); @@ -226,7 +232,8 @@ check 'title', 1; HEREDOC -$fh = IO::Scalar->new(\$tests); +open $fh, '<', \$tests + or die $!; like( dies { &load_checks($fh); }, qr/doesn't define 'on_failure'/, '"check" keyword bails without an "on_failure"'); diff --git a/xt/43-schema-upgrades.t b/xt/43-schema-upgrades.t index 4b511809aa..4676e68f6e 100755 --- a/xt/43-schema-upgrades.t +++ b/xt/43-schema-upgrades.t @@ -24,12 +24,12 @@ use LedgerSMB::Database; use LedgerSMB::Database::ChangeChecks qw/load_checks run_checks run_with_formatters/; use DBI; -use IO::Scalar; use Carp::Always; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($OFF); +my $fh; ####### Create test run conditions @@ -87,7 +87,9 @@ check 'test_success', 1; |; -my @checks = load_checks(IO::Scalar->new(\$check_def)); +open $fh, '<', \$check_def + or die $!; +my @checks = load_checks($fh); ok(run_checks($dbh, checks => \@checks), 'Checks successfully completed'); @@ -122,7 +124,9 @@ check 'test_failure', 1; |; -@checks = load_checks(IO::Scalar->new(\$check_def)); +open $fh, '<', \$check_def + or die $!; +@checks = load_checks($fh); run_with_formatters { ok(! run_checks($dbh, checks => \@checks), @@ -174,7 +178,9 @@ check 'test_success_2', 1; |; -@checks = load_checks(IO::Scalar->new(\$check_def)); +open $fh, '<', \$check_def + or die $!; +@checks = load_checks($fh); run_with_formatters { ok(run_checks($dbh, checks => \@checks), @@ -216,7 +222,9 @@ check 'test_failure', 1; |; -@checks = load_checks(IO::Scalar->new(\$check_def)); +open $fh, '<', \$check_def + or die $!; +@checks = load_checks($fh); my $grid_rows; run_with_formatters { diff --git a/xt/perlcriticrc b/xt/perlcriticrc index b7744efe16..6b268886b8 100644 --- a/xt/perlcriticrc +++ b/xt/perlcriticrc @@ -121,6 +121,7 @@ pager = less set_themes = lsmb lsmb_new [Modules::RequireExplicitPackage] set_themes = lsmb lsmb_new lsmb_old + allow_import_of = v5.36 experimental warnings [Modules::RequireFilenameMatchesPackage] set_themes = lsmb lsmb_new lsmb_old_wip lsmb_tests