Commit | Line | Data |
5d2f0933 |
1 | package Moose::Util::TypeConstraints::OptimizedConstraints; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
28412c0b |
6 | use Scalar::Util 'blessed', 'looks_like_number'; |
7 | |
c14746bc |
8 | our $VERSION = '0.02'; |
28412c0b |
9 | our $AUTHORITY = 'cpan:STEVAN'; |
5d2f0933 |
10 | |
bc47531e |
11 | use XSLoader; |
67767270 |
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. |
5d2f0933 |
15 | |
67767270 |
16 | sub Num { !ref($_[0]) && looks_like_number($_[0]) } |
5d2f0933 |
17 | |
67767270 |
18 | sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ } |
bc47531e |
19 | |
67767270 |
20 | sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") } |
5d2f0933 |
21 | |
67767270 |
22 | sub Role { blessed($_[0]) && $_[0]->can('does') } |
5d2f0933 |
23 | |
28412c0b |
24 | 1; |
5d2f0933 |
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 | |
5d2f0933 |
35 | =head1 DESCRIPTION |
36 | |
28412c0b |
37 | This file contains the hand optimized versions of Moose type constraints. |
5d2f0933 |
38 | |
39 | =head1 FUNCTIONS |
40 | |
41 | =over 4 |
42 | |
67767270 |
43 | =item Undef |
44 | |
45 | =item Defined |
46 | |
5d2f0933 |
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 | |
a4550ed1 |
73 | =item ObjectOfType |
74 | |
75 | Makes sure $object->isa($class). Used in anon type constraints. |
76 | |
5d2f0933 |
77 | =item Role |
78 | |
79 | =back |
28412c0b |
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> |
67767270 |
90 | Konobi E<lt>konobi@cpan.orgE<gt> |
28412c0b |
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 |