Al Newkirk > Validation-Class-5.85 > Validation::Class::Moose

Download:
Validation-Class-5.85.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

New  3
Open  3
View/Report Bugs
Module Version: 5.85   Source   Latest Release: Validation-Class-6.05

NAME ^

Validation::Class::Moose - Marries Validation::Class and Moose through Traits

VERSION ^

version 5.85

DESCRIPTION ^

Validation::Class::Moose is a Moose role that infuses the power and flexibility of Validation::Class into your Moose classes. Validation::Class::Moose, by design, is not designed for attribute type checking, the Moose type constraint system exists for that purpose and works well, ... instead, its purpose is suited for validating attribute values (parameters).

This class is experimental and hasn't been used in production. While it has been tested, please note, the API may change.

SYNOPSIS

    package Identify;
    
    use  Moose;
    with 'Validation::Class::Moose';
    
    has login => (
        is     => 'rw',
        isa    => 'Str',
        traits => ['Rules'],
        rules  => {
            label      => 'User Login',
            error      => 'Login invalid.',
            required   => 1,
            validation => sub {
                my ( $self, $this_field, $all_params ) = @_;
                return $this_field->{value} eq 'admin' ? 1 : 0;
            }
        }
    );
    
    has password => (
        is     => 'rw',
        isa    => 'Str',
        traits => ['Rules'],
        rules  => {
            label      => 'User Password',
            error      => 'Password invalid.',
            required   => 1,
            validation => sub {
                my ( $self, $this_field, $all_params ) = @_;
                return $this_field->{value} eq 'pass' ? 1 : 0;
            }
        }
    );
    
    package main;
    
    my $id    = Identify->new(login => 'admin', password => 'xxxx');
    my $rules = $id->rules;
    
    unless ( $rules->validate ) {
        exit print $rules->errors_to_string;
    }

AUTHOR ^

Al Newkirk <awncorp@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2011 by awncorp.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: