Add ObjectOfType XS function for use with anon types constraints that
[gitmo/Moose.git] / lib / Moose / Util / TypeConstraints / OptimizedConstraints.pm
CommitLineData
5d2f0933 1package Moose::Util::TypeConstraints::OptimizedConstraints;
2
3use strict;
4use warnings;
5
28412c0b 6use Scalar::Util 'blessed', 'looks_like_number';
7
c14746bc 8our $VERSION = '0.02';
28412c0b 9our $AUTHORITY = 'cpan:STEVAN';
5d2f0933 10
bc47531e 11use XSLoader;
67767270 12# Optimized type constraints are XS in Moose.xs
13XSLoader::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 16sub Num { !ref($_[0]) && looks_like_number($_[0]) }
5d2f0933 17
67767270 18sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
bc47531e 19
67767270 20sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") }
5d2f0933 21
67767270 22sub Role { blessed($_[0]) && $_[0]->can('does') }
5d2f0933 23
28412c0b 241;
5d2f0933 25
26__END__
27
28=pod
29
30=head1 NAME
31
32Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
33bodies for various moose types
34
5d2f0933 35=head1 DESCRIPTION
36
28412c0b 37This 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
75Makes sure $object->isa($class). Used in anon type constraints.
76
5d2f0933 77=item Role
78
79=back
28412c0b 80
81=head1 BUGS
82
83All complex software has bugs lurking in it, and this module is no
84exception. If you find a bug please either email me, or add the bug
85to cpan-RT.
86
87=head1 AUTHOR
88
89Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
67767270 90Konobi E<lt>konobi@cpan.orgE<gt>
28412c0b 91
92=head1 COPYRIGHT AND LICENSE
93
94Copyright 2006-2008 by Infinity Interactive, Inc.
95
96L<http://www.iinteractive.com>
97
98This library is free software; you can redistribute it and/or modify
99it under the same terms as Perl itself.
100
101=cut