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 $parent_name = $self->parent->name;
35 if ($parent_name eq 'ArrayRef') {
38 ($type_parameter->check($x)) || return
42 elsif ($parent_name eq 'HashRef') {
44 foreach my $x (values %$_) {
45 ($type_parameter->check($x)) || return
50 confess "Your isa must be either ArrayRef or HashRef (sorry no subtype support yet)";
53 $self->_set_constraint($constraint);
55 $self->SUPER::compile_type_constraint;
67 Moose::Meta::TypeConstraint::Parameterized - Higher Order type constraints for Moose
75 =item B<compile_type_constraint>
77 =item B<type_parameter>
79 =item B<has_type_parameter>
87 All complex software has bugs lurking in it, and this module is no
88 exception. If you find a bug please either email me, or add the bug
93 Stevan Little E<lt>stevan@iinteractive.comE<gt>
95 =head1 COPYRIGHT AND LICENSE
97 Copyright 2006, 2007 by Infinity Interactive, Inc.
99 L<http://www.iinteractive.com>
101 This library is free software; you can redistribute it and/or modify
102 it under the same terms as Perl itself.