NAME
Data::Validator - Rule based validator on type constraint subsystem
VERSION
This document describes Data::Validator version 0.01.
SYNOPSIS
use 5.10.0;
use Data::Validator;
# for functions
sub get {
state $rule = Data::Validator->new(
uri => { isa => 'Str', xor => [qw(schema host path_query)] },
schema => { isa => 'Str', default => 'http' },
host => { isa => 'Str' },
path_query => { isa => 'Str', default => '/' },
method => { isa => 'Str', default => 'GET' },
);
my $args = $rule->validate(@_);
# ...
}
get( uri => 'http://example.com/' );
# for methods
sub method {
state $rule = Data::Validator->new(
foo => 'Str',
)->with('Method');
my($self, $args) = $rule->validate(@_);
# ...
}
Foo->method( foo => 'bar' );
# using sequenced parameters
sub seq {
state $rule = Data::Validator->new(
foo => 'Str',
)->with('Sequenced');
my $args = $rule->validate(@_);
# ...
}
seq( 'bar' ); # seq() will get { foo => 'bar' }
seq({ foo => 'bar' }); # named style are available!
# both Method and Sequenced
sub seq_method {
state $rule = Data::Validator->new(
foo => 'Str',
)->with( 'Method', 'Sequenced');
my($self, $args) = $rule->validate(@_);
# ...
}
Foo->seq_method( 'bar' ); # seq() will get { foo => 'bar' }
DESCRIPTION
This is yet another validation library, based on Smart::Args
but less smart.
Any API will change without notice.
INTERFACE
Data::Validator->new(@rules) :Validator
$validator->with(@roles) :Validator
$validator->validate(@args) :HashRef
EXTENTIONS
There are extentions which changes behaviours of validate()
.
Extentions are defined as Mouse::Role
.
Method
Takes the first argument as a invocants (i.e. class or object instance), and returns it as the first value:
my($invocant, $args) = $rule->validate(@_);
Sequenced
Deals with arguments in sequenced style, where users should pass arguments by the order of argument rules, instead of by-name.
Note that if the last argument is a HASH reference, it is regarded as named-style arguments.
AllowExtra
Regards unknown arguments as extra arguments, and returns them as a list of name-value pairs:
my($args, %extra) = $rule->validate(@_);
DEPENDENCIES
Perl 5.8.1 or later.
BUGS
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.
SEE ALSO
AUTHOR
Fuji, Goro (gfx) <gfuji@cpan.org>
LICENSE AND COPYRIGHT
Copyright (c) 2010, Fuji Goro (gfx). All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.