From 8a4a17246fd4b2192fd9dac5d2380c09c666b5ee Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 15 Oct 2012 17:43:28 -0500 Subject: add maybe_doctype --- lib/MooseX/Meta/TypeConstraint/Doctype.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/MooseX/Meta/TypeConstraint/Doctype.pm') 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 { -- cgit v1.2.3-54-g00ecf