bump version to 0.56 and update changes for release
[gitmo/Moose.git] / lib / Moose / Meta / TypeConstraint / Parameterized.pm
CommitLineData
0fbd4b0a 1package Moose::Meta::TypeConstraint::Parameterized;
d67145ed 2
3use strict;
4use warnings;
5use metaclass;
6
7use Scalar::Util 'blessed';
8use Carp 'confess';
acb8a5db 9use Moose::Util::TypeConstraints;
d67145ed 10
3d24a30e 11our $VERSION = '0.56';
75b95414 12$VERSION = eval $VERSION;
d67145ed 13our $AUTHORITY = 'cpan:STEVAN';
14
15use base 'Moose::Meta::TypeConstraint';
16
0fbd4b0a 17__PACKAGE__->meta->add_attribute('type_parameter' => (
18 accessor => 'type_parameter',
19 predicate => 'has_type_parameter',
d67145ed 20));
21
dabed765 22sub equals {
23 my ( $self, $type_or_name ) = @_;
24
25 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
26
27 return unless $other->isa(__PACKAGE__);
28
29 return (
30 $self->type_parameter->equals( $other->type_parameter )
31 and
32 $self->parent->equals( $other->parent )
33 );
34}
35
d67145ed 36sub compile_type_constraint {
37 my $self = shift;
38
0fbd4b0a 39 ($self->has_type_parameter)
40 || confess "You cannot create a Higher Order type without a type parameter";
d67145ed 41
0fbd4b0a 42 my $type_parameter = $self->type_parameter;
d67145ed 43
0fbd4b0a 44 (blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint'))
45 || confess "The type parameter must be a Moose meta type";
7e4e1ad4 46
47 foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
48 if (my $constraint = $type->generate_constraint_for($self)) {
49 $self->_set_constraint($constraint);
50 return $self->SUPER::compile_type_constraint;
51 }
d67145ed 52 }
53
7e4e1ad4 54 # if we get here, then we couldn't
55 # find a way to parameterize this type
56 confess "The " . $self->name . " constraint cannot be used, because "
57 . $self->parent->name . " doesn't subtype or coerce from a parameterizable type.";
d67145ed 58}
59
601;
61
62__END__
63
64
65=pod
66
67=head1 NAME
68
0fbd4b0a 69Moose::Meta::TypeConstraint::Parameterized - Higher Order type constraints for Moose
d67145ed 70
d67145ed 71=head1 METHODS
72
73=over 4
74
75=item B<compile_type_constraint>
76
0fbd4b0a 77=item B<type_parameter>
d67145ed 78
0fbd4b0a 79=item B<has_type_parameter>
d67145ed 80
81=item B<meta>
82
dabed765 83=item B<equals>
84
d67145ed 85=back
86
87=head1 BUGS
88
89All complex software has bugs lurking in it, and this module is no
90exception. If you find a bug please either email me, or add the bug
91to cpan-RT.
92
93=head1 AUTHOR
94
95Stevan Little E<lt>stevan@iinteractive.comE<gt>
96
97=head1 COPYRIGHT AND LICENSE
98
778db3ac 99Copyright 2006-2008 by Infinity Interactive, Inc.
d67145ed 100
101L<http://www.iinteractive.com>
102
103This library is free software; you can redistribute it and/or modify
104it under the same terms as Perl itself.
105
106=cut