X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FParameterized.pm;h=5460166ecf915e653285575eaefb232d085b0f13;hb=ffa3d7bf45b7786ad1057cc38cda0e04ba9ab849;hp=7bbc54a8a6bd98e7713b5b0a168dee5e60ff5664;hpb=7e4e1ad46fd4c72845b18df57a80cdc03b47c4c4;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Parameterized.pm b/lib/Moose/Meta/TypeConstraint/Parameterized.pm index 7bbc54a..5460166 100644 --- a/lib/Moose/Meta/TypeConstraint/Parameterized.pm +++ b/lib/Moose/Meta/TypeConstraint/Parameterized.pm @@ -5,10 +5,10 @@ use warnings; use metaclass; use Scalar::Util 'blessed'; -use Carp 'confess'; use Moose::Util::TypeConstraints; -our $VERSION = '0.02'; +our $VERSION = '0.57'; +$VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::TypeConstraint'; @@ -18,16 +18,30 @@ __PACKAGE__->meta->add_attribute('type_parameter' => ( predicate => 'has_type_parameter', )); +sub equals { + my ( $self, $type_or_name ) = @_; + + my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); + + return unless $other->isa(__PACKAGE__); + + return ( + $self->type_parameter->equals( $other->type_parameter ) + and + $self->parent->equals( $other->parent ) + ); +} + sub compile_type_constraint { my $self = shift; ($self->has_type_parameter) - || confess "You cannot create a Higher Order type without a type parameter"; + || Moose::throw_error("You cannot create a Higher Order type without a type parameter"); my $type_parameter = $self->type_parameter; (blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint')) - || confess "The type parameter must be a Moose meta type"; + || Moose::throw_error("The type parameter must be a Moose meta type"); foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) { if (my $constraint = $type->generate_constraint_for($self)) { @@ -38,8 +52,8 @@ sub compile_type_constraint { # if we get here, then we couldn't # find a way to parameterize this type - confess "The " . $self->name . " constraint cannot be used, because " - . $self->parent->name . " doesn't subtype or coerce from a parameterizable type."; + Moose::throw_error("The " . $self->name . " constraint cannot be used, because " + . $self->parent->name . " doesn't subtype or coerce from a parameterizable type."); } 1; @@ -65,6 +79,8 @@ Moose::Meta::TypeConstraint::Parameterized - Higher Order type constraints for M =item B +=item B + =back =head1 BUGS