doc updates
[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
fd542f49 11sub Value { defined($_[0]) && !ref($_[0]) }
5d2f0933 12
fd542f49 13sub Ref { ref($_[0]) }
5d2f0933 14
fd542f49 15sub Str { defined($_[0]) && !ref($_[0]) }
bc47531e 16
fd542f49 17sub Num { !ref($_[0]) && looks_like_number($_[0]) }
5d2f0933 18
fd542f49 19sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
20
21{
22 no warnings 'uninitialized';
23 sub ScalarRef { ref($_[0]) eq 'SCALAR' }
24 sub ArrayRef { ref($_[0]) eq 'ARRAY' }
25 sub HashRef { ref($_[0]) eq 'HASH' }
26 sub CodeRef { ref($_[0]) eq 'CODE' }
27 sub RegexpRef { ref($_[0]) eq 'Regexp' }
28 sub GlobRef { ref($_[0]) eq 'GLOB' }
29}
30
31sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") }
32
33sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
34
35sub Role { blessed($_[0]) && $_[0]->can('does') }
36
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
004222dc 55This file contains the hand optimized versions of Moose type constraints,
56no user serviceable parts inside.
5d2f0933 57
58=head1 FUNCTIONS
59
60=over 4
61
62=item Value
63
64=item Ref
65
66=item Str
67
68=item Num
69
70=item Int
71
72=item ScalarRef
73
74=item ArrayRef
75
76=item HashRef
77
78=item CodeRef
79
80=item RegexpRef
81
82=item GlobRef
83
84=item FileHandle
85
86=item Object
87
88=item Role
89
90=back
28412c0b 91
92=head1 BUGS
93
94All complex software has bugs lurking in it, and this module is no
95exception. If you find a bug please either email me, or add the bug
96to cpan-RT.
97
98=head1 AUTHOR
99
100Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
101
102=head1 COPYRIGHT AND LICENSE
103
004222dc 104Copyright 2007-2008 by Infinity Interactive, Inc.
28412c0b 105
106L<http://www.iinteractive.com>
107
108This library is free software; you can redistribute it and/or modify
109it under the same terms as Perl itself.
110
111=cut