summaryrefslogtreecommitdiffstats
path: root/lib/MooseX/Validation
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-09 20:52:44 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-09 21:11:49 -0500
commitbb2bf61723962222952d2f68da497f8391dc6a5e (patch)
tree8b7f1eaba5805b31eb5b13523521896d9063acef /lib/MooseX/Validation
parent187562dd74bec5692831c08e8d8edf54f91ce031 (diff)
downloadmoosex-validation-doctypes-bb2bf61723962222952d2f68da497f8391dc6a5e.tar.gz
moosex-validation-doctypes-bb2bf61723962222952d2f68da497f8391dc6a5e.zip
initial implementation
Diffstat (limited to 'lib/MooseX/Validation')
-rw-r--r--lib/MooseX/Validation/Doctypes.pm35
-rw-r--r--lib/MooseX/Validation/Doctypes/Errors.pm17
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/MooseX/Validation/Doctypes.pm b/lib/MooseX/Validation/Doctypes.pm
index e69de29..668c4f0 100644
--- a/lib/MooseX/Validation/Doctypes.pm
+++ b/lib/MooseX/Validation/Doctypes.pm
@@ -0,0 +1,35 @@
+package MooseX::Validation::Doctypes;
+use strict;
+use warnings;
+
+use MooseX::Meta::TypeConstraint::Doctype;
+
+use Sub::Exporter -setup => {
+ exports => ['doctype'],
+ groups => {
+ default => ['doctype'],
+ },
+};
+
+sub doctype {
+ my $name;
+ $name = shift if @_ > 1;
+
+ my ($doctype) = @_;
+
+ # XXX validate name
+
+ my $args = {
+ ($name ? (name => $name) : ()),
+ doctype => $doctype,
+ package_defined_in => scalar(caller),
+ };
+
+ my $tc = MooseX::Meta::TypeConstraint::Doctype->new($args);
+ Moose::Util::TypeConstraints::register_type_constraint($tc)
+ if $name;
+
+ return $tc;
+}
+
+1;
diff --git a/lib/MooseX/Validation/Doctypes/Errors.pm b/lib/MooseX/Validation/Doctypes/Errors.pm
new file mode 100644
index 0000000..d510670
--- /dev/null
+++ b/lib/MooseX/Validation/Doctypes/Errors.pm
@@ -0,0 +1,17 @@
+package MooseX::Validation::Doctypes::Errors;
+use Moose;
+
+has errors => (
+ is => 'ro',
+ predicate => 'has_errors',
+);
+
+has extra_data => (
+ is => 'ro',
+ predicate => 'has_extra_data',
+);
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;