Commit | Line | Data |
684db121 |
1 | package Mouse::Meta::TypeConstraint; |
2 | use strict; |
3 | use warnings; |
4 | use overload '""' => sub { shift->{name} }, # stringify to tc name |
5 | fallback => 1; |
6 | |
7 | sub 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 | |
20 | sub name { shift->{name} } |
21 | |
22 | sub check { |
23 | my $self = shift; |
24 | $self->{_compiled_type_constraint}->(@_); |
25 | } |
26 | |
27 | 1; |
28 | __END__ |
29 | |
30 | =head1 NAME |
31 | |
32 | Mouse::Meta::TypeConstraint - The Mouse Type Constraint Metaclass |
33 | |
34 | =head1 DESCRIPTION |
35 | |
36 | For the most part, the only time you will ever encounter an |
37 | instance of this class is if you are doing some serious deep |
38 | introspection. This API should not be considered final, but |
39 | it is B<highly unlikely> that this will matter to a regular |
40 | Mouse user. |
41 | |
42 | Don'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 | |