Valida...Options(3pm)

πŸ“¦
version 7.900059 Β· 7 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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. 🫢


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