1 package Moose::Meta::TypeConstraint::Parameterized;
7 use Scalar::Util 'blessed';
10 our $VERSION = '0.01';
11 our $AUTHORITY = 'cpan:STEVAN';
13 use base 'Moose::Meta::TypeConstraint';
15 __PACKAGE__->meta->add_attribute('type_parameter' => (
16 accessor => 'type_parameter',
17 predicate => 'has_type_parameter',
20 sub compile_type_constraint {
23 ($self->has_type_parameter)
24 || confess "You cannot create a Higher Order type without a type parameter";
26 my $type_parameter = $self->type_parameter;
28 (blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint'))
29 || confess "The type parameter must be a Moose meta type";
33 my $array_constraint = sub {
35 ($type_parameter->check($x)) || return
39 my $hash_constraint = sub {
40 foreach my $x (values %$_) {
41 ($type_parameter->check($x)) || return
45 if ($self->is_subtype_of('ArrayRef')) {
46 $constraint = $array_constraint;
48 elsif ($self->is_subtype_of('HashRef')) {
49 $constraint = $hash_constraint;
52 confess "The " . $self->name . " constraint cannot be used, because " . $self->parent->name . " doesn't subtype ArrayRef or HashRef.";
55 $self->_set_constraint($constraint);
57 $self->SUPER::compile_type_constraint;
69 Moose::Meta::TypeConstraint::Parameterized - Higher Order type constraints for Moose
77 =item B<compile_type_constraint>
79 =item B<type_parameter>
81 =item B<has_type_parameter>
89 All complex software has bugs lurking in it, and this module is no
90 exception. If you find a bug please either email me, or add the bug
95 Stevan Little E<lt>stevan@iinteractive.comE<gt>
97 =head1 COPYRIGHT AND LICENSE
99 Copyright 2006, 2007 by Infinity Interactive, Inc.
101 L<http://www.iinteractive.com>
103 This library is free software; you can redistribute it and/or modify
104 it under the same terms as Perl itself.