1 package Moose::Util::TypeConstraints::OptimizedConstraints;
8 use Scalar::Util 'blessed', 'looks_like_number';
10 our $VERSION = '1.08';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
14 sub Value { defined($_[0]) && !ref($_[0]) }
16 sub Ref { ref($_[0]) }
18 # We need to use a temporary here to flatten LVALUEs, for instance as in
19 # Str(substr($_,0,255)).
22 defined($value) && ref(\$value) eq 'SCALAR'
25 sub Num { !ref($_[0]) && looks_like_number($_[0]) }
27 sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
29 sub ScalarRef { ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' }
30 sub ArrayRef { ref($_[0]) eq 'ARRAY' }
31 sub HashRef { ref($_[0]) eq 'HASH' }
32 sub CodeRef { ref($_[0]) eq 'CODE' }
33 sub RegexpRef { ref($_[0]) eq 'Regexp' }
34 sub GlobRef { ref($_[0]) eq 'GLOB' }
36 sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") }
38 sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
41 Moose::Deprecated::deprecated(
42 feature => 'Role type',
44 'The Role type has been deprecated. Maybe you meant to create a RoleName type?'
46 blessed( $_[0] ) && $_[0]->can('does');
50 return Class::MOP::is_class_loaded( $_[0] );
55 && (Class::MOP::class_of($_[0]) || return)->isa('Moose::Meta::Role')
59 # we have XS versions too, ...
60 # 04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz
61 # 04:09 <@konobi> or utilxs.tar.gz iirc
71 Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
72 bodies for various moose types
76 This file contains the hand optimized versions of Moose type constraints,
77 no user serviceable parts inside.
119 See L<Moose/BUGS> for details on reporting bugs.
123 Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
125 =head1 COPYRIGHT AND LICENSE
127 Copyright 2007-2009 by Infinity Interactive, Inc.
129 L<http://www.iinteractive.com>
131 This library is free software; you can redistribute it and/or modify
132 it under the same terms as Perl itself.