1 package Moose::Meta::TypeConstraint::Parameterized;
7 use Scalar::Util 'blessed';
8 use Moose::Util::TypeConstraints;
9 use Moose::Meta::TypeConstraint::Parameterizable;
11 our $VERSION = '0.73';
12 $VERSION = eval $VERSION;
13 our $AUTHORITY = 'cpan:STEVAN';
15 use base 'Moose::Meta::TypeConstraint';
17 __PACKAGE__->meta->add_attribute('type_parameter' => (
18 accessor => 'type_parameter',
19 predicate => 'has_type_parameter',
23 my ( $self, $type_or_name ) = @_;
25 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
27 return unless $other->isa(__PACKAGE__);
30 $self->type_parameter->equals( $other->type_parameter )
32 $self->parent->equals( $other->parent )
36 sub compile_type_constraint {
39 unless ( $self->has_type_parameter ) {
41 Moose->throw_error("You cannot create a Higher Order type without a type parameter");
44 my $type_parameter = $self->type_parameter;
46 unless ( blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint') ) {
48 Moose->throw_error("The type parameter must be a Moose meta type");
51 foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
52 if (my $constraint = $type->generate_constraint_for($self)) {
53 $self->_set_constraint($constraint);
54 return $self->SUPER::compile_type_constraint;
58 # if we get here, then we couldn't
59 # find a way to parameterize this type
61 Moose->throw_error("The " . $self->name . " constraint cannot be used, because "
62 . $self->parent->name . " doesn't subtype or coerce from a parameterizable type.");
65 sub create_child_type {
66 my ($self, %opts) = @_;
67 return Moose::Meta::TypeConstraint::Parameterizable->new(%opts, parent=>$self);
79 Moose::Meta::TypeConstraint::Parameterized - Type constraints with a bound parameter (ArrayRef[Int])
83 This class is intentionally not documented because the API is
84 confusing and needs some work.
88 C<Moose::Meta::TypeConstraint::Parameterized> is a subclass of
89 L<Moose::Meta::TypeConstraint>.
93 All complex software has bugs lurking in it, and this module is no
94 exception. If you find a bug please either email me, or add the bug
99 Stevan Little E<lt>stevan@iinteractive.comE<gt>
101 =head1 COPYRIGHT AND LICENSE
103 Copyright 2006-2009 by Infinity Interactive, Inc.
105 L<http://www.iinteractive.com>
107 This library is free software; you can redistribute it and/or modify
108 it under the same terms as Perl itself.