## type predicates ...
+sub equals {
+ my ( $self, $type_or_name ) = @_;
+
+ my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
+
+ $self->name eq $type->name;
+}
+
sub is_a_type_of {
- my ($self, $type_name) = @_;
- ($self->name eq $type_name || $self->is_subtype_of($type_name));
+ my ($self, $type_or_name) = @_;
+
+ my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
+
+ ($self->equals($type) || $self->is_subtype_of($type));
}
sub is_subtype_of {
- my ($self, $type_name) = @_;
+ my ($self, $type_or_name) = @_;
+
+ my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
+
my $current = $self;
+
while (my $parent = $current->parent) {
- return 1 if $parent->name eq $type_name;
+ return 1 if $parent->equals($type);
$current = $parent;
}
+
return 0;
}
=item B<new>
-=item B<is_a_type_of ($type_name)>
+=item B<equals ($type_name_or_object)>
+
+=item B<is_a_type_of ($type_name_or_object)>
This checks the current type name, and if it does not match,
checks if it is a subtype of it.
-=item B<is_subtype_of ($type_name)>
+=item B<is_subtype_of ($type_name_or_object)>
=item B<compile_type_constraint>
=item B<has_parent>
+=item B<parents>
+
=item B<constraint>
=item B<has_message>
sub has_hand_optimized_type_constraint { 1 }
+sub equals {
+ my ( $self, $type_or_name ) = @_;
+
+ my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
+
+ if ( $type->isa(__PACKAGE__) ) {
+ return $self->class eq $type->class;
+ } else {
+ $self->SUPER::equals($type);
+ }
+}
+
sub is_a_type_of {
- my ($self, $type_name) = @_;
+ my ($self, $type_or_name) = @_;
- return $self->name eq $type_name || $self->is_subtype_of($type_name);
+ my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
+
+ ($self->equals($type) || $self->is_subtype_of($type_or_name));
}
sub is_subtype_of {
- my ($self, $type_name) = @_;
-
- return 1 if $type_name eq 'Object';
- return $self->name->isa( $type_name );
+ my ($self, $type_or_name_or_class ) = @_;
+
+ if ( not ref $type_or_name_or_class ) {
+ # it might be a class
+ return 1 if $self->class->isa( $type_or_name_or_class );
+ }
+
+ my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_class);
+
+ if ( $type->isa(__PACKAGE__) ) {
+ # if $type_or_name_or_class isn't a class, it might be the TC name of another ::Class type
+ # or it could also just be a type object in this branch
+ return $self->class->isa( $type->class );
+ } else {
+ # the only other thing we are a subtype of is Object
+ $self->SUPER::is_subtype_of($type);
+ }
}
1;
=item B<has_hand_optimized_type_constraint>
+=item B<equals>
+
=item B<is_a_type_of>
=item B<is_subtype_of>