Valida...ective(3pm)
β¨ NAME β¨
Validation::Class::Directive β the base class for Validation Class directives, bestie π (it's a 3pm perl manual page, iykyk)
πΈ VERSION πΈ
version 7.900059 β yes that's the real number, no cap π
π SYNOPSIS π
Okay so picture this: you wanna build your own validation rule. Here's the whole vibe, a custom directive called CheckBlacklist:
package Validation::Class::Directive::CheckBlacklist;
use base 'Validation::Class::Directive';
use strict;
use warnings;
use Validation::Class::Util;
use File::Slurp;
has 'mixin' => 0;
has 'field' => 1;
has 'multi' => 0;
has 'message' => '%s has been blacklisted';
sub validate {
my $self = shift;
my ($proto, $field, $param) = @_;
if (defined $field->{check_blacklist} && $param) {
# is the parameter value blacklisted?
my @blacklist = read_file('/blacklist.txt');
$self->error if grep { $param =~ /^$_$/ } @blacklist;
}
}
1;
...and then, in your validation class, you just use it like the icon it is:
package MyApp::Person;
use Validation::Class;
field ip_address => {
required => 1,
check_blacklist => 1
};
1;
...and finally, in your application:
package main;
use MyApp::Person;
my $person = MyApp::Person->new(ip_address => '0.0.0.0');
unless ($person->validates('ip_address')) {
# handle validation error
}
Slay. That's the whole flow, start to finish. π¦
π DESCRIPTION π
So the tea is: you can extend Validation::Class by making your own validation rules, and those little rules are called directives. β¨
Validation::Class::Directive is the base-class you inherit from when you're cooking up new directive classes. It's giving "starter pack but make it architecture" π«Ά
And if you wanna see the full roster of core directives already in the box, go peek at Validation::Class::Directives β that's where the complete list lives, bestie. π
π AUTHOR π
Al Newkirk <anewkirk@ana.io> β absolute legend, main character energy, 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, gorgeous. This one's riding with perl v5.36.0 and it was last touched on 2023-06-11, so shoutout to that exact combo β go forth and write your directives, periodt. πβ¨π
π¦ 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