bump version to 0.87
[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 Class::MOP;
7 use Scalar::Util 'blessed', 'looks_like_number';
8
9 our $VERSION   = '0.87';
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
12
13 sub Value { defined($_[0]) && !ref($_[0]) }
14
15 sub Ref { ref($_[0]) }
16
17 sub Str { defined($_[0]) && !ref($_[0]) }
18
19 sub Num { !ref($_[0]) && looks_like_number($_[0]) }
20
21 sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
22
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 sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") }
31
32 sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
33
34 sub Role { Carp::cluck('The Role type is deprecated.'); blessed($_[0]) && $_[0]->can('does') }
35
36 sub ClassName {
37     return Class::MOP::is_class_loaded( $_[0] );
38 }
39
40 sub RoleName {
41     ClassName($_[0])
42     && (Class::MOP::class_of($_[0]) || return)->isa('Moose::Meta::Role')
43 }
44
45 # NOTE:
46 # we have XS versions too, ...
47 # 04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz
48 # 04:09 <@konobi> or utilxs.tar.gz iirc
49
50 1;
51
52 __END__
53
54 =pod
55
56 =head1 NAME
57
58 Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
59 bodies for various moose types
60
61 =head1 DESCRIPTION
62
63 This file contains the hand optimized versions of Moose type constraints,
64 no user serviceable parts inside.
65
66 =head1 FUNCTIONS
67
68 =over 4
69
70 =item C<Value>
71
72 =item C<Ref>
73
74 =item C<Str>
75
76 =item C<Num>
77
78 =item C<Int>
79
80 =item C<ScalarRef>
81
82 =item C<ArrayRef>
83
84 =item C<HashRef>
85
86 =item C<CodeRef>
87
88 =item C<RegexpRef>
89
90 =item C<GlobRef>
91
92 =item C<FileHandle>
93
94 =item C<Object>
95
96 =item C<Role>
97
98 =item C<ClassName>
99
100 =item C<RoleName>
101
102 =back
103
104 =head1 BUGS
105
106 All complex software has bugs lurking in it, and this module is no
107 exception. If you find a bug please either email me, or add the bug
108 to cpan-RT.
109
110 =head1 AUTHOR
111
112 Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
113
114 =head1 COPYRIGHT AND LICENSE
115
116 Copyright 2007-2009 by Infinity Interactive, Inc.
117
118 L<http://www.iinteractive.com>
119
120 This library is free software; you can redistribute it and/or modify
121 it under the same terms as Perl itself.
122
123 =cut