NAME

MVC::Neaf::X::Form::Wildcard - A special case form with unforeknown fields

SYNOPSIS

    use MVC::Neaf::X::Form::Wildcard;

    # once during application setup phase
    my $form = MVC::Neaf::X::Form::Wildcard->new(
        [ [ qr/name\d+/ => qr/...*/ ], ... ] );

    # much later, multiple times
    my $checked = $form->validate( {
        name1 => 'foo',
        surname2 => 'bar',
        name5 => 'o'
    } );

    $checked->fields;   # ( 'name1', 'name5' )
                        # ONLY the matched fields
    $checked->is_valid; # false
                        # because of next line
    $checked->error;    # { name5 => 'BAD_FORMAT' }

    $checked->data;     # { name1 => 'foo' }
                        # Data that passed validation
    $checked->raw;      # { name1 => 'foo', name5 => 'o' }
                        # Semi-good data to send back to user for amendment,
                        #     if needed

    # Note that surname2 did NOT affect anything at all.

DESCRIPTION

This module provides simple yet powerful validation method for plain hashes in cases where the fields are not known beforehand.

The validation rules come as tuples. A tuple containes name validation regexp, value validation regexp, and possibly other fields (not implemented yet).

All hash keys are filtered through name rules. In case of match, all other rules are applied, resulting in either matching or non-matching field that ends up in data or error hashes, respectively.

A field that doesn't match anything is let through.

new ( \@rules )

Create a new validator from rules.

More options may follow in the future, but now there are none.

add_rule( \@tuple )

add_rule( \%params )

validate( \%user_input )

Returns a MVC::Neaf::X::Form::Data object with keys of \%user_input, filtered by the rules.

LICENSE AND COPYRIGHT

This module is part of the MVC::Neaf suite.

Copyright 2017 Konstantin S. Uvarin.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.