I wasn't aware til you posted that there was a validate_with() function. Usually, Params::Validate is as concise as you said you desired. I've also never desired to have case-insensitive named parameters. I suppose that might be desireable. It looks like you'd want to have used the Params::Validate::validate_options() function to set that sort of policy for your package if that that's really common. Then it looks like you can go back to the normal, concise calling form.

So... my experience is that if you want simple cases, that's simple to use. I've wanted slightly more complex things like named validation for my parameters - then I've just made named constants for those.

# Restrict row ids to potential or all valid IDs # -1 1..inf use constant ROW_ID => { regex => qr/^$RE{num}{int}$/, callbacks => { valid => sub { local $_ = shif +t; $_ == -1 or $_ >= 1 +} } }; # Restrict row ids to things that are actually valid. # 1 .. inf use constant VALID_ROW_ID => { regex => qr/^$RE{num}{int}$/, callbacks => { valid => sub { local $_ += shift; defined() + && $_ >= 1 } } }; sub example_method { my $self = shift; my %p = validate_pos( @_, { handle => 1, thing => 1, something_else => VALID_ROW_ID } ); ... }

In reply to Re^3: RFC named parameter syntactic sugar by diotalevi
in thread RFC named parameter syntactic sugar by snowhare

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.