diff options
Diffstat (limited to 'lib/MooseX/Meta/TypeConstraint')
-rw-r--r-- | lib/MooseX/Meta/TypeConstraint/Doctype.pm | 36 |
1 files changed, 33 insertions, 3 deletions
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; |