Valida...Default(3pm)
π 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. π«Ά
β 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.
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
- 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