Commit | Line | Data |
d60c78b9 |
1 | #!/usr/bin/env perl |
2 | package Mouse::TypeRegistry; |
3 | use strict; |
4 | use warnings; |
9baf5d6b |
5 | |
58fe9fb7 |
6 | use Mouse::Util qw/blessed looks_like_number/; |
7 | use Scalar::Util qw/openhandle/; |
d60c78b9 |
8 | |
0f636a97 |
9 | no warnings 'uninitialized'; |
d60c78b9 |
10 | sub optimized_constraints { |
11 | return { |
12 | Any => sub { 1 }, |
13 | Item => sub { 1 }, |
14 | Bool => sub { |
15 | !defined($_) || $_ eq "" || "$_" eq '1' || "$_" eq '0' |
16 | }, |
f5fbe3cc |
17 | Undef => sub { !defined($_) }, |
18 | Defined => sub { defined($_) }, |
0f636a97 |
19 | Value => sub { defined($_) && !ref($_) }, |
20 | Num => sub { !ref($_) && looks_like_number($_) }, |
21 | Int => sub { defined($_) && !ref($_) && /^-?[0-9]+$/ }, |
22 | Str => sub { defined($_) && !ref($_) }, |
79af4b55 |
23 | ClassName => sub { Mouse::is_class_loaded($_) }, |
0f636a97 |
24 | Ref => sub { ref($_) }, |
25 | |
26 | ScalarRef => sub { ref($_) eq 'SCALAR' }, |
27 | ArrayRef => sub { ref($_) eq 'ARRAY' }, |
28 | HashRef => sub { ref($_) eq 'HASH' }, |
29 | CodeRef => sub { ref($_) eq 'CODE' }, |
30 | RegexpRef => sub { ref($_) eq 'Regexp' }, |
31 | GlobRef => sub { ref($_) eq 'GLOB' }, |
32 | |
33 | FileHandle => sub { |
34 | ref($_) eq 'GLOB' |
35 | && openhandle($_) |
36 | or |
37 | blessed($_) |
38 | && $_->isa("IO::Handle") |
39 | }, |
40 | |
41 | Object => sub { blessed($_) && blessed($_) ne 'Regexp' }, |
d60c78b9 |
42 | }; |
43 | } |
44 | |
45 | 1; |
46 | |
6feb83f1 |
47 | __END__ |
48 | |
49 | =head1 NAME |
50 | |
51 | Mouse::TypeRegistry - simple type constraints |
52 | |
53 | =head1 METHODS |
54 | |
55 | =head2 optimized_constraints -> HashRef[CODE] |
56 | |
57 | Returns the simple type constraints that Mouse understands. |
58 | |
59 | =cut |
60 | |
61 | |