diff options
author | Stevan Little <stevan.little@iinteractive.com> | 2012-10-10 09:34:08 -0400 |
---|---|---|
committer | Stevan Little <stevan.little@iinteractive.com> | 2012-10-10 09:34:08 -0400 |
commit | 36610f8548eeabdde065fa40fd8f3dd7ffc7fc56 (patch) | |
tree | a966dced1a091b2c36ee3d1f5d3a5a1a05418e67 /lib/MooseX/Validation/Doctypes | |
parent | a5be6ff67d942fd419646fad12c4f39a851f4257 (diff) | |
download | moosex-validation-doctypes-36610f8548eeabdde065fa40fd8f3dd7ffc7fc56.tar.gz moosex-validation-doctypes-36610f8548eeabdde065fa40fd8f3dd7ffc7fc56.zip |
adding more complex example in the synopsis to illustrate how much more this module does, and adding a test to test that example
Diffstat (limited to 'lib/MooseX/Validation/Doctypes')
-rw-r--r-- | lib/MooseX/Validation/Doctypes/Errors.pm | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/lib/MooseX/Validation/Doctypes/Errors.pm b/lib/MooseX/Validation/Doctypes/Errors.pm index 7ca640e..023493c 100644 --- a/lib/MooseX/Validation/Doctypes/Errors.pm +++ b/lib/MooseX/Validation/Doctypes/Errors.pm @@ -6,15 +6,45 @@ use Moose; 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; |