1 package Mouse::Meta::TypeConstraint;
6 use overload '""' => sub { shift->{name} }, # stringify to tc name
12 my $name = $args{name} || '__ANON__';
14 my $check = $args{_compiled_type_constraint} or Carp::croak("missing _compiled_type_constraint");
15 if (ref $check eq 'Mouse::Meta::TypeConstraint') {
16 $check = $check->{_compiled_type_constraint};
21 _compiled_type_constraint => $check,
22 message => $args{message}
26 sub name { shift->{name} }
30 $self->{_compiled_type_constraint}->(@_);
34 my ($self, $value) = @_;
\r
35 if ($self->{_compiled_type_constraint}->($value)) {
\r
39 $self->get_message($value);
\r
44 my ($self, $value) = @_;
\r
46 my $error = $self->validate($value);
\r
47 return 1 if ! defined $error;
\r
49 Carp::confess($error);
\r
54 return $_[0]->{message};
58 my ($self, $value) = @_;
59 if ( my $msg = $self->message ) {
61 return $msg->($value);
64 $value = ( defined $value ? overload::StrVal($value) : 'undef' );
66 "Validation failed for '"
68 . "' failed with value $value";
73 my($self, $tc_name) = @_;
75 return $self->name eq $tc_name
76 || $self->name =~ /\A $tc_name \[/xms; # "ArrayRef" =~ "ArrayRef[Foo]"
84 Mouse::Meta::TypeConstraint - The Mouse Type Constraint Metaclass
88 For the most part, the only time you will ever encounter an
89 instance of this class is if you are doing some serious deep
90 introspection. This API should not be considered final, but
91 it is B<highly unlikely> that this will matter to a regular