summaryrefslogtreecommitdiffstats
path: root/lib/MooseX/Meta/TypeConstraint/Doctype.pm
diff options
context:
space:
mode:
authorStevan Little <stevan.little@iinteractive.com>2012-10-10 09:34:08 -0400
committerStevan Little <stevan.little@iinteractive.com>2012-10-10 09:34:08 -0400
commit36610f8548eeabdde065fa40fd8f3dd7ffc7fc56 (patch)
treea966dced1a091b2c36ee3d1f5d3a5a1a05418e67 /lib/MooseX/Meta/TypeConstraint/Doctype.pm
parenta5be6ff67d942fd419646fad12c4f39a851f4257 (diff)
downloadmoosex-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/Meta/TypeConstraint/Doctype.pm')
-rw-r--r--lib/MooseX/Meta/TypeConstraint/Doctype.pm36
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;