Skip Menu |

This queue is for tickets about the Params-Validate CPAN distribution.

Report information
The Basics
Id: 2598
Status: resolved
Priority: 0/
Queue: Params-Validate

People
Owner: Nobody in particular
Requestors: mark [...] summersault.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.57
Fixed in: (no value)



Subject: syntactic sugar: validate_pos(@_, 3, 2)
Hello, I'm a new Params::Validate user and I find it very useful. Thanks! I have a suggestion to improve the validate_pos() interface a bit, while still being backwards compatible. Currenty, as I understand the basic for of validate_pos(), it consists only of a string of 1's followed by a string of zeros. This is hard to read, and this not how I think about it. I think "3 required, 2 optional". Since only "0" and 1" are the integers used now, I'd like to see this kind of interface supported: validate_pos(@_,3,2); That would mean that the first three fields are required, followed by two optionals. This syntax also prevents this happening by accident(1,0,1,0,1); Thanks! Mark
Date: Mon, 19 May 2003 23:10:24 -0500 (CDT)
From: Dave Rolsky <autarch [...] urth.org>
To: via RT <bug-Params-Validate [...] rt.cpan.org>
Subject: Re: [cpan #2598] syntactic sugar: validate_pos(@_, 3, 2)
RT-Send-Cc:
On Sat, 17 May 2003, via RT wrote: Show quoted text
> I'm a new Params::Validate user and I find it very useful. Thanks! I > have a suggestion to improve the validate_pos() interface a bit, while > still being backwards compatible. > > Currenty, as I understand the basic for of validate_pos(), it consists > only of a string of 1's followed by a string of zeros. This is hard to > read, and this not how I think about it. I think "3 required, 2 > optional". > > Since only "0" and 1" are the integers used now, I'd like to see this > kind of interface supported:
Actually, only true or false values are used. For all I know someone is doing something like: validate_pos( @_, 'required', 'required', ... ); so I'm not going to require 0 or 1 only. Show quoted text
> validate_pos(@_,3,2); > > That would mean that the first three fields are required, followed by > two optionals. This syntax also prevents this happening by > accident(1,0,1,0,1);
You could just write a subroutine like this: sub required { (1) x $_[0] } sub optional { (0) x $_[0] } and then do this: validate_pos( @_, required(3), optional(2) ); -dave /*======================= House Absolute Consulting www.houseabsolute.com =======================*/