From 63058fc04714281c68e0d795a1c9ab8c425fbfbc Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 25 Mar 2024 15:07:32 -0300 Subject: [PATCH] Bug 36419: Use wantarray to control return value Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall --- Koha/Plugins.pm | 19 ++++++++++++++++--- plugins/plugins-home.pl | 4 ++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index d93e9fe40fc..1584ec3d1ad 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -187,9 +187,22 @@ method or metadata value. The method and metadata parameters are optional. If you pass multiple keys in the metadata hash, all keys must match. -If you pass errors (only used in plugins-home), we return two arrayrefs: +If called in scalar context, a different data structure is returned: - ( $good, $bad ) = Koha::Plugins::GetPlugins( { errors => 1 } ); + my $plugins = Koha::Plugins::GetPlugins({ + method => 'some_method', + metadata => { some_key => 'some_value' }, + [ all => 1, errors => 1, verbose => 1 ], + }); + +where I<$plugins> looks like: + + { + good => [ plugin_1, ... ], + bad => [ { error => 1, name => 'PluginClass1 }, ... ] + } + +The B part of the response will only get returned If you pass I. If you pass verbose, you can enable or disable explicitly warnings from Module::Load::Conditional. Disabled by default to not flood @@ -255,7 +268,7 @@ sub GetPlugins { } } - return $errors ? ( \@plugins, \@failing ) : @plugins; + return wantarray ? @plugins : { good => \@plugins, bad => \@failing }; } =head2 InstallPlugins diff --git a/plugins/plugins-home.pl b/plugins/plugins-home.pl index 60b3cde2135..3c507ff4c8a 100755 --- a/plugins/plugins-home.pl +++ b/plugins/plugins-home.pl @@ -50,7 +50,7 @@ if ($plugins_enabled) { method => $method, ); - my ( $plugins, $failures ) = Koha::Plugins->new()->GetPlugins( + my $plugins = Koha::Plugins->new()->GetPlugins( { method => $method, all => 1, @@ -58,7 +58,7 @@ if ($plugins_enabled) { } ); - $template->param( plugins => [ @$plugins, @$failures ] ); + $template->param( plugins => [ @{$plugins->{good}}, @{$plugins->{bad}} ] ); $template->param( plugins_restricted => C4::Context->config('plugins_restricted') ); $template->param( can_search => C4::Context->config('plugin_repos') ? 1 : 0 ); -- 2.30.2