added Mouse::Meta::TypeConstraint and use it. Mouse::Meta::Attribute->type_constraint...
[gitmo/Mouse.git] / lib / Mouse / Meta / TypeConstraint.pm
CommitLineData
684db121 1package Mouse::Meta::TypeConstraint;
2use strict;
3use warnings;
4use overload '""' => sub { shift->{name} }, # stringify to tc name
5 fallback => 1;
6
7sub new {
8 my $class = shift;
9 my %args = @_;
10 my $name = $args{name} || '__ANON__';
11
12 my $check = $args{_compiled_type_constraint} or Carp::croak("missing _compiled_type_constraint");
13 if (ref $check eq 'Mouse::Meta::TypeConstraint') {
14 $check = $check->{_compiled_type_constraint};
15 }
16
17 bless +{ name => $name, _compiled_type_constraint => $check }, $class;
18}
19
20sub name { shift->{name} }
21
22sub check {
23 my $self = shift;
24 $self->{_compiled_type_constraint}->(@_);
25}
26
271;
28__END__
29
30=head1 NAME
31
32Mouse::Meta::TypeConstraint - The Mouse Type Constraint Metaclass
33
34=head1 DESCRIPTION
35
36For the most part, the only time you will ever encounter an
37instance of this class is if you are doing some serious deep
38introspection. This API should not be considered final, but
39it is B<highly unlikely> that this will matter to a regular
40Mouse user.
41
42Don't use this.
43
44=head1 METHODS
45
46=over 4
47
48=item B<new>
49
50=item B<name>
51
52=back
53
54=cut
55