Skip Menu |
 

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

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

People
Owner: DROLSKY [...] cpan.org
Requestors: djerius [...] cfa.harvard.edu
Cc:
AdminCc:

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



Subject: RFE: Mutually exclusive parameters (patch included)
Download (untitled) / with headers
text/plain 1.8k
Hi. I've attached a patch to version 0.72 that adds support for mutually exclusive parameters. Here's the blurb from the updated documentation: Mutually Exclusive Parameters It is possible to specify that two or more parameters are mutually exclusive and should not be present at the same time. There are several ways to do this, depending upon the complexity of the relationships between the parameters. One or more sets of parameters may be specified with the "excludes" option to "validate_with()": validate_with( params => \@_, spec => \%spec, excludes => [ qw/ foo bar / ] ); Here, only one of "foo" or "bar" may be present. Multiple independent sets are specified as nested arrays: validate_with( params => \@_, spec => \%spec, excludes => [ [ qw/ foo bar / ], [ qw/ goo sna / ] ] ); In more complicated cases, a single parameter may exclude others which do not exclude each other. For example, if "foo" may not appear with either "bar" or "baz", but it is permitted that "bar" and "baz" appear together, the above specification will not work. Instead, one can either specify two exclusion lists: excludes => [ [ qw/ foo bar / ], [ qw/ foo baz / ] ] or can specify the exclusion in the parameter spec: spec => { foo => { excludes => qw/ bar baz / } } which may be more intuitive. Dependencies are checked before exclusions. The "validate_pos()" version of exclusions is slightly different, in that you can only exclude one other parameter. Also, if for example, the second parameter excludes the third parameter, then it implies an exclusion of all parameters beyond the third. "Params::Validate" will die if you try to exclude a parameter not declared as part of your parameter specification. Thanks, Diab
Download patch-Params-Validate-0.72
application/octet-stream 30.3k

Message body not shown because it is not plain text.

From: edwardjsabol [...] iname.com
Download (untitled) / with headers
text/plain 669b
Show quoted text
> I've attached a patch to version 0.72 that adds support for mutually > exclusive parameters. Here's the blurb from the updated > documentation:
This rocks. I needed functionality just like this for the project I'm working on, so I applied the patch. I did get a compilation error in Validate.xs concerning the groups variable not being declared. I needed to added an open brace right before the line where groups is defined and a matching close brace near the end of that subroutine. Standard C only allows variables to be declared at the beginning of a code block. The patch applies cleanly to version 0.74 except that the exclude tests need to be renumbered.
Download (untitled) / with headers
text/plain 839b
On Wed Jun 23 17:35:21 2004, guest wrote: Show quoted text
> > I've attached a patch to version 0.72 that adds support for mutually > > exclusive parameters. Here's the blurb from the updated > > documentation:
> > This rocks. I needed functionality just like this for the project I'm > working on, so I applied the patch. I did get a compilation error in > Validate.xs concerning the groups variable not being declared. I needed > to added an open brace right before the line where groups is defined and > a matching close brace near the end of that subroutine. Standard C only > allows variables to be declared at the beginning of a code block. The > patch applies cleanly to version 0.74 except that the exclude tests need > to be renumbered.
This is exactly what I need for what I'm working on too; any ideas on an ETA of when it'll be applied?
Any motion on this?
Subject: Re: [rt.cpan.org #5701] RFE: Mutually exclusive parameters (patch included)
Date: Sun, 14 Feb 2010 08:43:11 -0600 (CST)
To: Christopher Nehren via RT <bug-Params-Validate [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
Download (untitled) / with headers
text/plain 630b
On Sun, 14 Feb 2010, Christopher Nehren via RT wrote: Show quoted text
> Any motion on this?
Doh. Basically, I'm not too keen on expanding the Params::Validate API, since I don't think it's that good an API in the first place. Over the years, I've vaguely contemplated building a new module. Anything I do build would probably build on type of Moose types like MooseX::Params::Validate. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
RT-Send-CC: autarch [...] urth.org, edwardjsabol [...] iname.com
Download (untitled) / with headers
text/plain 754b
I just uploaded Params::Validate::Dependencies to the CPAN, after discussing it briefly with Dave Rolsky. It provides support for mutually exclusive params thus: validate(@_, { alpha => { type => ARRAYREF, optional => 1 }, beta => { type => ARRAYREF, optional => 1 }, gamma => { type => ARRAYREF, optional => 1 }, bar => { type => SCALAR, optional => 1 }, baz => { type => SCALAR, optional => 1 }, }, one_of(qw(bar baz)) ); which makes either bar or baz compulsory. Or if you want them both to be optional, but they can't both be present at the same time ... any_of( none_of(qw(bar baz)), one_of(qw(bar baz)) ) There's also an all_of, to complete the set of Boolean operators.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.