1 package MooseX::Meta::TypeConstraint::Role::Structured;
4 use Moose::Util::TypeConstraints;
5 requires qw(_normalize_args signature_equals);
9 MooseX::Meta::TypeConstraint::Role::Structured - Structured Type Constraints
13 This Role defines the interface and basic behavior of Structured Type Constraints.
15 Structured type constraints let you assign an internal pattern of type
16 constraints to a 'container' constraint. The goal is to make it easier to
17 declare constraints like "ArrayRef[Int, Int, Str]" where the constraint is an
18 ArrayRef of three elements and the internal constraint on the three is Int, Int
21 To accomplish this, we add an attribute to the base L<Moose::Meta::TypeConstraint>
22 to hold a L</signature>, which is a reference to a pattern of type constraints.
23 We then override L</constraint> to check our incoming value to the attribute
24 against this signature pattern. Additionally we allow L</optional_signature> to
25 hold any optional type constraints. The overall goal is to support something
28 has 'attr' => (isa=>'Tuple[Int, Str, Optional[Int, Int]]');
30 These classes define how the underlying support for this works.
34 The following types are defined in this class.
36 =head2 Moose::Meta::TypeConstraint
38 Used to make sure we can properly validate incoming signatures.
42 class_type 'Moose::Meta::TypeConstraint';
46 This class defines the following attributes.
50 This is a signature of internal contraints for the contents of the outer
61 =head2 optional_signature
63 This is a signature of internal contraints for the contents of the outer
64 contraint container. These are optional constraints.
68 has 'optional_signature' => (
71 predicate=>'has_optional_signature',
76 This class defines the following methods.
80 modifier to make sure equals descends into the L</signature>
84 around 'equals' => sub {
85 my ($equals, $self, $compared_type_constraint) = @_;
87 ## Make sure we are comparing typeconstraints of the same base class
88 return unless $compared_type_constraint->isa(__PACKAGE__);
90 ## Make sure the base equals is also good
91 return unless $self->$equals($compared_type_constraint);
93 ## Make sure the signatures match
94 return unless $self->signature_equals($compared_type_constraint);
96 ## If we get this far, the two are equal
102 John James Napiorkowski <jjnapiork@cpan.org>
106 You may distribute this code under the same terms as Perl itself.