1 package Mouse::Meta::TypeConstraint;
5 use overload '""' => sub { shift->{name} }, # stringify to tc name
10 use Mouse::Util qw(:meta);
15 my $name = $args{name} || '__ANON__';
17 my $check = $args{_compiled_type_constraint} or Carp::croak("missing _compiled_type_constraint");
18 if (ref $check eq 'Mouse::Meta::TypeConstraint') {
19 $check = $check->{_compiled_type_constraint};
24 _compiled_type_constraint => $check,
25 message => $args{message}
29 sub name { shift->{name} }
33 $self->{_compiled_type_constraint}->(@_);
37 my ($self, $value) = @_;
38 if ($self->{_compiled_type_constraint}->($value)) {
42 $self->get_message($value);
47 my ($self, $value) = @_;
49 my $error = $self->validate($value);
50 return 1 if ! defined $error;
52 Carp::confess($error);
57 return $_[0]->{message};
61 my ($self, $value) = @_;
62 if ( my $msg = $self->message ) {
64 return $msg->($value);
67 $value = ( defined $value ? overload::StrVal($value) : 'undef' );
69 "Validation failed for '"
71 . "' failed with value $value";
76 my($self, $tc_name) = @_;
78 return $self->name eq $tc_name
79 || $self->name =~ /\A $tc_name \[/xms; # "ArrayRef" =~ "ArrayRef[Foo]"
87 Mouse::Meta::TypeConstraint - The Mouse Type Constraint metaclass
91 For the most part, the only time you will ever encounter an
92 instance of this class is if you are doing some serious deep
93 introspection. This API should not be considered final, but
94 it is B<highly unlikely> that this will matter to a regular
111 L<Moose::Meta::TypeConstraint>