Validation::Class::Moose - Marries Validation::Class and Moose through Traits
version 5.51
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.
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; }
Al Newkirk <awncorp@cpan.org>
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.
To install Validation::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Validation::Class
CPAN shell
perl -MCPAN -e shell install Validation::Class
For more information on module installation, please visit the detailed CPAN module installation guide.