From abcf38defd36cf7e25ac4b4d7e07f01d0bbd3cb1 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 15 Oct 2012 16:57:51 -0500 Subject: missing hashref/arrayref errors still need formatting also, they weren't being generated at all if the data was missing altogether --- lib/MooseX/Meta/TypeConstraint/Doctype.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/MooseX/Meta/TypeConstraint/Doctype.pm b/lib/MooseX/Meta/TypeConstraint/Doctype.pm index f18da4c..dbc1289 100644 --- a/lib/MooseX/Meta/TypeConstraint/Doctype.pm +++ b/lib/MooseX/Meta/TypeConstraint/Doctype.pm @@ -117,7 +117,7 @@ sub _validate_doctype { match_on_type $doctype => ( 'HashRef' => sub { if (!find_type_constraint('HashRef')->check($data)) { - $errors = $data; + $errors = $self->_format_error($data, $prefix); } else { for my $key (keys %$doctype) { @@ -147,7 +147,7 @@ sub _validate_doctype { }, 'ArrayRef' => sub { if (!find_type_constraint('ArrayRef')->check($data)) { - $errors = $data; + $errors = $self->_format_error($data, $prefix); } else { for my $i (0..$#$doctype) { @@ -178,7 +178,7 @@ sub _validate_doctype { my $tc = Moose::Util::TypeConstraints::find_or_parse_type_constraint($doctype); die "Unknown type $doctype" unless $tc; if (!$tc->check($data)) { - $errors = "invalid value " . dump($data) . " for '$prefix'"; + $errors = $self->_format_error($data, $prefix); } }, => sub { @@ -194,6 +194,13 @@ sub _validate_doctype { ); } +sub _format_error { + my $self = shift; + my ($data, $prefix) = @_; + + return "invalid value " . dump($data) . " for '$prefix'"; +} + no Moose; 1; -- cgit v1.2.3