[libtype-tiny-perl] 04/11: implement subtype/supertype stuff in unions (TODO: needs testing)

Jonas Smedegaard dr at jones.dk
Wed Oct 29 19:42:47 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 1.001_002
in repository libtype-tiny-perl.

commit 9c789388723e10607dc491c6d0de600717b2ae09
Author: Toby Inkster <mail at tobyinkster.co.uk>
Date:   Tue Sep 30 22:30:11 2014 +0100

    implement subtype/supertype stuff in unions (TODO: needs testing)
---
 lib/Type/Tiny/Union.pm | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/lib/Type/Tiny/Union.pm b/lib/Type/Tiny/Union.pm
index 9266273..a02484d 100644
--- a/lib/Type/Tiny/Union.pm
+++ b/lib/Type/Tiny/Union.pm
@@ -213,6 +213,49 @@ sub equals
 	@other_constraints == 0;
 }
 
+sub is_a_type_of
+{
+	my ($self, $other) = Type::Tiny::_loose_to_TypeTiny(@_);
+	return unless blessed($self)  && $self->isa("Type::Tiny");
+	return unless blessed($other) && $other->isa("Type::Tiny");
+	
+	return !!1 if $self->SUPER::is_a_type_of($other);
+	
+	for my $tc (@{ $self->type_constraints }) {
+		return !!0 unless $tc->is_a_type_of($other);
+	}
+	return !!1;
+}
+
+sub is_subtype_of
+{
+	my ($self, $other) = Type::Tiny::_loose_to_TypeTiny(@_);
+	return unless blessed($self)  && $self->isa("Type::Tiny");
+	return unless blessed($other) && $other->isa("Type::Tiny");
+	
+	return !!1 if $self->SUPER::is_subtype_of($other);
+	
+	for my $tc (@{ $self->type_constraints }) {
+		return !!0 unless $tc->is_subtype_of($other);
+	}
+	return !!1;
+}
+
+sub is_supertype_of
+{
+	my ($self, $other) = Type::Tiny::_loose_to_TypeTiny(@_);
+	return unless blessed($self)  && $self->isa("Type::Tiny");
+	return unless blessed($other) && $other->isa("Type::Tiny");
+	
+	return !!1 if $self->SUPER::is_supertype_of($other);
+	
+	for my $tc (@{ $self->type_constraints }) {
+		return !!1 if $tc->equals($other);
+		return !!1 if $tc->is_supertype_of($other);
+	}
+	return !!0;
+}
+
 1;
 
 __END__

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libtype-tiny-perl.git



More information about the Pkg-perl-cvs-commits mailing list