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
RoleName => 'ClassName', \&RoleName,
);
-
while (my ($name, $parent, $code) = splice @builtins, 0, 3) {
$TYPE{$name} = Mouse::Meta::TypeConstraint->new(
name => $name,
);
}
-# 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
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 {
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.");