1 package Moose::Meta::TypeConstraint::Parameterizable;
8 our $AUTHORITY = 'cpan:STEVAN';
10 use base 'Moose::Meta::TypeConstraint';
12 __PACKAGE__->meta->add_attribute('constraint_generator' => (
13 accessor => 'constraint_generator',
14 predicate => 'has_constraint_generator',
17 sub generate_constraint_for {
18 my ($self, $type) = @_;
20 return unless $self->has_constraint_generator;
22 return $self->constraint_generator->($type->type_parameter)
23 if $type->is_subtype_of($self->name);
25 return $self->_can_coerce_constraint_from($type)
26 if $self->has_coercion
27 && $self->coercion->has_coercion_for_type($type->parent->name);
32 sub _can_coerce_constraint_from {
33 my ($self, $type) = @_;
34 my $coercion = $self->coercion;
35 my $constraint = $self->constraint_generator->($type->type_parameter);
37 local $_ = $coercion->coerce($_);
52 Moose::Meta::TypeConstraint::Parameterizable - Higher Order type constraints for Moose
58 =item B<constraint_generator>
60 =item B<has_constraint_generator>
62 =item B<generate_constraint_for>
70 All complex software has bugs lurking in it, and this module is no
71 exception. If you find a bug please either email me, or add the bug
76 Stevan Little E<lt>stevan@iinteractive.comE<gt>
78 =head1 COPYRIGHT AND LICENSE
80 Copyright 2006-2008 by Infinity Interactive, Inc.
82 L<http://www.iinteractive.com>
84 This library is free software; you can redistribute it and/or modify
85 it under the same terms as Perl itself.