From 2e5edfdcf07500a8ea13cdceabfd6d9c08861e71 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 21 Nov 2022 18:09:14 -0500 Subject: [PATCH] fix(tools): return complete subroutine results in anvil-access-module --- tools/anvil-access-module | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/anvil-access-module b/tools/anvil-access-module index 0be4860e..1591698c 100755 --- a/tools/anvil-access-module +++ b/tools/anvil-access-module @@ -199,17 +199,17 @@ if ($sql_query) } elsif ($anvil->${sub_module_name}->can($sub_name)) { - my $decoded_sub_params; - my $is_decode_sub_params_success = eval { $decoded_sub_params = decode_json($sub_params); }; + my $decoded_sub_params; + my $is_decode_sub_params_success = eval { $decoded_sub_params = decode_json($sub_params); }; - if (not $is_decode_sub_params_success) - { - print STDERR "error: failed to parse subroutine parameters\n"; - $anvil->nice_exit({ exit_code => 1 }); - } + if (not $is_decode_sub_params_success) + { + print STDERR "error: failed to parse subroutine parameters\n"; + $anvil->nice_exit({ exit_code => 1 }); + } - my $results = $anvil->${sub_module_name}->${sub_name}($decoded_sub_params); - print JSON->new->utf8->encode({ sub_results => $results })."\n"; + my (@results) = $anvil->${sub_module_name}->${sub_name}($decoded_sub_params); + print JSON->new->utf8->encode({ sub_results => scalar(@results) > 1 ? \@results : $results[0] })."\n"; } elsif ($data_hash) { @@ -230,7 +230,7 @@ elsif ($data_hash) if (not $is_decode_data_hash_success) { print STDERR "error: failed to parse data structure\n"; - $anvil->nice_exit({ exit_code => 1 }); + $anvil->nice_exit({ exit_code => 1 }); } my $get_anvil_data_params = { data => {} };