X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FTypeConstraint.pm;h=3d2f19525096dc636fa2260ee1879d93709da100;hb=5a363f78184c2c5ab4eeeaec0cf2dba9487f0d8e;hp=052616336863c680f87462fdfc6c72dc30a32c4f;hpb=8adc0b23d04403eebb4e296a440079d8b475ebc0;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/TypeConstraint.pm b/lib/Mouse/Meta/TypeConstraint.pm index 0526163..3d2f195 100644 --- a/lib/Mouse/Meta/TypeConstraint.pm +++ b/lib/Mouse/Meta/TypeConstraint.pm @@ -2,6 +2,8 @@ package Mouse::Meta::TypeConstraint; use Mouse::Util qw(:meta); # enables strict and warnings use overload + 'bool' => sub { 1 }, # always true + '""' => sub { $_[0]->name }, # stringify to tc name '|' => sub { # or-combination @@ -232,6 +234,29 @@ sub is_a_type_of{ return 0; } +# See also Moose::Meta::TypeConstraint::Parameterizable +sub parameterize{ + my($self, $param, $name) = @_; + + if(!ref $param){ + require Mouse::Util::TypeConstraints; + $param = Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint($param); + } + + $name ||= sprintf '%s[%s]', $self->name, $param->name; + + my $generator = $self->{constraint_generator} + || Carp::confess("The $name constraint cannot be used, because $param doesn't subtype from a parameterizable type"); + + return Mouse::Meta::TypeConstraint->new( + name => $name, + parent => $self, + parameter => $param, + constraint => $generator->($param), # must be 'constraint', not 'optimized' + + type => 'Parameterized', + ); +} 1; __END__ @@ -242,7 +267,7 @@ Mouse::Meta::TypeConstraint - The Mouse Type Constraint metaclass =head1 VERSION -This document describes Mouse version 0.40_02 +This document describes Mouse version 0.40_03 =head1 DESCRIPTION