Params::Validate has too many features, (I know that sounds odd, but read on). It is also slow.

Too Many Features?

Yah. In trying to solve the generalized problem of parameter validation (which makes it darn useful - but only in specialized situations), it makes the simple cases complex. This is precisely the problem that my idea of adding some syntactic sugar proposes to address.

use Params::Validate qw (validate_with); sub example_method { my $self = shift; my %args = validate_with ( params => \@_, spec => { thing => 1, handle => 1 }, normalize_keys => sub { return lc($_[0]); }, ); my ($handle, $thing) = @args{'handle','thing'}; #... }

Uh huh. How long did it take you to figure out exactly what it was doing? That does the same thing as:

use Class::ParmList qw (simple_parms); sub example_method { my $self = shift; my ($handle, $thing) = simple_parms(['handle','thing'],@_); #... }

Except Params::Validate does it half as fast and considerably less clearly.

Ideally, I want Sub::Parms to do be able to do something like this:

use Sub::Parms; sub example_method { Invokation : $self; NamedParam : $handle (+handle); NamedParam : $thing (+thing); #... }

and have it run at the same speed as this (which is about 3x faster than Params::Validate and almost 2x faster than Class::ParmList is while doing exactly the same thing):

sub example_method { my $self = shift; my %args; { my %raw_args = @_; %args = map {lc($_) => $raw_args{$_}} keys %raw_args; } unless ($args{'handle'}) { croak("Missing 'handle' argument"); } unless ($args{'thing'}) { croak("Missing 'thing' argument"); } unless (4 == @_) { croak("Unexpected extra parameters"); } my ($handle,$thing) = @args{'handle','thing'}; #... }

The idea is that the simple cases should be simple and clear.


In reply to Re^2: RFC named parameter syntactic sugar by snowhare
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.