Valida...ective(3pm)

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

✨ 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 πŸ‘‘


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