in reply to Re^2: RFC named parameter syntactic sugar
in thread RFC named parameter syntactic sugar

The mistake Params::Validate makes is that it doesn't allow you to create what your simple case is. There should be a set of import parameters that specify exactly what the default handling for validate() should be, thus allowing you to customize it on a per-file basis. Or, allow the spec to be read from a datastore (such as a config file or files), allowing it to be global for a project. Oh, and that customization has to allow me to set callbacks when and where I need them, for custom validation and error-handling. And I have to be able to override the config file(s) in the use line.

THAT would be the featureset that would get me to use it. Otherwise, it's just too much trouble for very little gain.


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
  • Comment on Re^3: RFC named parameter syntactic sugar

Replies are listed 'Best First'.
Re^4: RFC named parameter syntactic sugar
by diotalevi (Canon) on Oct 19, 2005 at 15:36 UTC

    What, this doesn't cover it?

    use Params::Validate; Params::Validate::validate_options( normalize_keys => sub { map { local $_ = uc; s/^-//; $_ } @_ } );
Re^4: RFC named parameter syntactic sugar
by xdg (Monsignor) on Oct 19, 2005 at 15:57 UTC
    The mistake Params::Validate makes is that it doesn't allow you to create what your simple case is.

    That's not quite true. There is the validation_options function, which sets per-package defaults.

    Params::Validate::validation_options( normalize_keys => sub { $_[0] =~ s/^-//; lc $_[0] } );

    You can also define parameter specs up front and re-use them. (Or put them in a config file/module for reuse across an app.)

    my %specs_for = ( foo => # specify a type { type => ARRAYREF }, bar => # specify an interface { can => [ 'print', 'flush', 'frobnicate' ] }, baz => { type => SCALAR, # a scalar ... # ... that is a plain integer ... regex => qr/^\d+$/, callbacks => { # ... and smaller than 90 'less than 90' => sub { shift() < 90 }, }, ); sub wibble { my %args = validate( @_, { foo => $specs_for{foo}, bar => $specs_for{baz}, }); # ... }

    So with very little up-front work, you can create re-usable parameter validation specs with a preset default case.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.