MooseX::Meta::TypeConstraint::Doctype - Moose type constraint for validating doctypes
version 0.03
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);
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).
doctype
The doctype to validate. Required.
Jesse Luehrs <doy at cpan dot org>
This software is Copyright (c) 2012 by Jesse Luehrs.
This is free software, licensed under:
The MIT (X11) License
To install MooseX::Validation::Doctypes, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Validation::Doctypes
CPAN shell
perl -MCPAN -e shell install MooseX::Validation::Doctypes
For more information on module installation, please visit the detailed CPAN module installation guide.