From: John Napiorkowski Date: Wed, 1 Apr 2009 21:18:48 +0000 (+0000) Subject: first go at equals api X-Git-Tag: 0.01~31 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Dependent.git;a=commitdiff_plain;h=a5d0a8be817849c4ee58f39cd0143570a0b2633a first go at equals api --- diff --git a/lib/MooseX/Meta/TypeConstraint/Dependent.pm b/lib/MooseX/Meta/TypeConstraint/Dependent.pm index 6360c75..be3c2b8 100644 --- a/lib/MooseX/Meta/TypeConstraint/Dependent.pm +++ b/lib/MooseX/Meta/TypeConstraint/Dependent.pm @@ -271,59 +271,27 @@ around 'create_child_type' => sub { ); }; -=head2 is_a_type_of - -=head2 is_subtype_of - =head2 equals Override the base class behavior. - TBD +=cut sub equals { my ( $self, $type_or_name ) = @_; - my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); + my $other = Moose::Util::TypeConstraints::find_type_constraint("$type_or_name"); - return unless $other->isa(__PACKAGE__); - return ( - $self->type_constraints_equals($other) + $other->isa(__PACKAGE__) + and + $self->dependent_type_constraint->equals($other) and - $self->parent->equals( $other->parent ) + $self->constraining_type_constraint->equals($other) + and + $self->parent->equals($other->parent) ); } -=head2 type_constraints_equals - -Checks to see if the internal type contraints are equal. - - TBD - -sub type_constraints_equals { - my ($self, $other) = @_; - my @self_type_constraints = @{$self->type_constraints||[]}; - my @other_type_constraints = @{$other->type_constraints||[]}; - - ## Incoming ay be either arrayref or hashref, need top compare both - while(@self_type_constraints) { - my $self_type_constraint = shift @self_type_constraints; - my $other_type_constraint = shift @other_type_constraints - || return; ## $other needs the same number of children. - - if( ref $self_type_constraint) { - $self_type_constraint->equals($other_type_constraint) - || return; ## type constraints obviously need top be equal - } else { - $self_type_constraint eq $other_type_constraint - || return; ## strings should be equal - } - - } - - return 1; ##If we get this far, everything is good. -} - =head2 get_message Give you a better peek into what's causing the error.