I'm writing yet another paging data browser, and I was tired of needing to pass all the "interesting" query parameters around manually, because eventually, I'd forget one important parameter and wonder why my query would look weird or not page properly.
So I asked diotalevi what convenient existing wheels are out there that can change some parameters of the current query, but not all. And diotalevi pointed me to CGI, which gives me the current query as an object. All I had to do was to get a CGI object, add the "new" parameters, and look at the query part of the CGI object. Instant sticky parameters. I haven't added a whitelist/blacklist thing for non-sticky parameters, but it wouldn't be hard.
Update: blokhead rightfully points out that this will not work with multi-valued form elements. Enabling that will need some kind of real parsing, which I avoid because I don't need multi-valued parameters (yet).
use CGI; use URI; =head2 C<< link $ARGREF >> Returns a link to the current query, modified by C<$ARGREF>, suitable for use from within Template Toolkit. Very convenient if you want to page through a sorted set. All CGI query parameters are preserved. =cut sub link { my ($args) = @_; my %V = (%{ CGI->new->Vars }, %$args); return URI->new(CGI->new(\%V)->url(-full => 1, -query => 1))->query; };
In reply to Easy sticky query parameters outside of HTML forms by Corion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |