From 36610f8548eeabdde065fa40fd8f3dd7ffc7fc56 Mon Sep 17 00:00:00 2001 From: Stevan Little Date: Wed, 10 Oct 2012 09:34:08 -0400 Subject: adding more complex example in the synopsis to illustrate how much more this module does, and adding a test to test that example --- lib/MooseX/Meta/TypeConstraint/Doctype.pm | 36 ++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'lib/MooseX/Meta/TypeConstraint/Doctype.pm') diff --git a/lib/MooseX/Meta/TypeConstraint/Doctype.pm b/lib/MooseX/Meta/TypeConstraint/Doctype.pm index 03b5712..f18da4c 100644 --- a/lib/MooseX/Meta/TypeConstraint/Doctype.pm +++ b/lib/MooseX/Meta/TypeConstraint/Doctype.pm @@ -13,15 +13,45 @@ use MooseX::Validation::Doctypes::Errors; use MooseX::Validation::Doctypes; + doctype 'Location' => { + id => 'Str', + city => 'Str', + state => 'Str', + country => 'Str', + zipcode => 'Int', + }; + doctype 'Person' => { id => 'Str', - name => 'Str', - title => '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; - my $data = decode_json('{"id": "1234-A", "name": "Bob", "title": "CIO"}'); + # 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; -- cgit v1.2.3