Subject: | RFE: Mutually exclusive parameters (patch included) |
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
Message body not shown because it is not plain text.