X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FUtil%2FTypeConstraints.pm;h=808bb6b8def12625e695f0b5319f9656b8c6d28d;hp=446cea274ae71261ad2585fb3281611e90267a5b;hb=9abaecfdec4e3ee1c8fae217b029a692155385a3;hpb=f1a8bff35c48b4e801e34859913ae388363a2ef4 diff --git a/lib/Mouse/Util/TypeConstraints.pm b/lib/Mouse/Util/TypeConstraints.pm index 446cea2..808bb6b 100644 --- a/lib/Mouse/Util/TypeConstraints.pm +++ b/lib/Mouse/Util/TypeConstraints.pm @@ -1,12 +1,12 @@ package Mouse::Util::TypeConstraints; use Mouse::Util; # enables strict and warnings -use Carp (); -use Scalar::Util (); - use Mouse::Meta::TypeConstraint; use Mouse::Exporter; +use Carp (); +use Scalar::Util (); + Mouse::Exporter->setup_import_methods( as_is => [qw( as where message optimize_as @@ -66,7 +66,6 @@ my @builtins = ( RoleName => 'ClassName', \&RoleName, ); - while (my ($name, $parent, $code) = splice @builtins, 0, 3) { $TYPE{$name} = Mouse::Meta::TypeConstraint->new( name => $name, @@ -75,14 +74,12 @@ while (my ($name, $parent, $code) = splice @builtins, 0, 3) { ); } -# make it parametarizable - +# parametarizable types $TYPE{Maybe} {constraint_generator} = \&_parameterize_Maybe_for; $TYPE{ArrayRef}{constraint_generator} = \&_parameterize_ArrayRef_for; $TYPE{HashRef} {constraint_generator} = \&_parameterize_HashRef_for; # sugars - sub as ($) { (as => $_[0]) } ## no critic sub where (&) { (where => $_[0]) } ## no critic sub message (&) { (message => $_[0]) } ## no critic @@ -101,7 +98,6 @@ sub optimized_constraints { # DEPRECATED undef @builtins; # free the allocated memory @builtins = keys %TYPE; # reuse it sub list_all_builtin_type_constraints { @builtins } - sub list_all_type_constraints { keys %TYPE } sub _define_type { @@ -187,9 +183,8 @@ sub subtype { return _define_type 1, @_; } -sub coerce { +sub coerce { # coerce $type, from $from, via { ... }, ... my $type_name = shift; - my $type = find_type_constraint($type_name) or Carp::croak("Cannot find type '$type_name', perhaps you forgot to load it."); @@ -432,7 +427,7 @@ Mouse::Util::TypeConstraints - Type constraint system for Mouse =head1 VERSION -This document describes Mouse version 0.75 +This document describes Mouse version 0.76 =head2 SYNOPSIS