Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: robert.stockdale [...] gmail.com
Cc:
AdminCc:

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



Subject: conditional parameters feature request
It would be nice to be able to set a parameter as mandatory iff another specific parameter is passed. Example: foo is optional bar is required baz is required if foo is passed.
Subject: Re: [rt.cpan.org #32737] conditional parameters feature request
Date: Mon, 28 Jan 2008 10:52:30 -0600 (CST)
To: Robert Stockdale via RT <bug-Params-Validate [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Mon, 28 Jan 2008, Robert Stockdale via RT wrote: Show quoted text
> It would be nice to be able to set a parameter as mandatory iff another > specific parameter is passed. > > Example: > > foo is optional > bar is required > baz is required if foo is passed.
Look in the docs for "depends". That feature exists. -dave /*=================================================== VegGuide.Org www.BookIRead.com Your guide to all that's veg. My book blog ===================================================*/
From: robert.stockdale [...] gmail.com
Very nice, but I would like to request an extension of the existing functionality. It would be nice to be able to set an 'or' condition for depends. Example: foo is optional bar is optional baz is optional if foo is passed, one of bar or baz is required. On Mon Jan 28 11:52:27 2008, autarch@urth.org wrote: Show quoted text
> On Mon, 28 Jan 2008, Robert Stockdale via RT wrote: >
> > It would be nice to be able to set a parameter as mandatory iff another > > specific parameter is passed. > > > > Example: > > > > foo is optional > > bar is required > > baz is required if foo is passed.
> > Look in the docs for "depends". That feature exists. > > > -dave > > /*=================================================== > VegGuide.Org www.BookIRead.com > Your guide to all that's veg. My book blog > ===================================================*/
On Wed Feb 06 10:52:41 2008, stocks29 wrote: Show quoted text
> Very nice, but I would like to request an extension of the existing > functionality. > > It would be nice to be able to set an 'or' condition for depends. > Example: > > foo is optional > bar is optional > baz is optional > > if foo is passed, one of bar or baz is required. > > On Mon Jan 28 11:52:27 2008, autarch@urth.org wrote:
> > On Mon, 28 Jan 2008, Robert Stockdale via RT wrote: > >
> > > It would be nice to be able to set a parameter as mandatory iff another > > > specific parameter is passed. > > > > > > Example: > > > > > > foo is optional > > > bar is required > > > baz is required if foo is passed.
> > > > Look in the docs for "depends". That feature exists. > > > > > > -dave > > > > /*=================================================== > > VegGuide.Org www.BookIRead.com > > Your guide to all that's veg. My book blog > > ===================================================*/
> >
Robert - if you are still interested, check out Params::Validate::Dependencies (https://metacpan.org/module/Params::Validate::Dependencies ) which wraps Params::Validate to provides "any_of", "all_of", "one_of" and "none_of" options (which can be combined) The attached file shows your second request (bar or baz must be present if foo is)
Subject: test2.pl
#!/usr/bin/perl use Test::Most; use Params::Validate::Dependencies ':all'; sub options { my $args = validate( @_, { foo => { type => SCALAR, optional => 1 }, bar => { type => SCALAR, optional => 1 }, baz => { type => SCALAR, optional => 1 }, }, one_of( # none_of('foo'), # all_of( 'foo', one_of( 'bar', 'baz' ) ) ), ); } ok options(), "no foo"; ok options( foo => 1, bar => 1 ), "foo with bar"; ok options( foo => 1, baz => 1 ), "foo with baz"; dies_ok { options( foo => 1 ) } "foo with no bar or baz";
Thanks Awesome! Thanks Michael. I've changed jobs since I submitted the original ticket, but I'll definitely keep this in mind for future work :-) On Mon Sep 30 11:23:57 2013, mjemmeson wrote: Show quoted text
> On Wed Feb 06 10:52:41 2008, stocks29 wrote:
> > Very nice, but I would like to request an extension of the existing > > functionality. > > > > It would be nice to be able to set an 'or' condition for depends. > > Example: > > > > foo is optional > > bar is optional > > baz is optional > > > > if foo is passed, one of bar or baz is required. > > > > On Mon Jan 28 11:52:27 2008, autarch@urth.org wrote:
> > > On Mon, 28 Jan 2008, Robert Stockdale via RT wrote: > > >
> > > > It would be nice to be able to set a parameter as mandatory iff > > > > another > > > > specific parameter is passed. > > > > > > > > Example: > > > > > > > > foo is optional > > > > bar is required > > > > baz is required if foo is passed.
> > > > > > Look in the docs for "depends". That feature exists. > > > > > > > > > -dave > > > > > > /*=================================================== > > > VegGuide.Org www.BookIRead.com > > > Your guide to all that's veg. My book blog > > > ===================================================*/
> > > >
> > Robert - if you are still interested, check out > Params::Validate::Dependencies > (https://metacpan.org/module/Params::Validate::Dependencies ) which > wraps Params::Validate to provides "any_of", "all_of", "one_of" and > "none_of" options (which can be combined) > > The attached file shows your second request (bar or baz must be > present if foo is)