1 package Moose::Util::TypeConstraints::OptimizedConstraints;
7 use Scalar::Util 'blessed', 'looks_like_number';
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
13 sub Value { defined($_[0]) && !ref($_[0]) }
15 sub Ref { ref($_[0]) }
17 sub Str { defined($_[0]) && !ref($_[0]) }
19 sub Num { !ref($_[0]) && looks_like_number($_[0]) }
21 sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
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' }
30 sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") }
32 sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
34 sub Role { blessed($_[0]) && $_[0]->can('does') }
37 return Class::MOP::is_class_loaded( $_[0] );
42 && (Class::MOP::class_of($_[0]) || return)->isa('Moose::Meta::Role')
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
58 Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
59 bodies for various moose types
63 This file contains the hand optimized versions of Moose type constraints,
64 no user serviceable parts inside.
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
112 Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
114 =head1 COPYRIGHT AND LICENSE
116 Copyright 2007-2009 by Infinity Interactive, Inc.
118 L<http://www.iinteractive.com>
120 This library is free software; you can redistribute it and/or modify
121 it under the same terms as Perl itself.