summaryrefslogtreecommitdiffstats
path: root/lib/MooseX/Validation/Doctypes.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MooseX/Validation/Doctypes.pm')
-rw-r--r--lib/MooseX/Validation/Doctypes.pm36
1 files changed, 33 insertions, 3 deletions
diff --git a/lib/MooseX/Validation/Doctypes.pm b/lib/MooseX/Validation/Doctypes.pm
index c29e125..1c1ab2a 100644
--- a/lib/MooseX/Validation/Doctypes.pm
+++ b/lib/MooseX/Validation/Doctypes.pm
@@ -16,15 +16,45 @@ use Sub::Exporter -setup => {
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;