Bugzilla – Attachment 163850 Details for
Bug 36419
Ambiguous return value in GetPlugins
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[POC] Bug 36419: Use wantarray to control return value
POC-Bug-36419-Use-wantarray-to-control-return-valu.patch (text/plain), 2.51 KB, created by
Tomás Cohen Arazi (tcohen)
on 2024-03-25 18:07:49 UTC
(
hide
)
Description:
[POC] Bug 36419: Use wantarray to control return value
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2024-03-25 18:07:49 UTC
Size:
2.51 KB
patch
obsolete
>From 3108ffa2f4dc9091d62e57ee14f3a27c63112175 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 25 Mar 2024 15:07:32 -0300 >Subject: [PATCH] [POC] Bug 36419: Use wantarray to control return value > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > 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<bad> part of the response will only get returned If you pass I<errors>. > > 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.44.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36419
:
163850
|
163895