1 package Moose::Meta::TypeConstraint::Parameterized;
7 use Scalar::Util 'blessed';
8 use Moose::Util::TypeConstraints;
9 use Moose::Meta::TypeConstraint::Parameterizable;
11 use base 'Moose::Meta::TypeConstraint';
13 __PACKAGE__->meta->add_attribute('type_parameter' => (
14 accessor => 'type_parameter',
15 predicate => 'has_type_parameter',
19 my ( $self, $type_or_name ) = @_;
21 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
23 return unless $other->isa(__PACKAGE__);
26 $self->type_parameter->equals( $other->type_parameter )
28 $self->parent->equals( $other->parent )
32 sub compile_type_constraint {
35 unless ( $self->has_type_parameter ) {
37 Moose->throw_error("You cannot create a Higher Order type without a type parameter");
40 my $type_parameter = $self->type_parameter;
42 unless ( blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint') ) {
44 Moose->throw_error("The type parameter must be a Moose meta type");
47 foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
48 if (my $constraint = $type->generate_constraint_for($self)) {
49 $self->_set_constraint($constraint);
50 return $self->SUPER::compile_type_constraint;
54 # if we get here, then we couldn't
55 # find a way to parameterize this type
57 Moose->throw_error("The " . $self->name . " constraint cannot be used, because "
58 . $self->parent->name . " doesn't subtype or coerce from a parameterizable type.");
61 sub create_child_type {
62 my ($self, %opts) = @_;
63 return Moose::Meta::TypeConstraint::Parameterizable->new(%opts, parent=>$self);
68 # ABSTRACT: Type constraints with a bound parameter (ArrayRef[Int])
77 This class is intentionally not documented because the API is
78 confusing and needs some work.
82 C<Moose::Meta::TypeConstraint::Parameterized> is a subclass of
83 L<Moose::Meta::TypeConstraint>.
87 See L<Moose/BUGS> for details on reporting bugs.