summaryrefslogtreecommitdiffstats
path: root/lib/MooseX/Validation/Doctypes/Errors.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MooseX/Validation/Doctypes/Errors.pm')
-rw-r--r--lib/MooseX/Validation/Doctypes/Errors.pm63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/MooseX/Validation/Doctypes/Errors.pm b/lib/MooseX/Validation/Doctypes/Errors.pm
index d510670..7ca640e 100644
--- a/lib/MooseX/Validation/Doctypes/Errors.pm
+++ b/lib/MooseX/Validation/Doctypes/Errors.pm
@@ -1,11 +1,74 @@
package MooseX::Validation::Doctypes::Errors;
use Moose;
+# ABSTRACT: error class for MooseX::Validation::Doctypes
+
+=head1 SYNOPSIS
+
+ use MooseX::Validation::Doctypes;
+
+ doctype 'Person' => {
+ id => 'Str',
+ name => 'Str',
+ title => 'Str',
+ };
+
+ use JSON;
+
+ my $data = decode_json('{"id": "1234-A", "name": "Bob", "title": "CIO"}');
+
+ use Moose::Util::TypeConstraints;
+
+ my $person = find_type_constraint('Person');
+ my $errors = $person->validate($data);
+
+ use Data::Dumper;
+
+ warn Dumper($errors->errors) if $errors->has_errors;
+ warn Dumper($errors->extra_data) if $errors->has_extra_data;
+
+=head1 DESCRIPTION
+
+This class holds the errors that were found when validating a doctype. There
+are two types of errors: either an existing piece of data didn't validate
+against the given type constraint, or extra data was provided that wasn't
+listed in the doctype. These two types correspond to the C<errors> and
+C<extra_data> attributes described below.
+
+=cut
+
+=attr errors
+
+Returns the errors that were detected. The return value will be a data
+structure with the same form as the doctype, except only leaves corresponding
+to values that failed to match their corresponding type constraint. The values
+will be an appropriate error message.
+
+=method has_errors
+
+Returns true if any errors were found when validating the data against the type
+constraints.
+
+=cut
has errors => (
is => 'ro',
predicate => 'has_errors',
);
+=attr extra_data
+
+Returns the extra data that was detected. The return value will be a data
+structure with the same form as the incoming data, except only containing
+leaves for data which was not represented in the doctype. The values will be
+the values from the actual data being validated.
+
+=method has_extra_data
+
+Returns true if any extra data was found when comparing the data to the
+doctype.
+
+=cut
+
has extra_data => (
is => 'ro',
predicate => 'has_extra_data',