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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.