summaryrefslogtreecommitdiffstats
path: root/lib/MooseX/Meta/TypeConstraint/Doctype.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MooseX/Meta/TypeConstraint/Doctype.pm')
-rw-r--r--lib/MooseX/Meta/TypeConstraint/Doctype.pm36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/MooseX/Meta/TypeConstraint/Doctype.pm b/lib/MooseX/Meta/TypeConstraint/Doctype.pm
index 0d333cc..9502424 100644
--- a/lib/MooseX/Meta/TypeConstraint/Doctype.pm
+++ b/lib/MooseX/Meta/TypeConstraint/Doctype.pm
@@ -1,5 +1,6 @@
package MooseX::Meta::TypeConstraint::Doctype;
use Moose;
+# ABSTRACT: Moose type constraint for validating doctypes
use Devel::PartialDump 'dump';
use Moose::Util::TypeConstraints qw(class_type find_type_constraint
@@ -8,10 +9,45 @@ use Scalar::Util 'weaken';
use MooseX::Validation::Doctypes::Errors;
+=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');
+ die "Data is invalid" unless $person->check($data);
+
+=head1 DESCRIPTION
+
+This module implements the actual type constraint that is created by the
+C<doctype> function in L<MooseX::Validation::Doctypes>. It is a subclass of
+L<Moose::Meta::TypeConstraint> which adds a required C<doctype> parameter, and
+automatically generates a constraint and message which validate based on that
+doctype (as described in the MooseX::Validation::Doctypes docs).
+
+=cut
+
extends 'Moose::Meta::TypeConstraint';
class_type('Moose::Meta::TypeConstraint');
+=attr doctype
+
+The doctype to validate. Required.
+
+=cut
+
has doctype => (
is => 'ro',
isa => 'Ref',