Valida...Default(3pm)

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

πŸ’– Validation::Class::Directive::Default πŸ’–

okay bestie, so this is the 3pm manual page for Validation::Class::Directive::Default β€” like, the actual user-contributed Perl docs, and no cap it's a whole vibe. it's the Default Directive for Validation Class Field Definitions, and she's here to tell you what to do when nobody shows up with a value. πŸŽ€


✨ VERSION ✨

version 7.900059 β€” yes queen, we're on 7.900059 and that's iconic. πŸ’…


🌸 SYNOPSIS 🌸

okay so here's the whole thing in action, look at her go:

use Validation::Class::Simple;

my $rules = Validation::Class::Simple->new(
    fields => {
        access_code  => {
            default => 'demo123'
        }
    }
);

# set parameters to be validated
$rules->params->add($parameters);

# validate
unless ($rules->validate) {
    # handle the failures
}

see how access_code just has a default of 'demo123' sitting there? that's the whole point. if nobody brings a value, she brings her own. πŸ¦‹


πŸ’… DESCRIPTION πŸ’…

Validation::Class::Directive::Default is a core validation class field directive that holds the value which should be used if no parameter is supplied.

fr fr, that's it. no parameter? no problem. the default steps in like main character energy. πŸ‘‘

πŸŽ€ the alternative argument πŸŽ€

  • alternative argument: a-coderef-returning-a-default-value

so this directive can be passed a single value, OR a coderef which should return the value to be used as the default value. literally either one, bestie, the choice is yours:

fields => {
    access_code => {
        default => sub {
            my $self = shift; # this coderef will receive a context object
            return join '::', lc __PACKAGE__, time();
        }
    }
}
πŸ’€ heads up β€” that coderef will receive a context object, so don't forget the my $self = shift;. it's giving "i forgot to grab my argument" energy otherwise. 😭

🌈 AUTHOR 🌈

Al Newkirk <anewkirk@ana.io> β€” king behavior, we stan. 🫢


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.


and that's the whole page, bestie β€” no cap, every flag, every coderef, every copyright line, all of it. πŸ’– this was perl v5.36.0 dated 2023-06-11, and if you need her again she'll be right there in Valida...Default(3pm). slay, periodt, go set some defaults. βœ¨πŸŒΈπŸ‘‘

πŸ“¦ where this page comes from