1 package Moose::Meta::TypeConstraint::Parameterized;
7 use Scalar::Util 'blessed';
8 use Moose::Util::TypeConstraints;
10 our $VERSION = '0.60';
11 $VERSION = eval $VERSION;
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',
22 my ( $self, $type_or_name ) = @_;
24 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
26 return unless $other->isa(__PACKAGE__);
29 $self->type_parameter->equals( $other->type_parameter )
31 $self->parent->equals( $other->parent )
35 sub compile_type_constraint {
38 ($self->has_type_parameter)
39 || Moose->throw_error("You cannot create a Higher Order type without a type parameter");
41 my $type_parameter = $self->type_parameter;
43 (blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint'))
44 || Moose->throw_error("The type parameter must be a Moose meta type");
46 foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
47 if (my $constraint = $type->generate_constraint_for($self)) {
48 $self->_set_constraint($constraint);
49 return $self->SUPER::compile_type_constraint;
53 # if we get here, then we couldn't
54 # find a way to parameterize this type
55 Moose->throw_error("The " . $self->name . " constraint cannot be used, because "
56 . $self->parent->name . " doesn't subtype or coerce from a parameterizable type.");
59 sub create_child_type {
60 my ($self, %opts) = @_;
61 return Moose::Meta::TypeConstraint->new(%opts, parent => $self);
73 Moose::Meta::TypeConstraint::Parameterized - Higher Order type constraints for Moose
79 =item B<compile_type_constraint>
81 =item B<type_parameter>
83 =item B<has_type_parameter>
89 =item B<create_child_type>
95 All complex software has bugs lurking in it, and this module is no
96 exception. If you find a bug please either email me, or add the bug
101 Stevan Little E<lt>stevan@iinteractive.comE<gt>
103 =head1 COPYRIGHT AND LICENSE
105 Copyright 2006-2008 by Infinity Interactive, Inc.
107 L<http://www.iinteractive.com>
109 This library is free software; you can redistribute it and/or modify
110 it under the same terms as Perl itself.