summaryrefslogtreecommitdiffstats
path: root/lib/MooseX/Meta
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-15 17:43:28 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-15 17:43:51 -0500
commit8a4a17246fd4b2192fd9dac5d2380c09c666b5ee (patch)
tree9121dd79a1ba947f11f008622d7220132e67c397 /lib/MooseX/Meta
parent0bc360fa3c2e5a85a7110b62b74b1bfb9be284dd (diff)
downloadmoosex-validation-doctypes-8a4a17246fd4b2192fd9dac5d2380c09c666b5ee.tar.gz
moosex-validation-doctypes-8a4a17246fd4b2192fd9dac5d2380c09c666b5ee.zip
add maybe_doctype
Diffstat (limited to 'lib/MooseX/Meta')
-rw-r--r--lib/MooseX/Meta/TypeConstraint/Doctype.pm15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/MooseX/Meta/TypeConstraint/Doctype.pm b/lib/MooseX/Meta/TypeConstraint/Doctype.pm
index cc48312..18dfd7c 100644
--- a/lib/MooseX/Meta/TypeConstraint/Doctype.pm
+++ b/lib/MooseX/Meta/TypeConstraint/Doctype.pm
@@ -84,6 +84,11 @@ has doctype => (
required => 1,
);
+has maybe => (
+ is => 'ro',
+ isa => 'Bool',
+);
+
has '+parent' => (
default => sub { find_type_constraint('Ref') },
);
@@ -116,7 +121,10 @@ sub _validate_doctype {
match_on_type $doctype => (
'HashRef' => sub {
- if (!find_type_constraint('HashRef')->check($data)) {
+ if ($self->maybe && !defined($data)) {
+ # ignore it
+ }
+ elsif (!find_type_constraint('HashRef')->check($data)) {
$errors = $self->_format_error($data, $prefix);
}
else {
@@ -146,7 +154,10 @@ sub _validate_doctype {
}
},
'ArrayRef' => sub {
- if (!find_type_constraint('ArrayRef')->check($data)) {
+ if ($self->maybe && !defined($data)) {
+ # ignore it
+ }
+ elsif (!find_type_constraint('ArrayRef')->check($data)) {
$errors = $self->_format_error($data, $prefix);
}
else {