Skip to content

Commit

Permalink
Eliminate dependency on IO::Scalar; we have open()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuelsmann committed Jan 4, 2025
1 parent 6e98ab1 commit 424eaf7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
1 change: 0 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions lib/LedgerSMB/Template/Plugin/XLSX.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

use v5.36;
use warnings;

package LedgerSMB::Template::Plugin::XLSX;

=head1 NAME
Expand All @@ -11,10 +14,6 @@ Implements C<LedgerSMB::Template>'s FORMATTER protocol for XLSX output.
=cut

use strict;
use warnings;

use IO::Scalar;
use Excel::Writer::XLSX;
use Spreadsheet::WriteExcel;
use XML::Twig;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions t/16-schema-upgrade-html.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -175,7 +174,7 @@ check 'title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
ok( lives { @checks = load_checks($fh); is scalar @checks, 1 },
'Loading a single check from file-handle');

Expand Down Expand Up @@ -231,7 +230,7 @@ check 'title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
ok( lives { @checks = load_checks($fh); is scalar @checks, 1 },
'Loading a single check from file-handle');

Expand Down Expand Up @@ -285,7 +284,7 @@ check 'title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
ok( lives { @checks = load_checks($fh); is scalar @checks, 1 },
'Loading a single check from file-handle');

Expand Down Expand Up @@ -339,7 +338,7 @@ check 'title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
ok( lives { @checks = load_checks($fh); is scalar @checks, 1 },
'Loading a single check from file-handle');

Expand Down Expand Up @@ -411,7 +410,7 @@ check 'title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
ok(lives { @checks = load_checks($fh); is scalar @checks, 1 },
'Loading a single check from file-handle');

Expand Down
9 changes: 4 additions & 5 deletions t/16-schema-upgrade-json.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -90,7 +89,7 @@ check 'first title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
ok(lives { @checks = load_checks($fh); is scalar @checks, 1 },
'Loading a single check from file-handle');

Expand Down Expand Up @@ -143,7 +142,7 @@ check 'second title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
ok( lives { @checks = load_checks($fh); is scalar @checks, 1 },
'Loading a single check from file-handle');

Expand Down Expand Up @@ -198,7 +197,7 @@ check 'third title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
ok( lives { @checks = load_checks($fh); is scalar @checks, 1 },
'Loading a single check from file-handle');

Expand Down Expand Up @@ -310,7 +309,7 @@ check 'fifth title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
ok( lives { @checks = load_checks($fh); is scalar @checks, 1 },
'Loading a single check from file-handle');

Expand Down
17 changes: 8 additions & 9 deletions t/16-schema-upgrade-precheck.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -53,7 +52,7 @@ package PreCheckTests;
HEREDOC


my $fh = IO::Scalar->new(\$tests);
open my $fh, '<', \$tests;
ok( lives { is scalar &load_checks($fh), 0; } ,
'Loading empty checks from file-handle');

Expand Down Expand Up @@ -86,7 +85,7 @@ check 'title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
ok( lives { is scalar &load_checks($fh), 1; },
'Loading a single check from file-handle');

Expand Down Expand Up @@ -114,7 +113,7 @@ check 'title2',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
ok( lives { is scalar &load_checks($fh), 2; },
'Loading two checks from file-handle');

Expand Down Expand Up @@ -142,7 +141,7 @@ check 'title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
like( dies { &load_checks($fh); },
qr/^Multiple checks with the same name not supported/,
'Loading two equally named checks from file-handle');
Expand Down Expand Up @@ -170,7 +169,7 @@ check 'title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
like( dies { &load_checks($fh); }, qr/doesn't define a description/,
'"check" keyword bails without a description');

Expand All @@ -188,7 +187,7 @@ check 'title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
like( dies { &load_checks($fh); }, qr/doesn't define a query/,
'"check" keyword bails without a query');

Expand All @@ -207,7 +206,7 @@ check 'title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
like( dies { &load_checks($fh); }, qr/doesn't define 'on_submit'/,
'"check" keyword bails without an "on_submit"');

Expand All @@ -226,7 +225,7 @@ check 'title',
1;
HEREDOC

$fh = IO::Scalar->new(\$tests);
open $fh, '<', \$tests;
like( dies { &load_checks($fh); }, qr/doesn't define 'on_failure'/,
'"check" keyword bails without an "on_failure"');

Expand Down
14 changes: 9 additions & 5 deletions xt/43-schema-upgrades.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -87,7 +87,8 @@ check 'test_success',
1;
|;

my @checks = load_checks(IO::Scalar->new(\$check_def));
open $fh, '>', \$check_def;
my @checks = load_checks($fh);

ok(run_checks($dbh, checks => \@checks),
'Checks successfully completed');
Expand Down Expand Up @@ -122,7 +123,8 @@ check 'test_failure',
1;
|;

@checks = load_checks(IO::Scalar->new(\$check_def));
$check_def = '';
@checks = load_checks($fh);

run_with_formatters {
ok(! run_checks($dbh, checks => \@checks),

Check failure on line 130 in xt/43-schema-upgrades.t

View workflow job for this annotation

GitHub Actions / test-remainder (5.38, 14, chrome, 1, 3)

( DIAG ) job 5

Check failure on line 130 in xt/43-schema-upgrades.t

View workflow job for this annotation

GitHub Actions / test-remainder (5.40, 13, operablink, 1, 7)

( DIAG ) job 5

Check failure on line 130 in xt/43-schema-upgrades.t

View workflow job for this annotation

GitHub Actions / test-remainder (5.36, 15, firefox, 1, 7)

( DIAG ) job 5
Expand Down Expand Up @@ -174,7 +176,8 @@ check 'test_success_2',
1;
|;

@checks = load_checks(IO::Scalar->new(\$check_def));
$check_def = '';
@checks = load_checks($fh);

run_with_formatters {
ok(run_checks($dbh, checks => \@checks),
Expand Down Expand Up @@ -216,7 +219,8 @@ check 'test_failure',
1;
|;

@checks = load_checks(IO::Scalar->new(\$check_def));
$check_def = '';
@checks = load_checks($fh);

my $grid_rows;
run_with_formatters {
Expand Down

0 comments on commit 424eaf7

Please sign in to comment.