2 package Mouse::TypeRegistry;
6 use Mouse::Util 'blessed';
7 use Scalar::Util qw/looks_like_number openhandle/;
9 no warnings 'uninitialized';
10 sub optimized_constraints {
15 !defined($_) || $_ eq "" || "$_" eq '1' || "$_" eq '0'
17 Undef => sub { !defined($_) },
18 Defined => sub { defined($_) },
19 Value => sub { defined($_) && !ref($_) },
20 Num => sub { !ref($_) && looks_like_number($_) },
21 Int => sub { defined($_) && !ref($_) && /^-?[0-9]+$/ },
22 Str => sub { defined($_) && !ref($_) },
23 ClassName => sub { Mouse::is_class_loaded($_) },
24 Ref => sub { ref($_) },
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' },
38 && $_->isa("IO::Handle")
41 Object => sub { blessed($_) && blessed($_) ne 'Regexp' },
51 Mouse::TypeRegistry - simple type constraints
55 =head2 optimized_constraints -> HashRef[CODE]
57 Returns the simple type constraints that Mouse understands.