<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    FormValidator::Lite - lightweight form validation library

SYNOPSIS
        use FormValidator::Lite;

        FormValidator::Lite-&gt;load_constraints(qw/Japanese/);

        my $q = CGI-&gt;new();
        my $validator = FormValidator::Lite-&gt;new($q);
        my $res = $validator-&gt;check(
            name =&gt; [qw/NOT_NULL/],
            name_kana =&gt; [qw/NOT_NULL KATAKANA/],
            {mails =&gt; [qw/mail1 mail2/]} =&gt; ['DUPLICATION'],
        );
        if ( ..... return_true_when_if_error() ..... ) {
            $validator-&gt;set_error('login_id' =&gt; 'DUPLICATION');
        }
        if ($validator-&gt;has_error) {
            ...
        }

        # in your tmpl
        &lt;ul&gt;
        ? for my $msg ($validator-&gt;get_error_messages) {
            &lt;li&gt;&lt;?= $msg ?&gt;&lt;/li&gt;
        ? }
        &lt;/ul&gt;

DESCRIPTION
    FormValidator::Lite is simple, fast implementation for form validation.

    IT'S IN BETA QUALITY. API MAY CHANGE IN FUTURE.

HOW TO WRITE YOUR OWN CONSTRAINTS
        http parameter comes from $_
        validator args comes from @_

METHODS
    my $validator = FormValidator::Lite-&gt;new($q);
        Create a new instance.

        $q is query like object, such as Apache::Request, CGI.pm,
        Plack::Request. The object MUST have a "$q-&gt;parma" method.

    $validator-&gt;query()
    $validator-&gt;query($query)
        Getter/Setter for query like object.

    $validator-&gt;check(@rule_ary)
            my $res = $validator-&gt;check(
                name      =&gt; [qw/NOT_NULL/],
                name_kana =&gt; [qw/NOT_NULL KATAKANA/],
                {mails =&gt; [qw/mail1 mail2/]} =&gt; ['DUPLICATION'],
            );

        This method do validation. You can write a rule in @rule_ary. In
        above example code, *name* is a parameter name, *NOT_NULL*,
        *KATAKANA* and *DUPLICATION* are name of constraints.

    $validator-&gt;is_error($key)
        Return true value if parameter named $key got error.

    $validator-&gt;is_valid()
        Return true value if $validator don't detects error.

        This is same as "!$validator-&gt;has_error()".

    $validator-&gt;has_error()
        Return true value if $validator detects error.

        This is same as "!$validator-&gt;is_valid()".

    $validator-&gt;set_error($param, $rule_name)
        Set new error to parameter named "&lt;$param"&gt;. The rule name is
        "&lt;$rule_name"&gt;.

    $validator-&gt;errors()
        Return whole errors as HashRef.

            {
                'foo' =&gt; { 'NOT_NULL' =&gt; 1, 'INT' =&gt; 1 },
                'bar' =&gt; { 'EMAIL' =&gt; 1, },
            }

    $validator-&gt;load_constraints($name)
            $validator-&gt;load_constraints("DATE", "Email");

            # or load your own constraints
            $validator-&gt;load_constraints("+MyApp::FormValidator::Lite::Constraint");

        There is a import style.

            use FormValidator::Lite qw/Date Email/;

        load constraint components named
        "FormValidator::Lite::Constraint::${name}".

    $validator-&gt;load_function_message($lang)
            $validator-&gt;load_function_message('ja');

        Load function message file.

        Currently, FormValidator::Lite::Messages::ja and
        FormValidator::Lite::Messages::en are available.

    $validator-&gt;set_param_message($param =&gt; $message, ...)
            $validator-&gt;set_param_message(
                name =&gt; 'Your Name',
            );

        Make relational map for the parameter name to human readable name.

    $validator-&gt;set_message_data({ message =&gt; $msg, param =&gt; $param,
    function =&gt; $function })
            $v-&gt;set_message_data(YAML::Load(&lt;&lt;'...'));
            ---
            message:
              zip.jzip: Please input correct zip number.
            param:
              name: Your Name
            function:
              not_null: "[_1] is empty"
              hiragana: "[_1] is not Hiragana"
            ...

        Setup error message map.

    $validator-&gt;set_message("$param.$func" =&gt; $message)
            $v-&gt;set_message('zip.jzip' =&gt; 'Please input correct zip number.');

        Set error message for the $param and $func.

    my @errors = $validator-&gt;get_error_messages()
    my $errors = $validator-&gt;get_error_messages()
        Get whole error messages for "&lt;$q"&gt; in array/arrayref. This method
        returns array in list context, otherwise HashRef.

    my $msg = $validator-&gt;get_error_message($param =&gt; $func)
        Generate error message for parameter $param and function named
        $func.

    my @msgs = $validator-&gt;get_error_messages_from_param($param)
        Get error messages by $q for parameter $param.

WHY NOT FormValidator::Simple?
    Yes, I know. This module is very similar with FV::S.

    But, FormValidator::Simple is too heavy for me. FormValidator::Lite is
    fast!

       Perl: 5.010000
       FVS: 0.23
       FVL: 0.02
                               Rate FormValidator::Simple   FormValidator::Lite
       FormValidator::Simple  353/s                    --                  -75%
       FormValidator::Lite   1429/s                  304%                    --

AUTHOR
    Tokuhiro Matsuno &lt;tokuhirom AAJKLFJEF@ gmail.com&gt;

THANKS TO
    craftworks

    nekokak

    tomi-ru

SEE ALSO
    FormValidator::Simple, Data::FormValidator, HTML::FormFu

LICENSE
    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

</pre></body></html>