1 package Moose::Meta::TypeConstraint::Parameterizable;
8 $VERSION = eval $VERSION;
9 our $AUTHORITY = 'cpan:STEVAN';
11 use base 'Moose::Meta::TypeConstraint';
12 use Moose::Meta::TypeConstraint::Parameterized;
14 __PACKAGE__->meta->add_attribute('constraint_generator' => (
15 accessor => 'constraint_generator',
16 predicate => 'has_constraint_generator',
19 sub generate_constraint_for {
20 my ($self, $type) = @_;
22 return unless $self->has_constraint_generator;
24 return $self->constraint_generator->($type->type_parameter)
25 if $type->is_subtype_of($self->name);
27 return $self->_can_coerce_constraint_from($type)
28 if $self->has_coercion
29 && $self->coercion->has_coercion_for_type($type->parent->name);
34 sub _can_coerce_constraint_from {
35 my ($self, $type) = @_;
36 my $coercion = $self->coercion;
37 my $constraint = $self->constraint_generator->($type->type_parameter);
39 local $_ = $coercion->coerce($_);
45 my ($self, @args) = @_;
47 ## ugly hacking to deal with tc naming normalization issue
48 my ($tc_name, $contained_tc);
50 $contained_tc = shift @args;
51 $tc_name = $self->name .'['. $contained_tc->name .']';
53 ($tc_name, $contained_tc) = @args;
56 unless($contained_tc->isa('Moose::Meta::TypeConstraint')) {
57 Moose->throw_error("The type parameter must be a Moose meta type");
60 return Moose::Meta::TypeConstraint::Parameterized->new(
63 type_parameter => $contained_tc,
77 Moose::Meta::TypeConstraint::Parameterizable - Higher Order type constraints for Moose
83 =item B<constraint_generator>
85 =item B<has_constraint_generator>
87 =item B<generate_constraint_for>
91 Given an array of type constraints, parameterize the current type constraint.
99 All complex software has bugs lurking in it, and this module is no
100 exception. If you find a bug please either email me, or add the bug
105 Stevan Little E<lt>stevan@iinteractive.comE<gt>
107 =head1 COPYRIGHT AND LICENSE
109 Copyright 2006-2008 by Infinity Interactive, Inc.
111 L<http://www.iinteractive.com>
113 This library is free software; you can redistribute it and/or modify
114 it under the same terms as Perl itself.