Discussion:
Elegantly copy items of a hash returned from DBI to $c->param
(too old to reply)
Viktor Nacht
2018-09-29 18:16:03 UTC
Permalink
So I have a simple hash:

{ a => 'b', b => 'c' }

That I would like to turn into params per the
Mojolicious::Plugin::TagHelpers docs:

You can also use "param" in Mojolicious::Plugin::DefaultHelpers to set them
manually and let necessary attributes always be generated automatically.
It appears $c->param can only set one parameter at a time. Obviously I
could write a helper to copy the hash over one param at time, but I was
wondering if there was a more elegant way to do it. For example, is there a
way to access the Mojo::Parameters append method from the controller?
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Stefan Adams
2018-09-30 03:14:26 UTC
Permalink
Try $c->req->params
<https://mojolicious.org/perldoc/Mojo/Message/Request#params>

pairs() is what you're looking for but you might consider append() and
merge() as well.

$c->req->params->pairs([a => 'b', b => 'c']);

I haven't tried it myself, but the documentation seems to indicate to me
this would work! :D
Post by Viktor Nacht
{ a => 'b', b => 'c' }
That I would like to turn into params per the
You can also use "param" in Mojolicious::Plugin::DefaultHelpers to set
them manually and let necessary attributes always be generated
automatically.
It appears $c->param can only set one parameter at a time. Obviously I
could write a helper to copy the hash over one param at time, but I was
wondering if there was a more elegant way to do it. For example, is there a
way to access the Mojo::Parameters append method from the controller?
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Viktor Nacht
2018-10-02 22:19:03 UTC
Permalink
This was the ticket, I ended up using append. Thank you for the pointer, it
really helped.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...