bump version to 0.56 and update changes for release
[gitmo/Moose.git] / lib / Moose / Meta / TypeConstraint / Parameterizable.pm
CommitLineData
7e4e1ad4 1package Moose::Meta::TypeConstraint::Parameterizable;
2
3use strict;
4use warnings;
5use metaclass;
6
3d24a30e 7our $VERSION = '0.56';
75b95414 8$VERSION = eval $VERSION;
7e4e1ad4 9our $AUTHORITY = 'cpan:STEVAN';
10
11use base 'Moose::Meta::TypeConstraint';
12
13__PACKAGE__->meta->add_attribute('constraint_generator' => (
14 accessor => 'constraint_generator',
15 predicate => 'has_constraint_generator',
16));
17
18sub generate_constraint_for {
19 my ($self, $type) = @_;
20
21 return unless $self->has_constraint_generator;
22
23 return $self->constraint_generator->($type->type_parameter)
24 if $type->is_subtype_of($self->name);
25
26 return $self->_can_coerce_constraint_from($type)
27 if $self->has_coercion
28 && $self->coercion->has_coercion_for_type($type->parent->name);
29
30 return;
31}
32
33sub _can_coerce_constraint_from {
34 my ($self, $type) = @_;
35 my $coercion = $self->coercion;
36 my $constraint = $self->constraint_generator->($type->type_parameter);
37 return sub {
38 local $_ = $coercion->coerce($_);
39 $constraint->(@_);
40 };
41}
42
43
441;
45
46__END__
47
48
49=pod
50
51=head1 NAME
52
53Moose::Meta::TypeConstraint::Parameterizable - Higher Order type constraints for Moose
54
55=head1 METHODS
56
57=over 4
58
59=item B<constraint_generator>
60
61=item B<has_constraint_generator>
62
63=item B<generate_constraint_for>
64
65=item B<meta>
66
67=back
68
69=head1 BUGS
70
71All complex software has bugs lurking in it, and this module is no
72exception. If you find a bug please either email me, or add the bug
73to cpan-RT.
74
75=head1 AUTHOR
76
77Stevan Little E<lt>stevan@iinteractive.comE<gt>
78
79=head1 COPYRIGHT AND LICENSE
80
81Copyright 2006-2008 by Infinity Interactive, Inc.
82
83L<http://www.iinteractive.com>
84
85This library is free software; you can redistribute it and/or modify
86it under the same terms as Perl itself.
87
88=cut