Valida...Options(3pm)
π Validation::Class::Directive::Options β the manual, but make it make sense π
okay bestie, so this is a page from the User Contributed Perl Documentation (yes, 3pm, the perl module section, we love her), and it's all about one very specific little directive. Let's get into it. β¨
πΈ NAME πΈ
Validation::Class::Directive::Options</p> β the Options Directive for Validation Class Field Definitions. That's the whole name, no notes. π
π¦ VERSION π¦
version 7.900059</p> β yes, that's the version, and yes, it's giving very specific. Don't round it, don't truncate it, it's 7.900059 and that's final. π
β¨ SYNOPSIS β¨
here's the vibe in code, bestie, copy it exactly:
use Validation::Class::Simple;
my $rules = Validation::Class::Simple->new(
fields => {
user_role => {
options => 'Client'
}
}
);
# set parameters to be validated
$rules->params->add($parameters);
# validate
unless ($rules->validate) {
# handle the failures
}
so you build your $rules, you set your fields, you drop in an options => 'Client' situation, then you add your $parameters to params, then you validate β and if it doesn't validate (that's the unless), you go handle the failures. periodt. π
π DESCRIPTION π
Validation::Class::Directive::Options</p> is a core validation class field directive β main character energy, fr β and what she does is hold an enumerated list of values that get validated against the associated parameters. Like, you give her a menu of acceptable options and she checks your params against it. iconic. β¨
π alternative argument: an-array-of-user-defined-options π
bestie, this directive can be passed a single value or an array of values. both. she's flexible like that. π
fields => {
user_role => {
options => ['Client', 'Employee', 'Administrator']
}
}
and here's the thing β the following examples are useful for plugins (and other code) that may want to otherwise identify option values:
fields => {
user_role => {
options => [
'1|Client',
'2|Employee',
'3|Administrator'
]
}
}
β οΈ please note, and this is important, no cap: declaring options as "keyed-options" will cause the validation of the option's key and NOT the option's value. read that again. the KEY. not the value. it's giving sneaky. π
fields => {
user_role => {
options => [
[ 1 => 'Client' ],
[ 2 => 'Employee' ],
[ 3 => 'Administrator' ]
]
}
}
π AUTHOR π
Al Newkirk <anewkirk@ana.io> β the author, the icon, the moment. π«Ά
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2011 by Al Newkirk.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so like, go off, legally. π
and that's the page, bestie!! π¦β¨
little sign-off moment: this was documented under perl v5.36.0, dated 2023-06-11, and the manual name up top was Valida...Options(3pm) β folded in, as promised, not copy-pasted. mwah. π
πΈ
π¦ where this page comes from
- debian trixie: libvalidation-class-perl 7.900059-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libvalidation-class-perl 7.900059-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libvalidation-class-perl 7.900059-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libvalidation-class-perl 7.900059-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms