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