Why not adopt me?
This distribution is up for adoption!
If you're interested then please contact the PAUSE module admins via
email.
NAME
MooseX::Meta::TypeConstraint::Doctype - Moose type constraint for validating doctypes
VERSION
version 0.05
SYNOPSIS
use MooseX::Validation::Doctypes;
doctype 'Location' => {
id => 'Str',
city => 'Str',
state => 'Str',
country => 'Str',
zipcode => 'Int',
};
doctype 'Person' => {
id => 'Str',
name => {
# ... nested data structures
first_name => 'Str',
last_name => 'Str',
},
title => 'Str',
# ... complex Moose types
friends => 'ArrayRef[Person]',
# ... using doctypes same as regular types
address => 'Maybe[Location]',
};
use JSON;
# note the lack of Location,
# which is fine because it
# was Maybe[Location]
my $data = decode_json(q[
{
"id": "1234-A",
"name": {
"first_name" : "Bob",
"last_name" : "Smith",
},
"title": "CIO",
"friends" : [],
}
]);
use Moose::Util::TypeConstraints;
my $person = find_type_constraint('Person');
die "Data is invalid" unless $person->check($data);
DESCRIPTION
This module implements the actual type constraint that is created by the doctype
function in MooseX::Validation::Doctypes. It is a subclass of Moose::Meta::TypeConstraint which adds a required doctype
parameter, and automatically generates a constraint and message which validate based on that doctype (as described in the MooseX::Validation::Doctypes docs).
ATTRIBUTES
doctype
The doctype to validate. Required.
AUTHOR
Jesse Luehrs <doy at cpan dot org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2012 by Jesse Luehrs.
This is free software, licensed under:
The MIT (X11) License