1 package Moose::Util::TypeConstraints::OptimizedConstraints;
8 use Scalar::Util 'blessed', 'looks_like_number';
10 sub Value { defined($_[0]) && !ref($_[0]) }
12 sub Ref { ref($_[0]) }
14 # We might need to use a temporary here to flatten LVALUEs, for instance as in
15 # Str(substr($_,0,255)).
18 && ( ref(\ $_[0] ) eq 'SCALAR'
19 || ref(\(my $value = $_[0])) eq 'SCALAR')
22 sub Num { !ref($_[0]) && looks_like_number($_[0]) }
24 # using a temporary here because regex matching promotes an IV to a PV,
25 # and that confuses some things (like JSON.pm)
28 defined($value) && !ref($value) && $value =~ /\A-?[0-9]+\z/
31 sub ScalarRef { ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' }
32 sub ArrayRef { ref($_[0]) eq 'ARRAY' }
33 sub HashRef { ref($_[0]) eq 'HASH' }
34 sub CodeRef { ref($_[0]) eq 'CODE' }
35 sub RegexpRef { ref($_[0]) eq 'Regexp' }
36 sub GlobRef { ref($_[0]) eq 'GLOB' }
38 sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") }
40 sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
43 Moose::Deprecated::deprecated(
44 feature => 'Role type',
46 'The Role type has been deprecated. Maybe you meant to create a RoleName type? This type be will be removed in Moose 2.0200.'
48 blessed( $_[0] ) && $_[0]->can('does');
52 return Class::MOP::is_class_loaded( $_[0] );
57 && (Class::MOP::class_of($_[0]) || return)->isa('Moose::Meta::Role')
61 # we have XS versions too, ...
62 # 04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz
63 # 04:09 <@konobi> or utilxs.tar.gz iirc
73 Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
74 bodies for various moose types
78 This file contains the hand optimized versions of Moose type constraints,
79 no user serviceable parts inside.
121 See L<Moose/BUGS> for details on reporting bugs.