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',
16 Class::MOP::_definition_context(),
19 __PACKAGE__->meta->add_attribute('parameterized_from' => (
20 accessor => 'parameterized_from',
21 predicate => 'has_parameterized_from',
22 Class::MOP::_definition_context(),
26 my ( $self, $type_or_name ) = @_;
28 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
30 return unless $other->isa(__PACKAGE__);
33 $self->type_parameter->equals( $other->type_parameter )
35 $self->parent->equals( $other->parent )
39 sub compile_type_constraint {
42 unless ( $self->has_type_parameter ) {
44 Moose->throw_error("You cannot create a Higher Order type without a type parameter");
47 my $type_parameter = $self->type_parameter;
49 unless ( blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint') ) {
51 Moose->throw_error("The type parameter must be a Moose meta type");
54 foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
55 if (my $constraint = $type->generate_constraint_for($self)) {
56 $self->_set_constraint($constraint);
57 return $self->SUPER::compile_type_constraint;
61 # if we get here, then we couldn't
62 # find a way to parameterize this type
64 Moose->throw_error("The " . $self->name . " constraint cannot be used, because "
65 . $self->parent->name . " doesn't subtype or coerce from a parameterizable type.");
72 $self->has_parameterized_from
73 && $self->parameterized_from->has_inline_generator
74 && $self->type_parameter->can_be_inlined;
77 sub inline_environment {
81 ($self->has_parameterized_from
82 ? (%{ $self->parameterized_from->inline_environment })
84 ($self->has_type_parameter
85 ? (%{ $self->type_parameter->inline_environment })
93 return unless $self->can_be_inlined;
95 return $self->parameterized_from->generate_inline_for( $self->type_parameter, @_ );
98 sub create_child_type {
99 my ($self, %opts) = @_;
100 return Moose::Meta::TypeConstraint::Parameterizable->new(%opts, parent=>$self);
105 # ABSTRACT: Type constraints with a bound parameter (ArrayRef[Int])
114 This class is intentionally not documented because the API is
115 confusing and needs some work.
119 C<Moose::Meta::TypeConstraint::Parameterized> is a subclass of
120 L<Moose::Meta::TypeConstraint>.
124 See L<Moose/BUGS> for details on reporting bugs.