1 package Moose::Meta::TypeConstraint::Parameterized;
7 use Scalar::Util 'blessed';
8 use Moose::Util::TypeConstraints;
9 use Moose::Meta::TypeConstraint::Parameterizable;
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',
21 my ( $self, $type_or_name ) = @_;
23 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
25 return unless $other->isa(__PACKAGE__);
28 $self->type_parameter->equals( $other->type_parameter )
30 $self->parent->equals( $other->parent )
34 sub compile_type_constraint {
37 unless ( $self->has_type_parameter ) {
39 Moose->throw_error("You cannot create a Higher Order type without a type parameter");
42 my $type_parameter = $self->type_parameter;
44 unless ( blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint') ) {
46 Moose->throw_error("The type parameter must be a Moose meta type");
49 foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
50 if (my $constraint = $type->generate_constraint_for($self)) {
51 $self->_set_constraint($constraint);
52 return $self->SUPER::compile_type_constraint;
56 # if we get here, then we couldn't
57 # find a way to parameterize this type
59 Moose->throw_error("The " . $self->name . " constraint cannot be used, because "
60 . $self->parent->name . " doesn't subtype or coerce from a parameterizable type.");
63 sub create_child_type {
64 my ($self, %opts) = @_;
65 return Moose::Meta::TypeConstraint::Parameterizable->new(%opts, parent=>$self);
70 # ABSTRACT: Type constraints with a bound parameter (ArrayRef[Int])
79 This class is intentionally not documented because the API is
80 confusing and needs some work.
84 C<Moose::Meta::TypeConstraint::Parameterized> is a subclass of
85 L<Moose::Meta::TypeConstraint>.
89 See L<Moose/BUGS> for details on reporting bugs.