more refactoring to the Structured Role, put together some tests to show the optional...
[gitmo/MooseX-Types-Structured.git] / lib / MooseX / Meta / TypeConstraint / Role / Structured.pm
index 7d7c097..00e7722 100644 (file)
@@ -1,6 +1,8 @@
 package MooseX::Meta::TypeConstraint::Role::Structured;
 
 use Moose::Role;
+use Moose::Util::TypeConstraints;
+requires qw(_normalize_args signature_equals);
 
 =head1 NAME
 
@@ -18,6 +20,18 @@ our $VERSION = '0.01';
 
 STUB - TBD
 
+=head1 TYPES
+
+The following types are defined in this class.
+
+=head2 Moose::Meta::TypeConstraint
+
+Used to make sure we can properly validate incoming signatures.
+
+=cut
+
+class_type 'Moose::Meta::TypeConstraint';
+
 =head1 ATTRIBUTES
 
 This class defines the following attributes.
@@ -56,28 +70,37 @@ This class defines the following methods.
 
 Get arguments into a known state or die trying.  Ideally we try to make this
 into a HashRef so we can match it up with the L</signature> HashRef.
-
-=cut
-
     
 =head2 constraint
 
 The constraint is basically validating the L</signature> against the incoming
 
-=cut
-
 =head2 equals
 
 modifier to make sure equals descends into the L</signature>
 
 =cut
 
+around 'equals' => sub {
+    my ($equals, $self, $compared_type_constraint) = @_;
+    
+    ## Make sure we are comparing typeconstraints of the same base class
+    return unless $compared_type_constraint->isa(__PACKAGE__);
+    
+    ## Make sure the base equals is also good
+    return unless $self->$equals($compared_type_constraint);
+    
+    ## Make sure the signatures match
+    return unless $self->signature_equals($compared_type_constraint);
+   
+    ## If we get this far, the two are equal
+    return 1;
+};
+
 =head2 signature_equals
 
 Check that the signature equals another signature.
 
-=cut
-
 =head1 AUTHOR
 
 John James Napiorkowski <jjnapiork@cpan.org>