cde58f5766dc793acbb9a0172868faf63b00d16b
[gitmo/Moose.git] / lib / Moose / Util / TypeConstraints / OptimizedConstraints.pm
1 package Moose::Util::TypeConstraints::OptimizedConstraints;
2
3 use strict;
4 use warnings;
5
6 use Scalar::Util 'blessed', 'looks_like_number';
7
8 our $VERSION   = '0.02';
9 our $AUTHORITY = 'cpan:STEVAN';
10
11 use XSLoader;
12 # Optimized type constraints are XS in Moose.xs
13 XSLoader::load('Moose', '0.39'); # This is a pain... must use the version number of moose
14                                  # but can't refer to it since Moose may not be loaded.
15
16 sub Num         { !Ref($_[0]) && looks_like_number($_[0]) }
17
18 sub Int         { Defined($_[0]) && !Ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
19
20 sub FileHandle  { GlobRef($_[0]) && Scalar::Util::openhandle($_[0]) or ObjectOfType($_[0], "IO::Handle")  }
21
22 sub Role        { Object($_[0]) && $_[0]->can('does') }
23
24 1;
25
26 __END__
27
28 =pod
29
30 =head1 NAME
31
32 Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
33 bodies for various moose types
34
35 =head1 DESCRIPTION
36
37 This file contains the hand optimized versions of Moose type constraints.
38
39 =head1 FUNCTIONS
40
41 =over 4
42
43 =item Undef
44
45 =item Defined
46
47 =item Value
48
49 =item Ref
50
51 =item Str
52
53 =item Num
54
55 =item Int
56
57 =item ScalarRef
58
59 =item ArrayRef
60
61 =item HashRef
62
63 =item CodeRef
64
65 =item RegexpRef
66
67 =item GlobRef
68
69 =item FileHandle
70
71 =item Object
72
73 =item ObjectOfType
74
75 Makes sure $object->isa($class). Used in anon type constraints.
76
77 =item Role
78
79 =back
80
81 =head1 BUGS
82
83 All complex software has bugs lurking in it, and this module is no 
84 exception. If you find a bug please either email me, or add the bug
85 to cpan-RT.
86
87 =head1 AUTHOR
88
89 Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
90 Konobi E<lt>konobi@cpan.orgE<gt>
91
92 =head1 COPYRIGHT AND LICENSE
93
94 Copyright 2006-2008 by Infinity Interactive, Inc.
95
96 L<http://www.iinteractive.com>
97
98 This library is free software; you can redistribute it and/or modify
99 it under the same terms as Perl itself.
100
101 =cut