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