HTML::...lidator(3pm)

πŸ“¦
version 2.07000 Β· 5 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– NAME πŸ’–

okay bestie, gather round β€” this is HTML::FormFu::Validator, the Validator Base Class. it's giving "the blueprint all the other validators are built on" energy. iconic behavior honestly. ✨


🌸 VERSION 🌸

this is version 2.07, no cap. that's the one you're looking at right now. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

bestie... there is literally nothing here. the synopsis is empty. like, the vibe is immaculate but the content said "not today". 😭 moving on, we respect the silence.


πŸŽ€ DESCRIPTION πŸŽ€

also empty!! nothing!! the description section is a blank canvas, a vibe check that came back with no notes. 🫢 keep scrolling, the good stuff is down there.


✨ METHODS ✨

yeah so... also no methods listed here. empty. a whole mood. πŸ’œ


πŸ‘‘ CORE VALIDATORS πŸ‘‘

this is the part where it actually tells you something, and what it tells you is:

  • HTML::FormFu::Validator::Callback β€” that's it, that's the whole list. one core validator. the main character. πŸ”₯

🌈 BEST PRACTICES 🌈

ok so, real talk β€” try to avoid using callbacks if you can. πŸ’€

there's a better way, and it's more maintainable, more reusable, and it keeps all your code out of the controller. which is a whole glow-up. periodt.

a normal application's directory would have all this:

lib/HTML/FormFu/Constraint/MyApp/
lib/HTML/FormFu/Validator/MyApp/
lib/HTML/FormFu/Plugin/MyApp/
etc.

so then your form config file only needs this little cutie:

validator: 'MyApp::SomeValidator'

and the class itself would be something like:

package HTML::FormFu::Validator::MyApp::SomeValidator;

use Moose;
extends 'HTML::FormFu::Validator';

sub validate_value {
    my ( $self, $value, $params ) = @_;

    my $c = $self->form->stash->{context};

    return 1 if $c->model('DBIC')->is_valid($value);

    # assuming you want to return a custom error message
    # which perhaps includes something retrieved from the model
    # otherwise, just return 0
    die HTML::FormFu::Exception::Validator->new({
        message => 'custom error message',
    });
}

1;

see? clean. organized. she understood the assignment. 🧚


πŸ’œ AUTHOR πŸ’œ

Carl Franks, "cfranks@cpan.org" β€” the legend themselves. 🫢


⭐ LICENSE ⭐

this library is free software, bestie β€” you can redistribute it and/or modify it under the same terms as Perl itself. slay. πŸ’…


🌸 AUTHOR 🌸

again, but make it email-flavored: Carl Franks <cpan@fireartist.com>. two whole ways to reach the icon. πŸ’–


this software is copyright (c) 2018 by Carl Franks.

and yep β€” this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so generous, so iconic, so real of them. ✨


and that's the whole page, bestie!! this was pulled from perl v5.28.1, dated 2019-01-12 β€” shoutout to the archive, and to the HTML::...lidator(3pm) manual page for being exactly what it is. πŸ¦‹ mwah. πŸ’‹
πŸ“¦ where this page comes from