Hello dear esteemed monks,
I just tried to implement mojo-like path info handling in my own toy framework:
get '/from/:foo/to/:bar' => sub {
my $req = shift;
return { -content => "foo=".$req->param("foo", '\d+') };
};
It kind of works, but wasn't yet committed to master and/or CPAN.
The thing is, my param() method has a mandatory regex filter (much like perl's own -T switch). There's also a built-in way to impose such filter upon the URI tail (parameter called path_info_regex).
This made me think of combining the two and specifying parameter regex right in the URI. I've come up with the following variants:
- /:foo(regex) - requires parsing the parentheses and not too readable;
- /<foo=regex> - looks awkward and not similar to other frameworks;
- /:foo + param_regex hash - need to duplicate parameter names;
- just sticking with Mojo conventions - need to duplicate parameter validation
Maybe there is a more compact and readable way?
Thank you!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.