use Mojolicious::Lite (perl) - I want to get a list of all PARAMS into a simple @ARRAY

315 Views Asked by At

https://<server_name>/getparam?h1=hello&h2=goodbye

get 'getparam' => sub {
  my $c = shift;
  print $c->param('h1') . "\n";       # THIS WORKS AS I WOULD EXPECT
  my @list_of_all_params = $c->param; # DOES NOT WORK and THIS IS WHAT I WOULD LIKE TO MAKE WORK
  return 1;
};

So all I actually want is for @list_of_all_params to contain "h1" and "h2" which is the params passed using the: https://<server_name>/getparam?h1=hello&h2=goodbye

Thank you to everyone in-advance!

1

There are 1 best solutions below

1
AudioBubble On BEST ANSWER

Perhaps

  # Dump the query as a hash
  warn Data::Dumper->new([\$c->req()->params()->to_hash()],[qw(*text)])->Dump(),' ';
  # Dump the names in the query
  warn Data::Dumper->Dump([\$c->req()->params()->names],[qw(*params)]),' ';
  # Dump the values for each key of the query
  for my $key (@{$c->req()->params()->names}) {
       warn Data::Dumper->new([\$key,\$c->req()->every_param($key)],[qw(*key *values)])->Dump(),' ';
       };