making handles and AUTOLOAD play a bit better
[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
11sub Value { defined($_[0]) && !ref($_[0]) }
12
13sub Ref { ref($_[0]) }
14
15sub Str { defined($_[0]) && !ref($_[0]) }
16
17sub Num { !ref($_[0]) && looks_like_number($_[0]) }
18
19sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
20
42bc21a4 21{
22 no warnings 'uninitialized';
23 sub ScalarRef { ref($_[0]) eq 'SCALAR' }
28412c0b 24 sub ArrayRef { ref($_[0]) eq 'ARRAY' }
25 sub HashRef { ref($_[0]) eq 'HASH' }
26 sub CodeRef { ref($_[0]) eq 'CODE' }
42bc21a4 27 sub RegexpRef { ref($_[0]) eq 'Regexp' }
28412c0b 28 sub GlobRef { ref($_[0]) eq 'GLOB' }
42bc21a4 29}
5d2f0933 30
128c601e 31sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") }
5d2f0933 32
33sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
34
35sub Role { blessed($_[0]) && $_[0]->can('does') }
36
28412c0b 37# NOTE:
38# we have XS versions too, ...
39# 04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz
40# 04:09 <@konobi> or utilxs.tar.gz iirc
5d2f0933 41
28412c0b 421;
5d2f0933 43
44__END__
45
46=pod
47
48=head1 NAME
49
50Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
51bodies for various moose types
52
5d2f0933 53=head1 DESCRIPTION
54
28412c0b 55This file contains the hand optimized versions of Moose type constraints.
5d2f0933 56
57=head1 FUNCTIONS
58
59=over 4
60
61=item Value
62
63=item Ref
64
65=item Str
66
67=item Num
68
69=item Int
70
71=item ScalarRef
72
73=item ArrayRef
74
75=item HashRef
76
77=item CodeRef
78
79=item RegexpRef
80
81=item GlobRef
82
83=item FileHandle
84
85=item Object
86
87=item Role
88
89=back
28412c0b 90
91=head1 BUGS
92
93All complex software has bugs lurking in it, and this module is no
94exception. If you find a bug please either email me, or add the bug
95to cpan-RT.
96
97=head1 AUTHOR
98
99Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
100
101=head1 COPYRIGHT AND LICENSE
102
103Copyright 2006-2008 by Infinity Interactive, Inc.
104
105L<http://www.iinteractive.com>
106
107This library is free software; you can redistribute it and/or modify
108it under the same terms as Perl itself.
109
110=cut