summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO1
-rw-r--r--lib/Type/Tiny/Class.pm11
-rw-r--r--lib/Type/Tiny/Duck.pm11
-rw-r--r--lib/Type/Tiny/Enum.pm11
-rw-r--r--lib/Type/Tiny/Union.pm14
5 files changed, 48 insertions, 0 deletions
diff --git a/TODO b/TODO
index c09c0997..3a5c48f0 100644
--- a/TODO
+++ b/TODO
@@ -6,6 +6,7 @@
- t/type-union.t: test the Type::Tiny::Union class
- t/type-intersection.t: test the Type::Tiny::Intersection class
- test DWIM behaviour of Type::Tiny::Class::new
+ - test Moose inflation of Type::Tiny subclasses
- documentation
- mention DWIM behaviour of Type::Tiny::Class::new
diff --git a/lib/Type/Tiny/Class.pm b/lib/Type/Tiny/Class.pm
index 5a860fec..6c921538 100644
--- a/lib/Type/Tiny/Class.pm
+++ b/lib/Type/Tiny/Class.pm
@@ -60,6 +60,17 @@ sub _build_message
return sub { sprintf 'value "%s" did not pass type constraint "%s" (not isa %s)', $_[0], $name, $c };
}
+sub _instantiate_moose_type
+{
+ my $self = shift;
+ my %opts = @_;
+ delete $opts{parent};
+ delete $opts{constraint};
+ delete $opts{inlined};
+ require Moose::Meta::TypeConstraint::Class;
+ return "Moose::Meta::TypeConstraint::Class"->new(%opts, class => $self->class);
+}
+
1;
__END__
diff --git a/lib/Type/Tiny/Duck.pm b/lib/Type/Tiny/Duck.pm
index 52281a8c..a084a9ad 100644
--- a/lib/Type/Tiny/Duck.pm
+++ b/lib/Type/Tiny/Duck.pm
@@ -59,6 +59,17 @@ sub _build_message
return sub { sprintf 'value "%s" did not pass type constraint "%s"', $_[0], $name };
}
+sub _instantiate_moose_type
+{
+ my $self = shift;
+ my %opts = @_;
+ delete $opts{parent};
+ delete $opts{constraint};
+ delete $opts{inlined};
+ require Moose::Meta::TypeConstraint::DuckType;
+ return "Moose::Meta::TypeConstraint::DuckType"->new(%opts, methods => $self->methods);
+}
+
1;
__END__
diff --git a/lib/Type/Tiny/Enum.pm b/lib/Type/Tiny/Enum.pm
index f81220e6..a968419f 100644
--- a/lib/Type/Tiny/Enum.pm
+++ b/lib/Type/Tiny/Enum.pm
@@ -60,6 +60,17 @@ sub inline_check
"$_[0] =~ m{^(?:$regexp)\$}";
}
+sub _instantiate_moose_type
+{
+ my $self = shift;
+ my %opts = @_;
+ delete $opts{parent};
+ delete $opts{constraint};
+ delete $opts{inlined};
+ require Moose::Meta::TypeConstraint::Enum;
+ return "Moose::Meta::TypeConstraint::Enum"->new(%opts, values => $self->values);
+}
+
1;
__END__
diff --git a/lib/Type/Tiny/Union.pm b/lib/Type/Tiny/Union.pm
index 8f7199e5..eacbc34c 100644
--- a/lib/Type/Tiny/Union.pm
+++ b/lib/Type/Tiny/Union.pm
@@ -65,6 +65,20 @@ sub inline_check
join " or ", map $_->inline_check($_[0]), @$self;
}
+sub _instantiate_moose_type
+{
+ my $self = shift;
+ my %opts = @_;
+ delete $opts{parent};
+ delete $opts{constraint};
+ delete $opts{inlined};
+
+ my @tc = map $_->moose_type, @{$self->type_constraints};
+
+ require Moose::Meta::TypeConstraint::Union;
+ return "Moose::Meta::TypeConstraint::Union"->new(%opts, type_constraints => \@tc);
+}
+
1;
__END__