The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Validation::Class::Simple::Streamer - Simple Streaming Data Validation

VERSION

version 7.900030

SYNOPSIS

    use Validation::Class::Simple::Streamer;

    my $rules = Validation::Class::Simple::Streamer->new($parameters);

    # the point here is expressiveness

    unless ($rules->check('user_cc')->creditcard(['visa', 'mastercard'])) {
        # credit card is a valid visa/mastercard
    }

    unless ($rules->check('email_address')->min_length(3)->email) {
        # email address is valid
    }

    # prepare password for validation
    $rules->check('password');

    die "Password is not valid"
        unless $rules->min_symbols(1) && $rules->matches('password2');

    # are you of legal age?
    if ($rules->check('user_age')->between('18-75')) {
        # access to explicit content approved
    }

    # get all fields with errors
    my $fields = $rules->validator->error_fields;

    # print errors if any
    print $rules->messages unless $params->validate;

    # validate like a boss
    # THE END

DESCRIPTION

Validation::Class::Simple::Streamer is a simple streaming validation module that makes data validation fun. It is built around the powerful Validation::Class data validation framework via Validation::Class::Simple.

This module is/was inspired by the simplicity and expressiveness of the Node.js validator library, https://github.com/chriso/node-validator, but built on top of the ever-awesome Validation::Class framework, which is designed to be modular and extensible, i.e. whatever custom directives you create and install will become methods on this class which you can then use to enforce policies.

METHODS

check

The check method specifies the parameter to be used in the following series of commands.

    $self = $self->check('email_address');

clear

The clear method resets the validation queue and declared fields but leaves the declared parameters in-tact, almost like the object state post-instantiation.

    $self->clear;

messages

The messages method returns any registered errors as a concatenated string using the "errors_to_string" in Validation::Class::Prototype method and accepts the same parameters.

    print $self->messages("\n");

params

The params method gives you access to the validator's params list which is a Validation::Class::Mapping object.

    $params = $self->params($parameters);

validate

The validate method uses the validator to perform data validation based on the series and sequence of commands issued previously. This method is called implicitly whenever the object is used in boolean context, e.g. in a conditional.

    $true = $self->validate;

validator

The validator method gives you access to the object's validation class which is a Validation::Class::Simple object by default.

    $validator = $self->validator;

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.