Hello dear esteemed monks,

I'm working on a toy web framework. One of its key features is that fetching user input, like cookies and parameters, requires regexp-based validation.

The API is as follows:

my $request = shift; my $foo = $request->param( foo => '\d+' );

This would only return a value when the WHOLE foo parameter matches regexp (one or more digits in this case), empty string* (or a sane default provided as optional third argument) otherwise.

For now, this API deliberately ignores multi-valued query parameters, only using the LAST value. The time has come to fill this gaping hole.

I'm thinking of the following method:

my $request = shift; $request->param_arrayref( bar => '\d+' );

Note that we don't rely on calling context, but require an explicit statement ("list expected!") instead.

One thing I'm confused about is what I should do if the value passed by user contains both matching and non-matching values. Filter out matching ones? Return empty array? Return undef (and possibly break someone's code in runtime)? Croak is not a variant - this is left for the user.

I'm leaning towards the second options (a missing array is MUCH easier to debug than a missing element in the array). But may be there are other concerns? Or am I doing it wrong altogether? And btw, can arrayref be shortened to just array?

Last but not least, what could be the real-life usage examples of passing the same argument multiple times in a web form? I'd rather do some trial and error as well as write a meaningful example which I can click through with my browser.

Thank you,

*To be replaced with undef in next version.


In reply to Cool uses for multi-value GET/POST parameters by Dallaylaen

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.