Valida...::Class(3pm)
π Valida...::Class(3pm) π
okay bestie, this is the manual page for Validation::Class β the header is giving Valida...::Class(3pm) because it got truncated, but we know her. This is from the User Contributed Perl Documentation. It's giving powerful data validation framework energy, and we're gonna get into it. No cap. π
β¨ NAME β¨
Validation::Class β Powerful Data Validation Framework. Periodt. π
πΈ VERSION πΈ
version 7.900059 β¨
π¦ SYNOPSIS π¦
okay so here's the vibe check. You use Validation::Class::Simple::Streamer like this:
use Validation::Class::Simple::Streamer;
my $params = {username => 'admin', password => 's3cret'};
my $input = Validation::Class::Simple::Streamer->new(params => $params);
# check username parameter
$input->check('username')->required->between('5-255');
$input->filters([qw/trim strip/]);
# check password parameter
$input->check('password')->required->between('5-255')->min_symbols(1);
$input->filters([qw/trim strip/]);
# run validate
$input->validate or die $input->errors_to_string;
π DESCRIPTION π
okay so Validation::Class is a scalable data validation library with interfaces for applications of all sizes. The most common usage of Validation::Class is to transform class namespaces into data validation domains where consistency and reuse are primary concerns. Validation::Class provides an extensible framework for defining reusable data validation rules. It ships with a complete set of pre-defined validations and filters referred to as "directives". π
The core feature-set consist of self-validating methods, validation profiles, reusable validation rules and templates, pre and post input filtering, class inheritance, automatic array handling, and extensibility (e.g. overriding default error messages, creating custom validators, creating custom input filters and much more). Validation::Class promotes DRY (don't repeat yourself) code. The main benefit in using Validation::Class is that the architecture is designed to increase the consistency of data input handling. The following is a more traditional usage of Validation::Class, using the DSL to construct a validator class:
package MyApp::Person;
use Validation::Class;
# data validation template
mixin basic => {
required => 1,
max_length => 255,
filters => [qw/trim strip/]
};
# data validation rules for the username parameter
field username => {
mixin => 'basic',
min_length => 5
};
# data validation rules for the password parameter
field password => {
mixin => 'basic',
min_length => 5,
min_symbols => 1
};
package main;
my $person = MyApp::Person->new(username => 'admin', password => 'secr3t');
# validate rules on the person object
unless ($person->validates) {
# handle the failures
warn $person->errors_to_string;
}
1;
π§ QUICKSTART π§
If you are looking for a simple in-line data validation module built using the same tenets and principles as Validation::Class, please review Validation::Class::Simple or Validation::Class::Simple::Streamer. If you are new to Validation::Class, or would like more information on the underpinnings of this library and how it views and approaches data validation, please review Validation::Class::Whitepaper. Please review the "GUIDED-TOUR" in Validation::Class::Cookbook for a detailed step-by-step look into how Validation::Class works. π¦
π KEYWORDS π
π adopt
okay so the adopt keyword (or adt) copies configuration and functionality from other Validation::Class classes. The adopt keyword takes three arguments: the name of the class to be introspected, and the configuration type and name to be recreated. Basically, anything you can configure using a Validation::Class keyword can be adopted into other classes using this keyword, with the exception of coderefs registered using the build keyword. Please note! If you are adopting a field declaration which has an associated mixin directive defined on the target class, you must adopt the mixin explicitly if you wish its values to be interpolated.
package MyApp::Exployee;
use Validate::Class;
use MyApp::Person;
adopt MyApp::Person, mixin => 'basic';
adopt MyApp::Person, field => 'first_name';
adopt MyApp::Person, field => 'last_name';
adopt MyApp::Person, profile => 'has_fullname';
1;
π attribute
The attribute keyword (or has) registers a class attribute, i.e. it creates an accessor (getter and setter) on the class. Attribute declaration is flexible and only requires an attribute name to be configured. Additionally, the attribute keyword can take two arguments: the attribute's name and a scalar or coderef to be used as its default value.
package MyApp::Person;
use Validate::Class;
attribute 'first_name' => 'Peter';
attribute 'last_name' => 'Venkman';
attribute 'full_name' => sub {
join ', ', $_[0]->last_name, $_[0]->first_name
};
attribute 'email_address';
1;
π₯ build
The build keyword (or bld) registers a coderef to be run at instantiation much in the same way the common BUILD routine is used in modern OO frameworks.
package MyApp::Person;
use Validation::Class;
build sub {
my ($self, $args) = @_;
# run after instantiation in the order defined
};
1;
The build keyword takes one argument, a coderef which is passed the instantiated class object.
π directive
The directive keyword (or dir) registers custom validator directives to be used in your field definitions. Please note that custom directives can only be used with field definitions. This is a means of extending the list of directives per instance. See the list of core directives, Validation::Class::Directives, or review Validation::Class::Directive for insight into creating your own CPAN installable directives.
package MyApp::Person;
use Validate::Class;
# define a custom class-level directive
directive 'blacklisted' => sub {
my ($self, $field, $param) = @_;
if (defined $field->{blacklisted} && defined $param) {
if ($field->{required} || $param) {
if (exists_in_blacklist($field->{blacklisted}, $param)) {
my $handle = $field->label || $field->name;
$field->errors->add("$handle has been blacklisted");
return 0;
}
}
}
return 1;
};
field 'email_address' => {
blacklisted => '/path/to/blacklist'
email => 1,
};
1;
The directive keyword takes two arguments, the name of the directive and a coderef which will be used to validate the associated field. The coderef is passed four ordered parameters; a directive object, the class prototype object, the current field object, and the matching parameter's value. The validator (coderef) is evaluated by its return value as well as whether it altered any error containers.
π¦ document
The document keyword (or doc) registers a data matching profile which can be used to validate heiarchal data. It will store a hashref with pre-define path matching rules for the data structures you wish to validate. The "path matching rules", which use a specialized object notation, referred to as the document notation, can be thought of as a kind-of simplified regular expression which is executed against the flattened data structure. The following are a few general use-cases:
package MyApp::Person;
use Validation::Class;
field 'string' => {
mixin => [':str']
};
# given this JSON data structure
{
"id": "1234-A",
"name": {
"first_name" : "Bob",
"last_name" : "Smith",
},
"title": "CIO",
"friends" : [],
}
# select id to validate against the string rule
document 'foobar' =>
{ 'id' => 'string' };
# select name -> first_name/last_name to validate against the string rule
document 'foobar' =>
{'name.first_name' => 'string', 'name.last_name' => 'string'};
# or
document 'foobar' =>
{'name.*_name' => 'string'};
# select each element in friends to validate against the string rule
document 'foobar' =>
{ 'friends.@' => 'string' };
# or select an element of a hashref in each element in friends to validate
# against the string rule
document 'foobar' =>
{ 'friends.@.name' => 'string' };
The document declaration's keys should follow the aforementioned document notation schema and its values should be strings which correspond to the names of fields (or other document declarations) that will be used to preform the data validation. It is possible to combine document declarations to validate hierarchical data that contains data structures matching one or more document patterns. The following is an example of what that might look like.
package MyApp::Person;
use Validation::Class;
# data validation rule
field 'name' => {
mixin => [':str'],
pattern => qr/^[A-Za-z ]+$/,
max_length => 20,
};
# data validation map / document notation schema
document 'friend' => {
'name' => 'name'
};
# data validation map / document notation schema
document 'person' => {
'name' => 'name',
'friends.@' => 'friend'
};
package main;
my $data = {
"name" => "Anita Campbell-Green",
"friends" => [
{ "name" => "Horace" },
{ "name" => "Skinner" },
{ "name" => "Alonzo" },
{ "name" => "Frederick" },
],
};
my $person = MyApp::Person->new;
unless ($person->validate_document(person => $data)) {
warn $person->errors_to_string if $person->error_count;
}
1;
Alternatively, the following is a more verbose data validation class using traditional styling and configuration.
package MyApp::Person;
use Validation::Class;
field 'id' => {
mixin => [':str'],
filters => ['numeric'],
max_length => 2,
};
field 'name' => {
mixin => [':str'],
pattern => qr/^[A-Za-z ]+$/,
max_length => 20,
};
field 'rating' => {
mixin => [':str'],
pattern => qr/^\-?\d+$/,
};
field 'tag' => {
mixin => [':str'],
pattern => qr/^(?!evil)\w+/,
max_length => 20,
};
document 'person' => {
'id' => 'id',
'name' => 'name',
'company.name' => 'name',
'company.supervisor.name' => 'name',
'company.supervisor.rating.@.*' => 'rating',
'company.tags.@' => 'name'
};
package main;
my $data = {
"id" => "1234-ABC",
"name" => "Anita Campbell-Green",
"title" => "Designer",
"company" => {
"name" => "House of de Vil",
"supervisor" => {
"name" => "Cruella de Vil",
"rating" => [
{ "support" => -9,
"guidance" => -9
}
]
},
"tags" => [
"evil",
"cruelty",
"dogs"
]
},
};
my $person = MyApp::Person->new;
unless ($person->validate_document(person => $data)) {
warn $person->errors_to_string if $person->error_count;
}
1;
And bestie, there's yet another way to do this whole thing β instead of naming the spec, you just pass the document specification straight in. Same energy, different delivery. β¨
package MyApp::Person;
use Validation::Class;
package main;
my $data = {
"id" => "1234-ABC",
"name" => "Anita Campbell-Green",
"title" => "Designer",
"company" => {
"name" => "House of de Vil",
"supervisor" => {
"name" => "Cruella de Vil",
"rating" => [
{ "support" => -9,
"guidance" => -9
}
]
},
"tags" => [
"evil",
"cruelty",
"dogs"
]
},
};
my $spec = {
'id' => { max_length => 2 },
'name' => { mixin => ':str' },
'company.name' => { mixin => ':str' },
'company.supervisor.name' => { mixin => ':str' },
'company.supervisor.rating.@.*' => { pattern => qr/^(?!evil)\w+/ },
'company.tags.@' => { max_length => 20 },
};
my $person = MyApp::Person->new;
unless ($person->validate_document($spec => $data)) {
warn $person->errors_to_string if $person->error_count;
}
1;
β¨ ensure β¨
Okay so ensure (or its lil nickname ens) is the glow-up keyword β it takes a method you already wrote and turns it into an auto-validating method. The method gets registered and behaves exactly like you'd made it with the method keyword. Your original method gets overridden with a modified version that runs the pre- and/or post-validation routines. πͺ
package MyApp::Person;
use Validation::Class;
sub register {
...
}
ensure register => {
input => ['name', '+email', 'username', '+password', '+password2'],
output => ['+id'], # optional output validation, dies on failure
};
package main;
my $person = MyApp::Person->new(params => $params);
if ($person->register) {
# handle the successful registration
}
1;
ensure takes two arguments: the name of the method you're overriding, and a hashref of required key/value pairs. That hashref can have an input key (like input, input_document, input_profile, or input_method). The input key specifically has to hold either an arrayref of fields to validate, or a scalar value matching a validation profile or an auto-validating method name. The hashref can also have an output key (like output, output_document, output_profile, or output_method). The output key specifically has to hold either an arrayref of fields to validate, or a scalar value matching a validation profile or an auto-validating method name. Whether your method returns anything, and what β that's entirely your call. If validation fails, the method returns undefined. Honestly ensure wraps things up pretty much the same way method does. π
β¨ field β¨
The field keyword (or fld) registers a data validation rule for reuse and validation in your code. The field name should line up with the parameter name you expect to get passed to your validation class, or the thing you're validating against. π
package MyApp::Person;
use Validation::Class;
field 'username' => {
required => 1,
min_length => 1,
max_length => 255
};
field takes two arguments: the field name, and a hashref of key/value pairs known as directives. Wanna know about the pre-defined ones? Go peek at the "list of core directives". π
Oh and β plot twist β field also creates accessors that give you easy access to that field's corresponding parameter value(s). The accessor gets built from the field's name used as a label, with any special characters swapped out for an underscore. π¦
# accessor will be created as send_reminders
field 'send-reminders' => {
length => 1
};
Now listen closely because this part is important, no cap. If you prefix a field name with a double plus-symbol, you're telling the register to merge your declaration with any pre-existing declarations in the same scope (think: fields you imported by loading roles). But if you prefix it with a single plus-symbol, you're telling the register to overwrite any pre-existing declarations. Two totally different vibes, one character apart. π
package MyApp::Person;
use Validation::Class;
set role => 'MyApp::User';
# append existing field and overwrite directives
field '++email_address' => {
required => 1
};
# redefine existing field
field '+login' => {
required => 1
};
1;
β¨ filter β¨
The filter keyword (or flt) registers custom filters you can use in your field definitions. It's how you extend the pre-existing filters declared by the "filters directive" before instantiation. Basically you're adding your own little beauty blender to the kit. π§
package MyApp::Person;
use Validate::Class;
filter 'flatten' => sub {
$_[0] =~ s/[\t\r\n]+/ /g;
return $_[0];
};
field 'biography' => {
filters => ['trim', 'strip', 'flatten']
};
1;
filter takes two arguments: the name of the filter, and a coderef that'll be used to filter the value of the associated field. The coderef gets passed the value of the field, and that value MUST be operated on directly. The coderef should also return the transformed value. Don't forget the return, bestie, or you get nothing back. π
β¨ load β¨
The load keyword (or set) β which you can also use as a class method β hands you options for extending the current class by declaring roles, requirements, etc. π
The whole process of applying roles, requirements, and other settings to the current class is mainly about introspecting the namespace's methods and merging the relevant parts of the prototype configuration. It's giving very "go through your closet and merge the good stuff into the main wardrobe." π
β¨ load-classes β¨
The classes (or class) option uses Module::Find to load all child classes (in-all-subdirectories) so you can conveniently reach them through the "class" in Validation::Class::Prototype method, and so introspection works when you're dealing with a bigger application. This option accepts an arrayref or a single argument. π
package MyApp;
use Validation::Class;
load classes => ['MyApp::Domain1', 'MyApp::Domain2'];
package main;
my $app = MyApp->new;
my $person = $app->class('person'); # return a new MyApp::Person object
1;
β¨ load-requirements β¨
package MyApp::User;
use Validate::Class;
load requirements => 'activate';
package MyApp::Person;
use Validation::Class;
load role => 'MyApp::User';
sub activate {}
1;
The requirements (or required) option makes sure that if/when the class gets used as a role, the calling class already has certain specific pre-existing methods. So like... you can't be a role unless you can actually do the thing, bestie. This option accepts an arrayref or a single argument. β¨
package MyApp::User;
use Validate::Class;
load requirements => ['activate', 'deactivate'];
1;
β¨ load-roles β¨
package MyApp::Person;
use Validation::Class;
load role => 'MyApp::User';
1;
The roles (or role) option is how you load and inherit functionality from other validation classes. These classes should be used and thought of as roles, even though they can totally also be fully-functioning validation classes in their own right. Main character and supporting cast at the same time. π This option accepts an arrayref or a single argument.
package MyApp::Person;
use Validation::Class;
load roles => ['MyApp::User', 'MyApp::Visitor'];
1;
β¨ message β¨
The message keyword (or msg) registers a class-level error message template that'll be used in place of the error message defined in the corresponding directive class β if one is defined. And guess what, you can override error messages at the individual field-level too. Check out Validation::Class::Directive::Messages for the full instructions on how to do the field-level overrides. π
package MyApp::Person;
use Validation::Class;
field email_address => {
required => 1,
min_length => 3,
messages => {
# field-level error message override
min_length => '%s is not even close to being a valid email address'
}
};
# class-level error message overrides
message required => '%s is needed to proceed';
message min_length => '%s needs more characters';
1;
message takes two arguments: the name of the directive whose error message you want to override, and a string that gets used as a template which is fed to sprintf to format the message. So %s is doing a lot of heavy lifting here, okay? π
β¨ method β¨
The method keyword (or mth) registers an auto-validating method. Think of it like method signatures β an auto-validating method can lean on your pre-existing validation rules and profiles to make sure the method has the required pre/post-conditions and all the data it needs before it runs. Obsessed with the efficiency, honestly. π₯
package MyApp::Person;
use Validation::Class;
method 'register' => {
input => ['name', '+email', 'username', '+password', '+password2'],
output => ['+id'], # optional output validation, dies on failure
using => sub {
my ($self, @args) = @_;
# do something registrationy
$self->id(...); # set the ID field for output validation
return $self;
}
...and here's the rest of that example, so you can see the whole vibe:
};
package main;
my $person = MyApp::Person->new(params => $params);
if ($person->register) {
# handle the successful registration
}
1;
Okay so the method keyword takes two arguments: the name of the method you wanna create, and a hashref of required key/value pairs. π
That hashref can have a using key, and its value is the coderef that gets executed upon successful validation. The using key is only optional when a pre-existing subroutine has the same name, or the method being declared is prefixed with a dash or dash-process-dash. No cap. π«Ά
These are the valid subroutine names that the method declaration will call in the absence of a using key. And please note, unlike the ensure keyword, any pre-existing subroutines will not be wrapped-and-replaced β they can totally be executed without validation if you call them directly. π
sub _name {
...
}
sub _process_name {
...
}
The hashref may also have an input key (like input, input_document, input_profile, or input_method). The input key specifically must have a value that's either an arrayref of fields to be validated, or a scalar value that matches (a validation profile or auto-validating method name) β and that's what gets used to do data validation before the aforementioned coderef has been executed. Whether the method returns anything, and what, is yours to decide. The method returns undefined if validation fails. π
# alternate usage
method 'registration' => {
input => ['name', '+email', 'username', '+password', '+password2'],
output => ['+id'], # optional output validation, dies on failure
};
sub _process_registration {
my ($self, @args) = @_;
$self->id(...); # set the ID field for output validation
return $self;
}
Optionally the hashref may <em>also</em> have an output key (like output, output_document, output_profile, or output_method). The output key specifically must have a value that's either an arrayref of fields to be validated, or a scalar value that matches (a validation profile or auto-validating method name) β and that gets used to do data validation after the aforementioned coderef has been executed. β¨
Please note: output validation failure will cause the program to die. The premise behind this decision is based on the assumption that, given successfully validated input, a routine's output should be predictable β and if an error occurs it is most-likely a program error as opposed to a user error. So like, that's on purpose. π
See the ignore_failure and report_failure attributes on the prototype to control how method validation failures are handled. π
β¨ mixin β¨
The mixin keyword (or mxn) registers a validation rule template that can be applied (or "mixed-in") to any field by specifying the mixin directive. Mixin directives are processed first, so existing field directives will override any directives created by the mixin directive. Periodt. π
package MyApp::Person;
use Validation::Class;
mixin 'boilerplate' => {
required => 1,
min_length => 1,
max_length => 255
};
field 'username' => {
# min_length, max_length, .. required will be overridden
mixin => 'boilerplate',
required => 0
};
Since version 7.900015, all classes are automatically configured with the following default mixins, just for the sake of convenience π:
mixin ':flg' => {
required => 1,
min_length => 1,
filters => [qw/trim strip numeric/],
between => [0, 1]
};
mixin ':num' => {
required => 1,
min_length => 1,
filters => [qw/trim strip numeric/]
};
mixin ':str' => {
required => 1,
min_length => 1,
filters => [qw/trim strip/]
};
Please note that the aforementioned mixin names are prefixed with a semi-colon but are treated as an exception to the rule. Prefixing mixin names with a double plus-symbol instructs the register to merge your declaration with any pre-existing declarations within the same scope (e.g. mixins imported via loading roles), whereas prefixing mixin names with a single plus-symbol instructs the register to overwrite any pre-existing declarations. iykyk π¦
package MyApp::Moderator;
use Validation::Class;
set role => 'MyApp::Person';
# overwrite and append existing mixin
mixin '++boilerplate' => {
min_symbols => 1
};
# redefine existing mixin
mixin '+username' => {
required => 1
};
1;
The mixin keyword takes two arguments: the mixin name and a hashref of key/values pairs known as directives. πΈ
β¨ profile β¨
The profile keyword (or pro) registers a validation profile (a coderef) which β as in the traditional use of the term β is a sequence of validation routines that validates data relevant to a specific action. π§
package MyApp::Person;
use Validation::Class;
profile 'check_email' => sub {
my ($self, @args) = @_;
if ($self->email_exists) {
my $email = $self->fields->get('email');
$email->errors->add('Email already exists');
return 0;
}
return 1;
};
package main;
my $user = MyApp::Person->new(params => $params);
unless ($user->validate_profile('check_email')) {
# handle failures
}
1;
The profile keyword takes two arguments: a profile name and a coderef which will be used to execute a sequence of actions for validation purposes. So iconic of it honestly. β¨
π METHODS π
π¦ new π¦
The new method instantiates a new class object. It performs a series of actions (magic) required for the class to function properly β and for that reason, this method should never be overridden. Use the build keyword for hooking into the instantiation process instead, bestie. π«Ά
In the event a foreign (pre-existing) new method is detected, an initialize_validator method will be injected into the class containing the code (magic) necessary to normalize your environment. β¨
package MyApp::Person;
use Validation::Class;
# hook
build sub {
my ($self, @args) = @_; # on instantiation
};
sub new {
# rolled my own
my $self = bless {}, shift;
# execute magic
$self->initialize_validator;
}
1;
π¦ prototype π¦
The prototype method (or proto) returns an instance of the associated class prototype. The class prototype is responsible for manipulating and validating the data model (the class). It is not likely that you'll need to access this method directly β see Validation::Class::Prototype. π
package MyApp::Person;
use Validation::Class;
package main;
my $person = MyApp::Person->new;
my $prototype = $person->prototype;
1;
β¨ PROXY METHODS β¨
okay so real talk β Validation::Class is mostly out here handing you sugar functions for modeling your data validation requirements. π Every class you create gets associated with a prototype class, and that prototype is the one holding the actual data validation engine, which keeps your class namespace clean and free from pollution. For the specifics on particular methods and attributes, please see Validation::Class::Prototype β that's where the full tea lives. π
And here's the cute part: Validation::Class injects a few proxy methods into your class, and those are basically aliases to the matching prototype class methods. That said, you can always skip the middleman and access the prototype directly using the proto/prototype methods. π
Here's the whole roster, bestie:
classβ$self->class;β see "class" inValidation::Class::Prototypefor full documentation.clear_queueβ$self->clear_queue;β see "clear_queue" inValidation::Class::Prototypefor full documentation.error_countβ$self->error_count;β see "error_count" inValidation::Class::Prototypefor full documentation.error_fieldsβ$self->error_fields;β see "error_fields" inValidation::Class::Prototypefor full documentation.errorsβ$self->errors;β see "errors" inValidation::Class::Prototypefor full documentation.errors_to_stringβ$self->errors_to_string;β see "errors_to_string" inValidation::Class::Prototypefor full documentation.get_errorsβ$self->get_errors;β see "get_errors" inValidation::Class::Prototypefor full documentation.get_fieldsβ$self->get_fields;β see "get_fields" inValidation::Class::Prototypefor full documentation.get_hashβ$self->get_hash;β see "get_hash" inValidation::Class::Prototypefor full documentation.get_paramsβ$self->get_params;β see "get_params" inValidation::Class::Prototypefor full documentation.get_valuesβ$self->get_values;β see "get_values" inValidation::Class::Prototypefor full documentation.fieldsβ$self->fields;β see "fields" inValidation::Class::Prototypefor full documentation.filteringβ$self->filtering;β see "filtering" inValidation::Class::Prototypefor full documentation.ignore_failureβ$self->ignore_failure;β see "ignore_failure" inValidation::Class::Prototypefor full documentation.ignore_interventionβ$self->ignore_intervention;β see "ignore_intervention" inValidation::Class::Prototypefor full documentation.ignore_unknownβ$self->ignore_unknown;β see "ignore_unknown" inValidation::Class::Prototypefor full documentation.is_validβ$self->is_valid;β see "is_valid" inValidation::Class::Prototypefor full documentation.paramβ$self->param;β see "param" inValidation::Class::Prototypefor full documentation.paramsβ$self->params;β see "params" inValidation::Class::Prototypefor full documentation.pluginβ$self->plugin;β see "plugin" inValidation::Class::Prototypefor full documentation.queueβ$self->queue;β see "queue" inValidation::Class::Prototypefor full documentation.report_failureβ$self->report_failure;β see "report_failure" inValidation::Class::Prototypefor full documentation.report_unknownβ$self->report_unknown;β see "report_unknown" inValidation::Class::Prototypefor full documentation.reset_errorsβ$self->reset_errors;β see "reset_errors" inValidation::Class::Prototypefor full documentation.reset_fieldsβ$self->reset_fields;β see "reset_fields" inValidation::Class::Prototypefor full documentation.reset_paramsβ$self->reset_params;β see "reset_params" inValidation::Class::Prototypefor full documentation.set_errorsβ$self->set_errors;β see "set_errors" inValidation::Class::Prototypefor full documentation.set_fieldsβ$self->set_fields;β see "set_fields" inValidation::Class::Prototypefor full documentation.set_paramsβ$self->set_params;β see "set_params" inValidation::Class::Prototypefor full documentation.set_methodβ$self->set_method;β see "set_method" inValidation::Class::Prototypefor full documentation.stashβ$self->stash;β see "stash" inValidation::Class::Prototypefor full documentation.validateβ$self->validate;β see "validate" inValidation::Class::Prototypefor full documentation.validate_documentβ$self->validate_document;β see "validate_document" inValidation::Class::Prototypefor full documentation.validate_methodβ$self->validate_method;β see "validate_method" inValidation::Class::Prototypefor full documentation.validate_profileβ$self->validate_profile;β see "validate_profile" inValidation::Class::Prototypefor full documentation.
π UPGRADE π
so, status check: Validation::Class is stable, its feature-set is complete, and it's currently chilling in maintenance-only mode β meaning it only gets updated with minor enhancements and bug fixes. no big glow-ups here, bestie. π
but wait, the plot thickens: all the lessons learned are being folded into a complete rewrite that's uploaded under the namespace Validation::Interface. that fork is designed to have a much simpler API with fewer options and better execution, and it's focused on validating hierarchical data as its primary objective. main character energy, honestly. π
π§ EXTENSIBILITY π§
important thing: Validation::Class does NOT provide method modifiers. π but β and this is the good part β it can be easily extended with Class::Method::Modifiers. slay. β¨
before
before foo => sub { ... };
See "before method(s) => sub { ... }" in Class::Method::Modifiers for full documentation.
around
around foo => sub { ... };
See "around method(s) => sub { ... }" in Class::Method::Modifiers for full documentation.
after
after foo => sub { ... };
See "after method(s) => sub { ... }" in Class::Method::Modifiers for full documentation.
π SEE ALSO π
quick heads up: Validation::Class does not validate blessed objects. nope, not its thing. if you need a way to validate object types, you should use a modern object system like Moo, Mouse, or Moose. π¦
or, alternatively, you could use decoupled object validators like Type::Tiny, Params::Validate or Specio. multiple options, all iconic. π
π AUTHOR π
Al Newkirk <anewkirk@ana.io>
π 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 a wrap on the whole page, bestie!! π«Ά this lil doc is from perl v5.36.0, dated 2023-06-11, and it lives under the name Valida...::Class(3pm) in the User Contributed Perl Documentation. go forth and validate, you absolute legend. βπΈπ
π¦ 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