Dancer2-Plugin-FormValidator
view release on metacpan or search on metacpan
lib/Dancer2/Plugin/FormValidator.pm view on Meta::CPAN
=back
=head1 ROLES
=over 4
=item *
Dancer2::Plugin::FormValidator::Role::Profile - for profile classes.
=item *
Dancer2::Plugin::FormValidator::Role::HasMessages - for classes, that implements custom error messages.
=item *
Dancer2::Plugin::FormValidator::Role::ProfileHasMessages - brings together Profile and HasMassages.
=item *
Dancer2::Plugin::FormValidator::Role::Extension - for extension classes.
=item *
Dancer2::Plugin::FormValidator::Role::Validator - for custom validators.
=back
=head1 HINTS
If you don't want to create separated classes for your validation logic,
you could create one base class and reuse it in your project.
### Validator class
package Validator {
use Moo;
with 'Dancer2::Plugin::FormValidator::Role::Profile';
has profile_hash => (
is => 'ro',
required => 1,
);
sub profile {
return $_[0]->profile_hash;
}
}
### Application
use Dancer2
my $validator = Validator->new(profile_hash =>
{
email => [qw(required email)],
}
);
post '/subscribe' => sub {
if (not validate profile => $validator) {
to_json errors;
}
};
=head1 BUGS AND LIMITATIONS
If you find one, please let me know.
=head1 SOURCE CODE REPOSITORY
L<https://github.com/AlexP007/dancer2-plugin-formvalidator|https://github.com/AlexP007/dancer2-plugin-formvalidator>.
=head1 AUTHOR
Alexander Panteleev <alexpan at cpan dot org>.
=head1 LICENSE AND COPYRIGHT
This software is copyright (c) 2022 by Alexander Panteleev.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 1.760 second using v1.01-cache-2.11-cpan-39bf76dae61 )