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',
18 __PACKAGE__->meta->add_attribute('parameterized_from' => (
19 accessor => 'parameterized_from',
20 predicate => 'has_parameterized_from',
24 my ( $self, $type_or_name ) = @_;
26 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
28 return unless $other->isa(__PACKAGE__);
31 $self->type_parameter->equals( $other->type_parameter )
33 $self->parent->equals( $other->parent )
37 sub compile_type_constraint {
40 unless ( $self->has_type_parameter ) {
42 Moose->throw_error("You cannot create a Higher Order type without a type parameter");
45 my $type_parameter = $self->type_parameter;
47 unless ( blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint') ) {
49 Moose->throw_error("The type parameter must be a Moose meta type");
52 foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
53 if (my $constraint = $type->generate_constraint_for($self)) {
54 $self->_set_constraint($constraint);
55 return $self->SUPER::compile_type_constraint;
59 # if we get here, then we couldn't
60 # find a way to parameterize this type
62 Moose->throw_error("The " . $self->name . " constraint cannot be used, because "
63 . $self->parent->name . " doesn't subtype or coerce from a parameterizable type.");
70 $self->has_parameterized_from
71 && $self->parameterized_from->has_inline_generator
72 && $self->type_parameter->can_be_inlined;
78 return unless $self->can_be_inlined;
80 return $self->parameterized_from->generate_inline_for( $self->type_parameter, @_ );
83 sub create_child_type {
84 my ($self, %opts) = @_;
85 return Moose::Meta::TypeConstraint::Parameterizable->new(%opts, parent=>$self);
90 # ABSTRACT: Type constraints with a bound parameter (ArrayRef[Int])
99 This class is intentionally not documented because the API is
100 confusing and needs some work.
104 C<Moose::Meta::TypeConstraint::Parameterized> is a subclass of
105 L<Moose::Meta::TypeConstraint>.
109 See L<Moose/BUGS> for details on reporting bugs.