1 package Moose::Meta::TypeConstraint::Parameterized;
7 use Scalar::Util 'blessed';
9 use Moose::Util::TypeConstraints;
11 our $VERSION = '0.02';
12 our $AUTHORITY = 'cpan:STEVAN';
14 use base 'Moose::Meta::TypeConstraint';
16 __PACKAGE__->meta->add_attribute('type_parameter' => (
17 accessor => 'type_parameter',
18 predicate => 'has_type_parameter',
21 sub compile_type_constraint {
24 ($self->has_type_parameter)
25 || confess "You cannot create a Higher Order type without a type parameter";
27 my $type_parameter = $self->type_parameter;
29 (blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint'))
30 || confess "The type parameter must be a Moose meta type";
32 foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
33 if (my $constraint = $type->generate_constraint_for($self)) {
34 $self->_set_constraint($constraint);
35 return $self->SUPER::compile_type_constraint;
39 # if we get here, then we couldn't
40 # find a way to parameterize this type
41 confess "The " . $self->name . " constraint cannot be used, because "
42 . $self->parent->name . " doesn't subtype or coerce from a parameterizable type.";
54 Moose::Meta::TypeConstraint::Parameterized - Higher Order type constraints for Moose
60 =item B<compile_type_constraint>
62 =item B<type_parameter>
64 =item B<has_type_parameter>
72 All complex software has bugs lurking in it, and this module is no
73 exception. If you find a bug please either email me, or add the bug
78 Stevan Little E<lt>stevan@iinteractive.comE<gt>
80 =head1 COPYRIGHT AND LICENSE
82 Copyright 2006-2008 by Infinity Interactive, Inc.
84 L<http://www.iinteractive.com>
86 This library is free software; you can redistribute it and/or modify
87 it under the same terms as Perl itself.