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
CommitLineData
9a491c80 1package MooseX::Meta::TypeConstraint::Role::Structured;
2
3use Moose::Role;
b5f77bd3 4use Moose::Util::TypeConstraints;
5requires qw(_normalize_args signature_equals);
9a491c80 6
7=head1 NAME
8
9MooseX::Meta::TypeConstraint::Role::Structured - Structured Type Constraints
10
11=head1 VERSION
12
130.01
14
15=cut
16
17our $VERSION = '0.01';
18
19=head1 DESCRIPTION
20
bc5c0758 21STUB - TBD
9a491c80 22
b5f77bd3 23=head1 TYPES
24
25The following types are defined in this class.
26
27=head2 Moose::Meta::TypeConstraint
28
29Used to make sure we can properly validate incoming signatures.
30
31=cut
32
33class_type 'Moose::Meta::TypeConstraint';
34
9a491c80 35=head1 ATTRIBUTES
36
37This class defines the following attributes.
38
39=head2 signature
40
41This is a signature of internal contraints for the contents of the outer
42contraint container.
43
44=cut
45
46has 'signature' => (
47 is=>'ro',
bc5c0758 48 isa=>'Ref',
9a491c80 49 required=>1,
50);
51
24dd1d2e 52=head2 optional_signature
53
54This is a signature of internal contraints for the contents of the outer
55contraint container. These are optional constraints.
56
57=cut
58
59has 'optional_signature' => (
60 is=>'ro',
61 isa=>'Ref',
62 predicate=>'has_optional_signature',
63);
64
9a491c80 65=head1 METHODS
66
67This class defines the following methods.
68
69=head2 _normalize_args
70
71Get arguments into a known state or die trying. Ideally we try to make this
72into a HashRef so we can match it up with the L</signature> HashRef.
9a491c80 73
74=head2 constraint
75
76The constraint is basically validating the L</signature> against the incoming
77
9a491c80 78=head2 equals
79
80modifier to make sure equals descends into the L</signature>
81
82=cut
83
b5f77bd3 84around 'equals' => sub {
85 my ($equals, $self, $compared_type_constraint) = @_;
86
87 ## Make sure we are comparing typeconstraints of the same base class
88 return unless $compared_type_constraint->isa(__PACKAGE__);
89
90 ## Make sure the base equals is also good
91 return unless $self->$equals($compared_type_constraint);
92
93 ## Make sure the signatures match
94 return unless $self->signature_equals($compared_type_constraint);
95
96 ## If we get this far, the two are equal
97 return 1;
98};
99
9a491c80 100=head2 signature_equals
101
102Check that the signature equals another signature.
103
9a491c80 104=head1 AUTHOR
105
106John James Napiorkowski <jjnapiork@cpan.org>
107
108=head1 LICENSE
109
110You may distribute this code under the same terms as Perl itself.
111
112=cut
113
bc5c0758 1141;